TDI Samples

Home Up Filters Rawether for Windows NDIS IM TDI Samples Universal Bundle License & Warranty

Advanced TDI Samples
For
Windows NT, Windows 2000 and Higher

TDI Client & TDI Filter Samples

March 14, 2005 - Version 2.02.06.15 released.

Background

The Windows Transport Data interface (TDI) is sometimes referred to as the "native" Windows NT networking interface. It is a kernel-mode interface between two types of device drivers:

TDI Providers
These are NDIS protocol drivers (also called "Transport Drivers") that provide the base implementation of network protocols such as TCP/IP.
 
At their lower edge TDI providers interface with packet-oriented NDIS miniport drivers that communicate over the physical network medium such as Ethernet or WAN. At their upper edge TDI providers interact with their clients using the TDI interface.
 
TDI Clients
These are kernel-mode drivers that use the networking services of a TDI provider such as Tcpip. For example, a kernel-mode driver that is a TDI client of Tcp can initiate or accept TCP connections and send or receive stream data while remaining in the kernel.
 
Even user-mode networking services such as Winsock eventually interface to the kernel-mode base providers via a series of user-mode DLLs and kernel-mode TDI client drivers.

The NDIS FAQ includes a diagram that illustrates where TDI fits into the overall Windows network architecture. See the Windows Network Data and Packet Filtering page.

There is a third type of device driver that is of interest to developers:

TDI Filters
A TDI filter is a device driver that inserts itself between selected providers and their clients. In this logical position a TDI filter can monitor and influence the interaction between TDI clients and providers. TDI filters are often used in implementation of email scanning and firewall products.

Microsoft provides documentation of TDI, and this documentation is essentially correct. However, the documentation is written for the advanced programmer and is easily misinterpreted. There is a great need for companion sample code as an adjunct to the documentation. 

Topics below discuss:

bulletTCI Client Samples Overview
bulletTDI Filter Samples Overview
bulletDownloading Additional Documentation
bulletDownloading Demonstration Executables
bulletLicensing Information
bulletPricing Information

 

TDI Client Samples Overview

A major goal of these samples is to illustrate how to add TDI client functionality into your own Windows driver. The product includes provides several TDI client driver samples, including:

bulletTDI Test TCP (TTCP)
bulletTCP Client (Unidirectional Transmitter)
bulletTCP Server (Unidirectional TCP Receiver)
bulletUDP Client (Unidirectional Transmitter)
bulletUDP Server (Unidirectional Receiver)
 
bulletTDI Echo Server
bulletTCP Server (Receive & Transmit)
bulletUDP Server (Receive & Transmit)
 
bulletTDI Query Test Driver
bulletVarious TDI & Extended TCP Queries

The TDI client Samples illustrate these basic TDI operations:

bulletOpening A Transport Address
bulletOpening A Connection Endpoint
bulletMaking An Endpoint-To-Endpoint Connection
bulletRequesting A Connection To A Remote Node
bulletAccepting A Connection Offer From A Remote Node
bulletListen Operation
bulletConnect Event Handler
bulletSending And Receiving Connection-Oriented Data (TCP)
bulletSending And Receiving Connectionless Data (UDP)
bulletDisconnecting An Endpoint-To-Endpoint Connection
bulletClosing A Connection Endpoint

The TDI Client Samples also illustrate these more advanced TDI Operations

bulletSending Chained MDLs
bulletQuerying TDI Information
bulletTDI_QUERY_ADDRESS_INFO
bulletTDI_QUERY_CONNECTION_INFO
bulletTDI_QUERY_PROVIDER_INFORMATION
bulletTDI_QUERY_PROVIDER_STATISTICS
bulletQuerying Extended TCP Information
bulletIP Address Table - Including Masks, Default Gateway
bulletIP Interface Information - Including Physical Address
bulletIP Route Table
bulletIP SNMP Information
bulletSetting TDI Information (Limited)

Most of the TDI Client Samples are capable of handling multiple concurrent connections.

 

Winsock and Win32 Test Applications

PCAUSA provides companion Winsock and Win32 applications used to test and control operation of the sample drivers.

For example, a Winsock TTCP application is provided as a companion to the TDI TTCP driver sample. This allows you to see both the user-mode and the kernel-mode implementation of similar functions.

 

TDI Kernel Support Library

The implementation of the PCAUSA TDI client samples employs thin API over the basic TDI request interface. The functions provided by the TDI Kerned Support (KS) Library are intended to make TDI client development a little easier. The KS library routines provide a thin layer over the low-level TDI API (after all, who cares how an extended attribute buffer is built...), but don't totally obscure their intended use.

Also see the topic Why We Don't Provide a "Kernel Sockets" Framework.

The thin KS library API has been well received by PCAUSA customers since it was introduced in early 2000 and has been used in a wide variety of shipping commercial applications.

A Programmers Reference to the KS library routines is provided.

 

TDI Filter Samples Overview

Filtering of TDI operation is required for a variety of applications including:

bulletFirewalls
bulletEmail Scanning
bulletMonitoring Data (Not Packets) on Specified IP Addresses and Ports
bulletMonitoring Data (Not Packet) on the IP Loopback Address (127.0.0.1)

PCAUSA provides several TDI filter samples intended to provide insight into practical approaches to filter TDI.

It should be emphasized that TDI filtering is not simple for a variety of reasons:

bulletAlthough the basic TDI API for normal TCP and UDP operations is fairly well documented in the DDK, the API employs fairly sophisticated kernel-mode programming techniques that may not be familiar to many Windows driver programmers.
 
bulletWriting of any filter driver requires that the filter-writer be thoroughly familiar with the behavior of the higher-level devices (e.g., the TDI clients) that are to be filtered. Many TDI filter-writers do not take the time to understand how TDI clients operate before they begin writing a filter.
 
bulletThe TDI API for normal TCP and UDP operations is extremely flexible. For many operations there are several different APIs that can be used either alone or in combination to achieve the same result (e.g., to receive TCP stream data). It difficult for a filter-writer to anticipate the possible API combinations that may be invoked by the TDI client being filtered.
 
bulletThere are IRQL and API limitations that make it difficult to pend or delay some TDI operations.
 
bulletThere are potential interactions between TDI filters and anti-virus or firewall products.
 
bulletMicrosoft-proprietary undocumented APIs are used for some special purposes such as VPN tunneling.

Despite these difficulties TDI filters may be the only solution that can be used to satisfy some requirements.  The PCAUSA TDI samples certainly provide a starting point for TDI filter development if it is required.

 

PassThru TDI Filter Samples

PCAUSA provides two different pass through TDI filter samples. Both of these are "monitoring" filters that do not modify data. In general monitoring data, as well as blocking connections and datagrams, are operations that can be achieved reliably for TCP and UDP. Modifying TCP or UDP data (in any filter including - the much simpler NDIS IM driver...) is an advanced topic beyond the scope the PCAUSA TDI filter samples.

bulletLayered Pass Through TDI Filter - Uses IoAttachDeviceToDeviceStack.
bulletDispatch-Hooking Pass Through TDI Filter - Manipulates the Tcpip Dispatch table.

The Pass Through TDI filter samples provides functions that support filtering of these TDI operations and their completion functions (when appropriate):

bulletTdiOpenAddress, TdiCloseAddress
bulletTdiOpenConnection, TdiCloseConnection
bulletTdiSetEvent
bulletTdiConnect, TdiDisconnect
bulletTdiAssociateAddress, TdiDisAssociateAddress
bulletTdiSend, TdiReceive
bulletTdiReceiveEventHandler, TdiChainedReceiveEventHandler
bulletTdiSendDatagram, TdiReceiveDatagram
bulletTdiReceiveDGEventHandler, TdiChainedReceiveDGEventHandler

The TDI filter samples include code to associate, to the extent practical, the process that owns each new TDI Address Object. For TCP and UDP operations the TDI filter samples illustrate fetching the local and remote IP address and port for most operations.

Operation of the Layered Pass Through TDI Filter can be observed with a debugger. See an Example TDI Filter Trace.

 

Advanced TDI Filter Samples

Additional TDI filter samples are provided that build on the basic functionality of the pass through TDI filters. These include:

bulletLoopback Data Monitor - Logs data sent and received on 127.0.0.1 to the console.
bulletRemote Port Data Monitor - Logs data sent and received on a specific remote port to the console.
bulletTCP/UDP Port Blocker - Selectively blocks incoming and outgoing TCP connections and UDP datagram traffic.
    Click here for more information.
bulletOutgoing TCP Connection Redirector - Can redirect selected connection attempts to local proxy.
    Click here for more information.

An example of the operation of the Remote Port Data Monitor is monitoring email sent via a SMTP server:

bulletEmail Sent
bulletData Logged on SMTP Port

The PCAUSA TDI Filter samples illustrate attaching a filter driver over the MSTCP driver's \Device\Tcp and \Device\Udp devices. Most normal TCP and UDP data is transferred over these devices.

MSTCP exports additional devices which are basically Microsoft proprietary or largely undocumented. These devices provide support for the Microsoft Virtual Private Network (VPN) tunnels as well as IP support operations (e.g., ICMP, etc.).

The PCAUSA TDI Filter Samples do NOT provide information on these Microsoft proprietary MSTCP devices.

The current TDI Client and TDI Filter samples have been tested to the extent practical on the most current Windows versions available as of the release date. The current samples have been developed and tested on systems up to and including 4-way Windows Server 2003 systems.

Most TDI Client and TDI Filter samples can be built for and run on NT systems ranging from Windows NT 4.0 through Windows Server 2003.

Some of the TDI Filter samples can be optionally built to use OS enhancements introduced with Windows XP. For example, the TDI Loopback Data Monitor (TDILpbkH) can be built to use the queued spin lock feature available with Windows XP and higher.

 

Why We Don't Provide a "Kernel Sockets" Framework

The term "sockets" appears to be a magic word in the world of network programming. It suggests a standard network programming interface that is intended to be portable across a wide variety of platforms. Judging by questions on various newsgroups and mailing lists related to "porting" sockets applications from one platform to another, the "portability" of sockets applications seems far from perfect.

In the specific case of Winsock, it is only after a sockets application has been "successfully" ported to Winsock that the developer realizes that the use of Microsoft-specific Winsock facilities (WSA..., IOCP, etc.) must be (or should be) used to extract maximum performance on the platform.

In addition, it should be remembered that the sockets API is a user mode API.

On the other hand, kernel mode network programming on any platform is significantly different from user mode programming.

The Transport Data Interface (TDI)
is
the Windows native networking API.

In PCAUSA's judgment, TDI is well suited to network programming in kernel mode, and wrapping the NT native kernel mode networking API in a "kernel sockets" API would obscure its intended use. In addition, it would only be after a sockets application had been "successfully" ported to "kernel sockets" that the developer realizes that the use of TDI-specific facilities must be (or should be) used to extract maximum performance in the kernel environment.

So, no "kernel sockets" from PCAUSA...

 

Development Environment

It is your responsibility to setup the device driver build environment. In addition, it is your responsibility to learn the general techniques used to build and debug Windows NT device drivers.

If this is your first experience in device driver development, it is likely that you will encounter problems in simply setting up the Device Driver Kit (DDK). Some of these problems can be very frustrating to the uninitiated. When you undergo these trials for the first time, please have patience.

The Advanced TDI Samples can be built under:

bulletNT 4.0 Target - Windows NT 4.0 Device Driver Kit
bulletWindows 2000 or Higher Target - Windows 2000 Build Environment of the Windows Server 2003 DDK

There are several Window DDK versions that include the Windows 2000 Build Environment. However, PCAUSA currently uses and recommends the Windows 2000 Build Environment provided by the Windows Server 2003 DDK (Build 3790).

It is strongly recommended that you have separate executables for each of the two target platforms compiled under the appropriate DDK.

 

Prerequisite Experience

A programmer intending to write TDI Clients or TDI Filters should have prior experience in development and debugging of Windows NT device drivers.

Some of the techniques used the TDI API are not encountered in typical Windows NT device drivers and/or are weakly described in Microsoft documentation and DDK samples. The following intermediate-level device driver programming topics are involved in TDI device drivers:

bulletExtended Attributes
bulletHandmade IRPs
bulletMemory Descriptor Lists (MDLs)
bulletAsynchronous Inter-Driver Calling Methods
bulletKernel Threads
bulletAttention To IRQL Restrictions
bulletAttention To Process/Thread Context Restrictions

TDI filter driver writers must also understand the architecture of the Windows NT layered device driver model and techniques used to filter IRPs.

 

Download TDI Samples Documentation

The product includes:

bulletOver 100 pages of documentation, provided in HTML Help format
bulletOver 15,000 lines (250 pages) of heavily commented driver sample code
bulletComplete source code to all sample drivers

You can download and review the TDI Sample documentation using the link below.

Download TDI Sample HTML Help Documentation

You can also view the current Release Notes.

 

Download TDI Demonstration Executables

You can download executable versions of several TDI driver samples. Clicking on the links below should activate your email client to send an empty request message to PCAUSA. You'll need to read the Terms And Conditions and enter your Contact Information before receiving an autoresponder email that will provide the URL to download the sample executables.

Your Contact Information will only be used by PCAUSA, primarily to determine if there is sufficient interest to maintain the software on the PCAUSA website.

You can download the executable versions of this TDI client sample driver:

bulletTest TCP (TTCP) TDI Client - Uses a TDI client to implement the Test TCP (TTCP) suite of performance benchmarking tests. This sample illustrates use of TCP and UDP for sending and receiving from a kernel-mode driver.

The PCAUSA TDI Client Demo Executables can be downloaded as a ZIP from the following URL:

TDIClientDemo.zip
267.77KB (274198 bytes)

After unzipping the file, please read the documentation in the Readme.htm files in this folder:

\PCADemo\TDI Samples\TDI Clients\TTCP
 

You can download the executables for two sample TDI filters:

bulletTDI Loopback Data Monitor - Uses a TDI filter to log TCP data sent and received on the loopback (127.0.0.1) address.
bulletTDI Remote Port Monitor - Uses a TDI filter to log TCP data sent and received on a specified remote port such as SMTP, POP3 or HTTP.

The PCAUSA TDI Filter Demo Executables can be downloaded as a ZIP from the following URL:

TDIFilterDemo.zip
143.87KB (147320 bytes)

After unzipping the file, please read the documentation in the Readme.htm files in these folders:

\PCADemo\TDI Samples\TDI Filters\Loopback Monitor
\PCADemo\TDI Samples\TDI Filters\Remote Port Monitor
 

If you find bugs in these samples or wish to suggest improvements, please let us know.

 

Licensing Information

The product includes a royalty-free license to incorporate sample code into your executable products. Please review the PCAUSA License Agreement and Limited Warranty.

 

Pricing And Ordering Information

PCAUSA offers the Advanced TDI Samples with a variety of terms and conditions.

Advanced TDI Samples For Windows NT, Windows 2000 and Higher

SKU

Description

Documentation
Source Code
License

Product Updates

Technical Support

Satisfaction Guarantee

TDI Client Samples

TDI Filter Samples

Price

041

Advanced TDI Samples
-
Developer Edition -

Yes

90 Days

90 Days

Yes!

Yes!

Yes!

US$495.00

042

Advanced TDI Samples
-
Subscription Edition -

Yes

1 Year

1 Year

Yes!

Yes!

Yes!

US$695.00

043

Advanced TDI Samples
-
Subscription Renewal -

Yes

1 Year

1 Year

Yes!

Yes!

Yes!

US$500.00

Ordering Information...

Prices good through June 30, 2008.

Hit Counter3/27/06

 
 

PCAUSA Home · Privacy Statement · Products · Ordering · Support · Utilities · Resources
Mailing Lists  · PCAUSA Newsletter · PCAUSA Discussion List
 
Rawether for Windows and WinDis 32 are trademarks of Printing Communications Assoc., Inc. (PCAUSA)
Microsoft, MS, Windows, Windows 95, Windows 98, Windows Millennium, Windows 2000, and Win32 are registered trademarks and Visual C++ and Windows NT are trademarks of the Microsoft Corporation.
Send mail to webmaster@pcausa.com with questions or comments about this web site.
Copyright © 1996-2008 Printing Communications Assoc., Inc. (PCAUSA)
Last modified: December 31, 2007