Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
8.5 KiB

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
  5. <meta name="ProgId" content="FrontPage.Editor.Document">
  6. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  7. <title>TdiClientSample</title>
  8. </head>
  9. <body>
  10. <h2>TDISAMPLE.SYS -- Sample Tdi Client Driver</h2>
  11. <p></p>
  12. <h3>SUMMARY</h3>
  13. <p></p>
  14. <h4>Sample Tdi Client Driver</h4>
  15. <p>
  16. The TdiClient sample is a simple driver that demonstrates many of the
  17. the basic principles involved in a Tdi Client. It is written to work with a variety
  18. of Tdi providers in order to more completely demonstrate how the Tdi interface is used.
  19. <br><br>
  20. The sample is composed of the Tdisample.sys driver, which is the actual Tdi client, and
  21. a simple user application, Tdisamp.exe, which communicates through this driver. The user
  22. application is itself divided into two parts--a library, which knows how to talk to Tdisample.sys,
  23. and the actual program, which uses these library functions to communicate between two machines.
  24. </p>
  25. <h3>BUILDING THE SAMPLE</h3>
  26. <p>
  27. Run the <b>build</b> command from this directory to build the sample�it creates the
  28. binaries Tdisample.sys and Tdisamp.exe.
  29. <br><br>
  30. To install this driver on Windows� 2000, use the INF also found in this directory.<br>
  31. </p>
  32. <h3>INSTALLING THE SAMPLE</h3>
  33. <p>
  34. Tdisample is installed as a service (called �Tdisample Driver� in the supplied
  35. INFs/notification object). To install, follow the steps below.
  36. <br><br>
  37. Prepare a floppy disk (or installation directory) that contains these files:
  38. nettdic.inf, Tdisample.sys and Tdisamp.exe.
  39. <br><br>
  40. On the desktop, right-click the <b>My Network Places</b> icon and choose <b>Properties</b>.
  41. <br><br>
  42. Right-click on any Local Area Connection icon and choose <b>Properties</b>.
  43. <br><br>
  44. Click <b>Install</b>, then <b>Service</b>, then <b>Add</b>, then <b>Have Disk</b>.
  45. <br><br>
  46. Browse to the drive/directory containing the files listed above. Click <b>OK</b>. This
  47. should show �Tdisample Driver� in a list of Network Services. Highlight this and
  48. click <b>OK</b>. This should install the Tdisample driver.
  49. <br><br>
  50. Click <b>OK</b> or <b>Yes</b> each time the system prompts with a warning regarding
  51. installation of unsigned files. This is necessary because binaries generated via
  52. the DDK build environment are not signed.
  53. </p>
  54. <h3>RUNNING THE SAMPLE</h3>
  55. <p>
  56. The sample is designed to be run between two machines, one running as the <i>server</i> and the
  57. other running as the <i>client</i>. In addition, it can be run over several different Tdi providers
  58. (ie, protocols). The server should always be started first, then the client. The two machines must
  59. be on the same network--preferable on the same network segment--in order for the test to run. Also,
  60. they must both be running over the same protocol. The examples below show the various ways in
  61. which the tests can be run.
  62. <br><br>
  63. Running test over ipx:<br>
  64. tdisamp /server /ipx<br>
  65. tdisamp /ipx
  66. <br><br>
  67. Running test over tcpip (ipv4)<br>
  68. tdisamp /server /ipv4<br>
  69. tdisamp /ipv4
  70. <br><br>
  71. Running test over Netbios<br>
  72. tdisamp /server /netbt<br>
  73. tdisamp /netbt
  74. </p>
  75. <h3>CODE TOUR</h3>
  76. <h4>File Manifest</h4>
  77. <pre><u>File Description</u>
  78. <br>
  79. dirs causes lib, sys, and tdisamp directories to be built
  80. tdiclient.htm this help file
  81. nettdic.inf installation file
  82. inc\glbconst.h constants shared between library and driver
  83. inc\glbtypes.h structure types shared between library and driver
  84. inc\libbase.h constants and structures shared between library and application
  85. inc\libprocs.h library functions available to the application
  86. lib\makefile makefile for the library
  87. lib\sources file listing sources to be used in building the library
  88. lib\libvars.h defines private to the library
  89. lib\stdafx.h precompiled header for library
  90. lib\connect.cpp user mode apis for making and breaking connections
  91. lib\events.cpp user mode apis for enabling event handlers
  92. lib\misc.cpp user mode apis for miscellaneous operations
  93. lib\open.cpp user mode apis for opening and close control, address, and endpoint objects
  94. lib\receive.cpp user mode apis for receiving data
  95. lib\send.cpp user mode apis for sending data
  96. lib\stdafx.cpp for creating binary associated with precompiled header
  97. lib\tdilib.cpp user mode apis for starting and ending communication with driver
  98. lib\tdiquery.cpp user mode apis for querying tdi provider
  99. lib\utils.cpp library internal functions for communicating with the driver
  100. tdisamp\makefile makefile for user mode application
  101. tdisamp\sources file listing sources used in building the user mode application
  102. tdisamp\tdisamp.cpp actual source for user mode application
  103. sys\makefile makefile for driver
  104. sys\sources file listing sources used in building the driver
  105. sys\sysprocs.h prototypes for driver functions
  106. sys\sysvars.h driver-specific types and constants
  107. sys\buffer.cpp functions for doing posted receives
  108. sys\connect.cpp functions for establishing and breaking connections
  109. sys\events.cpp functions for enabling event handlers
  110. sys\open.cpp functions for opening and closing control, address, and endpoint objects
  111. sys\rcvdgram.cpp functions for receiving datagrams using event handlers
  112. sys\receive.cpp functions for receiving data over a connection using event handlers
  113. sys\recvcom.cpp common receive utilities
  114. sys\requests.cpp function dealing with device io requests
  115. sys\send.cpp functions for sending data or datagrams
  116. sys\tdipnp.cpp functions for dealing with pnp and power management events
  117. sys\tdiquery.cpp functions for dealing with tdi requests
  118. sys\tdisample.cpp functions dealing with driver initialization and unloading
  119. sys\utils.cpp some utility functions
  120. sys\tdisample.rc resources file for driver
  121. </pre>
  122. <h4>Programming Tour</h4>
  123. <p>
  124. The general layout of the source code is that the user application calls the functions provided by
  125. the library to do all the work. The library function packs up the arguments for the driver and calls
  126. TdiLibDeviceIO. This function is essentially a wrapper for the system's DeviceIoControl function,
  127. which calls the driver at its TSDispatch entry point. The execution is then routed to TSIssueRequest,
  128. which determines what driver function needs to be called to support the request. The appropriate
  129. function is then called. In most cases, the function called in the driver is in a file having the
  130. same name as the function originally called in the library.
  131. <br><br>
  132. Tdisample.sys is writen to be as independent as possible of which protocol is being used as the
  133. tdi provider. For this reason, opening devices as well as sending and receiving data is handled
  134. through the DeviceIoControl mechanism rather than through Open, Read, and Write. An actual Tdi client
  135. is more likely to use these rather than DeviceIoControl.
  136. <br><br>
  137. Since the more interesting part of this sample is the driver, the rest of this section will concentrate
  138. on what goes on there. Hopefully, the inline comments will be helpful in understanding what is
  139. going on throughout the code.
  140. <br><br>
  141. 1) During DriverEntry, the TdiSample driver registers itself with the system, informing it of its
  142. various entry points. It then registers itself with TDI by informing it of its pnp handlers
  143. (see sys\tdisample.cpp, function DriverEntry).
  144. Intermediate miniport driver.
  145. <br><br>
  146. 2) TDI next calls the TSPnpAddAddressCallback handler once for every address which has been
  147. registered with it. This function will store the name and address of each one received. Both the
  148. name and address are required, since NetBios opens devices on the basis of their name, while ipx
  149. and ipv4 open devices on the basis of their address.
  150. <br><br>
  151. 3) TDI also calls the TSPnpBindCallback handler once for each protocol. The sample does nothing
  152. with these calls except to output the call information to the debugger.
  153. <br><br>
  154. 4) <b>Memory Management</b> The driver uses a wrapper around the system memory management functions.
  155. This is useful during development and debugging to help track memory leaks and overwrites.
  156. 5) <b>Handling Power Management</b>
  157. <br><br>
  158. 5.1 During initialization, the TdiSample registers its power management handler
  159. with TDI.
  160. <br><br>
  161. 5.2 Power management messages are handled by the TSPnpPowerHandler function. Note that it does
  162. not do anything useful with these messages, but just outputs the messages to the debugger.
  163. <br><br>
  164. </p>
  165. <p>Top of page</p>
  166. <p>� 1999 Microsoft Corporation</p>
  167. </body>
  168. </html>