Source code of Windows XP (NT5)
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.

531 lines
19 KiB

  1. /*
  2. (C) Copyright 1999
  3. All rights reserved.
  4. Portions of this software are:
  5. (C) Copyright 1995 TriplePoint, Inc. -- http://www.TriplePoint.com
  6. License to use this software is granted under the same terms
  7. outlined in the Microsoft Windows Device Driver Development Kit.
  8. (C) Copyright 1992 Microsoft Corp. -- http://www.Microsoft.com
  9. License to use this software is granted under the terms outlined in
  10. the Microsoft Windows Device Driver Development Kit.
  11. @doc INTERNAL Miniport Miniport_h
  12. @module Miniport.h |
  13. This module defines the interface to the <t MINIPORT_DRIVER_OBJECT_TYPE>.
  14. @comm
  15. This module defines the software structures and values used to support
  16. the NDIS WAN/TAPI Minport. It's a good place to look when your trying
  17. to figure out how the driver structures are related to each other.
  18. Include this file at the top of each module in the Miniport.
  19. @head3 Contents |
  20. @index class,mfunc,func,msg,mdata,struct,enum | Miniport_h
  21. @end
  22. */
  23. /* @doc EXTERNAL INTERNAL
  24. @topic 1.0 Miniport Call Manager Overview |
  25. The NDIS wrapper provides services to both the Transport drivers, and the
  26. Miniport drivers. The NDIS wrapper provides an abstraction layer between
  27. the two which allows them to interoperate with each other as long as they
  28. both adhere to the NDIS interfaces defined for Transports and Miniports.
  29. The NDIS wrapper also provides a set of services which isolates NDIS
  30. drivers from the specifics of the Operating System (Windows 98 vs
  31. Windows 2000), as well as the platform specifics (Processor, Bus,
  32. Interrupts). The advantage of using the NDIS wrapper is that the Miniport
  33. can be easily ported to other Windows environments with little or no
  34. re-coding.
  35. An MCM consists of two, cooperating, drivers contained the the same binary.
  36. The DATA portion of the driver handles packet transmits and receives. The
  37. CONNECTION portion handles call setup and tear down.
  38. The DATA side of the Miniport is very similar to an NDIS LAN style Miniport,
  39. except that some of the NDIS interfaces have been modified to support the
  40. WAN media type. The primary difference from the Miniport's point of view is
  41. that we use a different set of NDIS requests, and more importantly the line
  42. can go up and down.
  43. The CONNECTION portion of the Miniport adds significant complexity to the
  44. Miniport. The MCM Miniport must provide a pseudo Telephony Service Provider
  45. Interface (TSPI) which lives under NDPROXY. The NDPROXY TSPI loads under
  46. TAPI as the 'real' service provider, and then routes all TAPI events to the
  47. MCM.
  48. NDPROXY can have multiple MCM's living under its TSPI interface. And since
  49. Remote Access Services (RAS) usess the TAPI interface to place and accept
  50. all calls, any Dial Up Networking (DUN) requests associated with the MCM,
  51. will end up at the MCM via CONDIS requests from NDPROXY.
  52. @topic 1.1 Reference Documents |
  53. The most reliable source of information is provided on the Microsoft
  54. Developer Network CD. These documents will provide you with the complete
  55. NDIS interface requirements and architectural overviews. In addition,
  56. there are many addendums and developer notes in the Microsoft Knowledge
  57. Base. The most important references are:
  58. @iex
  59. Product Documentation\DDKs\Windows 2000 DDK\Network Drivers\
  60. Design Guide\Part 2: Miniport NIC Drivers
  61. Chapters 1-7 discuss all the NDIS interface routines.
  62. Chapters 8 provide details on WAN/TAPI extensions.
  63. Section 8.7 discuss CoNdis extensions to support TAPI.
  64. Product Documentation\SDKs\Platform SDK\Networking and Directory Services\
  65. Telephone Application Programming Interfaces\TAPI Service Providers
  66. This section defines the Windows TSPI implementation.
  67. @normal
  68. @end
  69. */
  70. /* @doc EXTERNAL INTERNAL
  71. @topic 2.0 Installing and Configuring the Sample Driver |
  72. The sample driver implements a fully functional ISDN style CO-NDIS WAN
  73. driver. It layers in under NDPROXY which translates the RAS/WAN/TAPI
  74. interfaces into a more generic CO-NDIS interface. The driver supports
  75. multiple adapter instances, so you can install it more than once to
  76. create multiple adapters.
  77. Each adapter can emulate multiple ISDN B channels. By default, each
  78. adapter is setup with 2 channels, but you can modify the "IsdnBChannels"
  79. and "WanEndPoints" registry entries to creates as many as you'd like.
  80. Alternatively, you can just modify these values in the INF file before
  81. you install the adapter. Either way works fine.
  82. @topic 2.1 Installation |
  83. The driver can be installed as a non-plug-n-play device using the Windows
  84. device manager interface as follows:
  85. 1) Right-click the "My Computer" icon on the desktop and select the
  86. Properties item from the context menu.
  87. 2) Select the "Hardware" tab on the "System Properties" dialog.
  88. 3) Click the "Hardware Wizard" button, then click "Next" when the welcome
  89. dialog appears.
  90. 4) Click "Next" again to "Add/Troubleshoot a device".
  91. 5) Select "Add a new device" from the list presented, then click "Next".
  92. 6) Select "No, I want to select the hardware from a list" radio button,
  93. then click "Next".
  94. 7) Select "Network adapters" from the list presented, then click "Next".
  95. 8) Click the "Have Disk" button, then browse to the location of the driver
  96. and INF file, then click OK."
  97. 9) You should now see "TriplePoint COISDN Adapter" on the screen. Click
  98. "Next" and then "Next" again to install the driver. If Windows warns you
  99. about an unsigned driver, just click yes to install. If you don't have
  100. permission to install such drivers, you'll have to exit and logon with the
  101. proper permissions. You will have to disable the driver signing check on
  102. your system if it doesn't allow unsigned drivers to be installed.
  103. 10) Now click "Finish" to load the driver.
  104. @topic 2.2 Dial-In Setup |
  105. You must install and enable Dial-Up networking before you can accept an
  106. incoming call with the driver. This can be done using the following
  107. procedure:
  108. 1) Right-click the "My Network Places" icon on the desktop and select the
  109. Properties item from the context menu.
  110. 2) Double-click the "Make New Connction" icon from the list.
  111. 3) Select the "Accept incoming connections" radio button, then click "Next".
  112. 4) Click the check box next to the "TriplePoint COISDN Adapter"(s) to allow
  113. incoming calls on the adapter. All channels on that adapter are enabled
  114. for incoming calls. Once you select the adapter(s), click "Next".
  115. 5) Select "Do not allow virtual private connections", then click "Next".
  116. 6) Select the users you want to have dial-in access, then click "Next".
  117. 7) Select the protocols and services you want to support, then click "Next".
  118. 8) Now click "Finish" to enable the dial-in connections.
  119. @topic 2.3 Dial-Out Setup |
  120. The sample driver implements the following simple dialing method.
  121. A) "0" can be used to connect to any available more on any available
  122. adapter. This is generally good enough for most testing.
  123. B) "N" specifies that the connection should be directed to a specific
  124. adapter instance. Where N must match the ObjectID assigned to a particular
  125. adapter when the <f MiniportInitialize> routine is called. Numbers are
  126. assigned from 1-M based on the adapter initialization order. The call is
  127. then directed to any available listening channel on the selected adapter.
  128. You must create a dial-out connection before you can place call with the
  129. driver. This can be done using the following procedure:
  130. 1) Right-click the "My Network Places" icon on the desktop and select the
  131. Properties item from the context menu.
  132. 2) Double-click the "Make New Connction" icon from the list.
  133. 3) Select the "Dial-up to private network" radio button, then click "Next".
  134. 4) Click the check box next to one or more "TriplePoint COISDN Adapter"
  135. ISDN Channels to allow outgoing calls on the channel. Make sure you leave
  136. enough channels available to answer the call when it comes in... You have
  137. no way to know which driver BChannel is actually going to be used, but that
  138. doesn't generally matter anyway. Once you select the channel(s), click "Next".
  139. 5) Walk your way through the rest of the Wizard dialogs to setup the
  140. connection as you like.
  141. 6) When you're done click "Finish" to enable the dial-out connection.
  142. Now you can double-click the dial-out connection to see how it all works.
  143. I suggest you also turn some debug flags in the driver to see how the call
  144. setup and teardown winds its way through the driver. This can be quite
  145. useful before starting to modify the driver for your hardware.
  146. @end
  147. */
  148. /* @doc EXTERNAL INTERNAL
  149. @topic 4.0 Functional Overview |
  150. This section describes the major functional objects defined by the driver.
  151. This driver is designed as a generic ISDN device driver. It does not
  152. support any specific hardware, but does have the basic elements of an ISDN
  153. device. The network interface is emulated by placing calls between one or
  154. more of the driver's BChannels. This is accomplished using a set of
  155. software events that simulate typical network events (i.e MakeCall,
  156. AnnounceCall, Tranmit, Receive, Hangup, etc).
  157. By using this design approach you can compile and test the driver without
  158. having to purchase specific hardware. The downside is that you cannot
  159. easily test the data flow because the networking infrastructure does not
  160. support terminating the endpoint on the local host. However, the data flow
  161. is not usually very difficult to test once the call manager interfaces are
  162. reliable. RAS does support connecting to the local host, but the NDIS
  163. protocols won't normally route traffic through the interface because they
  164. just loop back before it reaches the driver. The PPP negotiation packets
  165. are routed through the interface, so this does give some data flow excersise,
  166. but nothing worth writing home about. The NDISWAN tester has been modified
  167. to allow it to run over locally terminated connections, so this is the only
  168. real way to test the data pump.
  169. Because this driver does not support real hardware, all the hardware
  170. resource code has been ifdef'd out. This code has been used in working
  171. drivers, so I'm pretty sure it will work if you add the corresponding
  172. compiler options. However, it has not been verified and may require some
  173. modifications for your environment.
  174. There are several other good samples included on the DDK that can be useful
  175. for using other NDIS features. This sample focuses primarily on the
  176. CO-NDIS call manager interfaces.
  177. @end
  178. */
  179. #ifndef _MPDMAIN_H
  180. #define _MPDMAIN_H
  181. #define MINIPORT_DRIVER_OBJECT_TYPE ((ULONG)'D')+\
  182. ((ULONG)'R'<<8)+\
  183. ((ULONG)'V'<<16)+\
  184. ((ULONG)'R'<<24)
  185. #define INTERRUPT_OBJECT_TYPE ((ULONG)'I')+\
  186. ((ULONG)'N'<<8)+\
  187. ((ULONG)'T'<<16)+\
  188. ((ULONG)'R'<<24)
  189. #define RECEIVE_OBJECT_TYPE ((ULONG)'R')+\
  190. ((ULONG)'E'<<8)+\
  191. ((ULONG)'C'<<16)+\
  192. ((ULONG)'V'<<24)
  193. #define TRANSMIT_OBJECT_TYPE ((ULONG)'T')+\
  194. ((ULONG)'R'<<8)+\
  195. ((ULONG)'A'<<16)+\
  196. ((ULONG)'N'<<24)
  197. #define REQUEST_OBJECT_TYPE ((ULONG)'R')+\
  198. ((ULONG)'Q'<<8)+\
  199. ((ULONG)'S'<<16)+\
  200. ((ULONG)'T'<<24)
  201. /*
  202. // NDIS_MINIPORT_DRIVER and BINARY_COMPATIBLE must be defined before the
  203. // NDIS include files. Normally, it is defined on the command line by
  204. // setting the C_DEFINES variable in the SOURCES build file.
  205. */
  206. #include <ndis.h>
  207. #include <ndiswan.h>
  208. #include <ndistapi.h>
  209. #include "vTarget.h"
  210. #include "TpiDebug.h"
  211. #if !defined(IRP_MN_KERNEL_CALL) && !defined(PCI_SUBCLASS_DASP_OTHER)
  212. // This should be defined in the NTDDK 5.0 ndis.h, but it's not.
  213. // So I copied this here from ntddk.h to use with NdisQueryBufferSafe().
  214. typedef enum _MM_PAGE_PRIORITY {
  215. LowPagePriority,
  216. NormalPagePriority = 16,
  217. HighPagePriority = 32
  218. } MM_PAGE_PRIORITY;
  219. #endif
  220. // Figure out which DDK we're building with.
  221. #if defined(NDIS_LCODE)
  222. # if defined(NDIS_DOS)
  223. # define USING_WFW_DDK
  224. # define NDIS_MAJOR_VERSION 0x03
  225. # define NDIS_MINOR_VERSION 0x00
  226. # elif defined(OID_WAN_GET_INFO)
  227. # define USING_WIN98_DDK
  228. # elif defined(NDIS_WIN)
  229. # define USING_WIN95_DDK
  230. # else
  231. # error "BUILDING WITH UNKNOWN 9X DDK"
  232. # endif
  233. #elif defined(NDIS_NT)
  234. # if defined(OID_GEN_MACHINE_NAME)
  235. # define USING_NT51_DDK
  236. # elif defined(OID_GEN_SUPPORTED_GUIDS)
  237. # define USING_NT50_DDK
  238. # elif defined(OID_GEN_MEDIA_CONNECT_STATUS)
  239. # define USING_NT40_DDK
  240. # elif defined(OID_WAN_GET_INFO)
  241. # define USING_NT351_DDK
  242. # else
  243. # define USING_NT31_DDK
  244. # endif
  245. #else
  246. # error "BUILDING WITH UNKNOWN DDK"
  247. #endif
  248. // Figure out which DDK we should be building with.
  249. #if defined(NDIS51) || defined(NDIS51_MINIPORT)
  250. # if defined(USING_NT51_DDK)
  251. # define NDIS_MAJOR_VERSION 0x05
  252. # define NDIS_MINOR_VERSION 0x01
  253. # else
  254. # error "YOU MUST BUILD WITH THE NT 5.1 DDK"
  255. # endif
  256. #elif defined(NDIS50) || defined(NDIS50_MINIPORT)
  257. # if defined(USING_NT50_DDK) || defined(USING_NT51_DDK)
  258. # define NDIS_MAJOR_VERSION 0x05
  259. # define NDIS_MINOR_VERSION 0x00
  260. # else
  261. # error "YOU MUST BUILD WITH THE NT 5.0 DDK"
  262. # endif
  263. #elif defined(NDIS40) || defined(NDIS40_MINIPORT)
  264. # if defined(USING_NT40_DDK) || defined(USING_NT50_DDK) || defined(USING_NT51_DDK)
  265. # define NDIS_MAJOR_VERSION 0x04
  266. # define NDIS_MINOR_VERSION 0x00
  267. # else
  268. # error "YOU MUST BUILD WITH THE NT 4.0 or 5.0 DDK"
  269. # endif
  270. #elif defined(NDIS_MINIPORT_DRIVER)
  271. # if defined(USING_NT351_DDK) || defined(USING_NT40_DDK) || defined(USING_NT50_DDK) || defined(USING_NT51_DDK)
  272. # define NDIS_MAJOR_VERSION 0x03
  273. # define NDIS_MINOR_VERSION 0x00
  274. # else
  275. # error "YOU MUST BUILD WITH THE NT 3.51, 4.0, or 5.0 DDK"
  276. # endif
  277. #elif !defined(NDIS_MAJOR_VERSION) || !defined(NDIS_MINOR_VERSION)
  278. // Must be FULL MAC
  279. # define NDIS_MAJOR_VERSION 0x03
  280. # define NDIS_MINOR_VERSION 0x00
  281. #endif
  282. // Gotta nest NDIS_STRING_CONST or compiler/preprocessor won't be able to
  283. // handle L##DEFINED_STRING.
  284. #define INIT_STRING_CONST(name) NDIS_STRING_CONST(name)
  285. #define DECLARE_WIDE_STRING(name) L##name
  286. #define INIT_WIDE_STRING(name) DECLARE_WIDE_STRING(name)
  287. typedef struct MINIPORT_ADAPTER_OBJECT *PMINIPORT_ADAPTER_OBJECT;
  288. typedef struct BCHANNEL_OBJECT *PBCHANNEL_OBJECT;
  289. typedef struct DCHANNEL_OBJECT *PDCHANNEL_OBJECT;
  290. typedef struct CARD_OBJECT *PCARD_OBJECT;
  291. typedef struct PORT_OBJECT *PPORT_OBJECT;
  292. /*
  293. // The <t NDIS_MAC_LINE_UP> structure is confusing, so I redefine the
  294. // field name to be what makes sense.
  295. */
  296. #define MiniportLinkContext NdisLinkHandle
  297. #if defined(_VXD_) && !defined(NDIS_LCODE)
  298. # define NDIS_LCODE code_seg("_LTEXT", "LCODE")
  299. # define NDIS_LDATA data_seg("_LDATA", "LCODE")
  300. #endif
  301. /*
  302. // The link speeds we support.
  303. */
  304. #define _64KBPS 64000
  305. #define _56KBPS 56000
  306. #define MICROSECONDS (1)
  307. #define MILLISECONDS (1000*MICROSECONDS)
  308. #define SECONDS (1000*MILLISECONDS)
  309. #define TSPI_ADDRESS_ID 0
  310. /*
  311. // Include everything here so the driver modules can just include this
  312. // file and get all they need.
  313. */
  314. #include "Keywords.h"
  315. #include "Card.h"
  316. #include "Adapter.h"
  317. #include "BChannel.h"
  318. #include "CallMgr.h"
  319. #include "DChannel.h"
  320. #include "Port.h"
  321. #include "TpiParam.h"
  322. #include "TpiMem.h"
  323. /***************************************************************************
  324. // These routines are defined in Miniport.c
  325. */
  326. NTSTATUS DriverEntry(
  327. IN PDRIVER_OBJECT DriverObject,
  328. IN PUNICODE_STRING RegistryPath
  329. );
  330. NDIS_STATUS MiniportInitialize(
  331. OUT PNDIS_STATUS OpenErrorStatus,
  332. OUT PUINT SelectedMediumIndex,
  333. IN PNDIS_MEDIUM MediumArray,
  334. IN UINT MediumArraySize,
  335. IN NDIS_HANDLE MiniportAdapterHandle,
  336. IN NDIS_HANDLE WrapperConfigurationContext
  337. );
  338. void MiniportHalt(
  339. IN PMINIPORT_ADAPTER_OBJECT pAdapter
  340. );
  341. void MiniportShutdown(
  342. IN PMINIPORT_ADAPTER_OBJECT pAdapter
  343. );
  344. NDIS_STATUS MiniportReset(
  345. OUT PBOOLEAN AddressingReset,
  346. IN PMINIPORT_ADAPTER_OBJECT pAdapter
  347. );
  348. /***************************************************************************
  349. // These routines are defined in interrup.c
  350. */
  351. BOOLEAN MiniportCheckForHang(
  352. IN PMINIPORT_ADAPTER_OBJECT pAdapter
  353. );
  354. void MiniportDisableInterrupt(
  355. IN PMINIPORT_ADAPTER_OBJECT pAdapter
  356. );
  357. void MiniportEnableInterrupt(
  358. IN PMINIPORT_ADAPTER_OBJECT pAdapter
  359. );
  360. void MiniportHandleInterrupt(
  361. IN PMINIPORT_ADAPTER_OBJECT pAdapter
  362. );
  363. void MiniportISR(
  364. OUT PBOOLEAN InterruptRecognized,
  365. OUT PBOOLEAN QueueMiniportHandleInterrupt,
  366. IN PMINIPORT_ADAPTER_OBJECT pAdapter
  367. );
  368. void MiniportTimer(
  369. IN PVOID SystemSpecific1,
  370. IN PMINIPORT_ADAPTER_OBJECT pAdapter,
  371. IN PVOID SystemSpecific2,
  372. IN PVOID SystemSpecific3
  373. );
  374. /***************************************************************************
  375. // These routines are defined in receive.c
  376. */
  377. void ReceivePacketHandler(
  378. IN PBCHANNEL_OBJECT pBChannel,
  379. IN PNDIS_BUFFER pNdisBuffer,
  380. IN ULONG BytesReceived
  381. );
  382. VOID MiniportReturnPacket(
  383. IN PMINIPORT_ADAPTER_OBJECT pAdapter,
  384. IN PNDIS_PACKET pNdisPacket
  385. );
  386. /***************************************************************************
  387. // These routines are defined in request.c
  388. */
  389. NDIS_STATUS MiniportCoRequest(
  390. IN PMINIPORT_ADAPTER_OBJECT pAdapter,
  391. IN PBCHANNEL_OBJECT pBChannel,
  392. IN OUT PNDIS_REQUEST NdisRequest
  393. );
  394. /***************************************************************************
  395. // These routines are defined in transmit.c
  396. */
  397. VOID MiniportCoSendPackets(
  398. IN PBCHANNEL_OBJECT pBChannel,
  399. IN PPNDIS_PACKET PacketArray,
  400. IN UINT NumberOfPackets
  401. );
  402. void TransmitCompleteHandler(
  403. IN PMINIPORT_ADAPTER_OBJECT pAdapter
  404. );
  405. void FlushSendPackets(
  406. IN PMINIPORT_ADAPTER_OBJECT pAdapter,
  407. IN PBCHANNEL_OBJECT pBChannel
  408. );
  409. #endif // _MPDMAIN_H