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.

1001 lines
32 KiB

  1. // Copyright (c) 1997, Microsoft Corporation, all rights reserved
  2. // Copyright (c) 1997, Parallel Technologies, Inc., all rights reserved
  3. //
  4. // ptiwan.h
  5. // RAS DirectParallel WAN mini-port/call-manager driver
  6. // Main private header (precompiled)
  7. //
  8. // 01/07/97 Steve Cobb
  9. // 09/15/97 Jay Lowe, Parallel Technologies, Inc.
  10. //
  11. //
  12. // About naming:
  13. //
  14. // This driver contains code for both the DirectParallel mini-port and call
  15. // manager. All handler routines exported to NDIS are prefixed with either
  16. // 'Pti' for the mini-port handlers or 'PtiCm' for the call manager handlers.
  17. //
  18. //
  19. // About locks:
  20. //
  21. // Data structures that may change during simultaneous requests to different
  22. // processors in a multi-processor system must be protected with spin-locks or
  23. // accessed only with interlocked routines. Where locking is required to
  24. // access a data field in this header, the comment for that field indicates
  25. // same. A CoNDIS client is a trusted kernel mode component and presumed to
  26. // follow the documented call sequences of CoNDIS. Some access conflicts that
  27. // might be caused by goofy clients are not checked, though the easy ones are.
  28. // Cases where multiple clients might conflict are protected even though, for
  29. // now, the TAPI proxy is expected to be the only client.
  30. //
  31. #ifndef _PTIWAN_H_
  32. #define _PTIWAN_H_
  33. #include <ntddk.h>
  34. #include <ndis.h>
  35. #include <ndiswan.h>
  36. #include <ndistapi.h>
  37. //#include <ndisadd.h> // Temporary
  38. #include <debug.h>
  39. #include <bpool.h>
  40. #include <ppool.h>
  41. #include <ptilink.h> // PTILINK device (lower edge)
  42. //-----------------------------------------------------------------------------
  43. // Constants
  44. //-----------------------------------------------------------------------------
  45. // The NDIS version we report when registering mini-port and address family.
  46. //
  47. #define NDIS_MajorVersion 5
  48. #define NDIS_MinorVersion 0
  49. // Frame and buffer sizes. The "plus 2 times 2" is necessary to account for
  50. // the byte-stuffing that is necessary for Win9x legacy reasons. See the
  51. // HdlcFromAsyncFraming and AsyncFromHdlcFraming routines.
  52. //
  53. #define PTI_MaxFrameSize 1500
  54. #define PTI_FrameBufferSize (((PTI_MaxFrameSize + 2) * 2) + 32)
  55. // Default reported speed of a DirectParallel in bits/second.
  56. // ??? dynamically report line speed
  57. //
  58. #define PTI_LanBps 4000000 // 100K Bytes/sec typical 4BIT
  59. // 500K Bytes/sec typical enhanced
  60. //-----------------------------------------------------------------------------
  61. // Data types
  62. //-----------------------------------------------------------------------------
  63. // Forward declarations.
  64. //
  65. typedef struct _VCCB VCCB;
  66. // Adapter control block defining the state of a single DirectParallel
  67. // connection. The DirectParallel driver may support simultaneous connections
  68. // over multiple LPT ports on the same machine
  69. //
  70. // ??? Do we support multiple LPT connections on one machine
  71. // ??? Need to check PTILINK, here in PTIWAN we will allow them
  72. //
  73. // ADAPTERCBs are allocated in MiniportInitialize and deallocated in
  74. // MiniportHalt.
  75. //
  76. typedef struct
  77. _ADAPTERCB
  78. {
  79. // Set to MTAG_ADAPTERCB for easy identification in memory dumps and use
  80. // in assertions.
  81. //
  82. ULONG ulTag;
  83. // Reference count on this control block. The reference pairs are:
  84. //
  85. // (a) A reference is added when the MiniportAdapterHandle field is set,
  86. // i.e. when LmpInitialize succeeds and cleared when the LmpHalt
  87. // handler is called. The adapter block is actually passed to NDIS
  88. // before it's known if LmpInitialize will succeed but according to
  89. // ArvindM NDIS will not call halt unless it succeeds.
  90. //
  91. // (b) A reference is added when the NdisAfHandle field is set and removed
  92. // when it is cleared.
  93. //
  94. // (c) A reference is added when the NdisSapHandle field is set and
  95. // removed when it is cleared.
  96. //
  97. // (d) A reference is added for the VCCB's back pointer and removed when
  98. // the VCCB is freed.
  99. //
  100. // (e) A reference is added when an NDIS_WORK_ITEM is scheduled and
  101. // removed when it has completed.
  102. //
  103. // Access is via ReferenceAdapter and DereferenceAdapter only.
  104. //
  105. LONG lRef;
  106. // ACBF_* bit flags indicating various options. Access restrictions are
  107. // indicated for each individual flag.
  108. //
  109. // ACBF_SapActive: Set when the NdisSapHandle may be used with incoming
  110. // calls. Access is protected by 'lockSap'.
  111. //
  112. ULONG ulFlags;
  113. #define ACBF_SapActive 0x00000001
  114. // Our framing and bearer capablities bit masks as passed in StartCcReq.
  115. //
  116. ULONG ulFramingCaps;
  117. ULONG ulBearerCaps;
  118. // Milliseconds to delay OpenAf to give PARPORT a chance to initialize all
  119. // the parallel ports, and the secondary delay to perform only if no
  120. // parallel ports are enumerated after the first wait.
  121. //
  122. ULONG ulParportDelayMs;
  123. ULONG ulExtraParportDelayMs;
  124. // Got to keep handles on all open PtiLink ports to prevent reopen
  125. // due to bizarrely involuted CoNdis sequences re Saps and Vcs
  126. //
  127. HANDLE hPtiLinkTable[NPORTS];
  128. // Table of TAPI Line Ids by port
  129. //
  130. ULONG ulLineIds[NPORTS];
  131. // Table of PtiLink interface status bit flags by port
  132. //
  133. ULONG ulPtiLinkState[NPORTS];
  134. #define PLSF_PortExists 0x00000001
  135. #define PLSF_LineIdValid 0x00000002
  136. // Parallel port name. Valid only when port exists.
  137. //
  138. WCHAR szPortName[ NPORTS ][ MAXLPTXNAME + 1 ];
  139. // VC TABLE --------------------------------------------------------------
  140. // The maximum number of simultaneous VCs. The value is read from the
  141. // registry during initialization.
  142. //
  143. // ??? This is currently used as the maximum LPT port index in validation,
  144. // though this may need to change if PTILINK can return a disjoint set of
  145. // LPT ports
  146. //
  147. USHORT usMaxVcs;
  148. // The actual number of devices for Vcs available to RasPti via PtiLink
  149. // Determined at OID_CO_TAPI_CM_CAPS time using PtiQueryDeviceStatus
  150. //
  151. ULONG ulActualVcs;
  152. // Table of Temporary Listening VCCBs, one for each possible port.
  153. // We open PtiLink for listening at RegisterSap time, and we
  154. // don't have a Vc then. So, at RegisterSap time, we'll make a
  155. // VCCB, put a pointer to it here, and use it to listen on.
  156. VCCB* pListenVc;
  157. // RESOURCE POOLS --------------------------------------------------------
  158. // Lookaside list of NDIS_WORK_ITEM scheduling descriptors with extra
  159. // context space used by all tunnels and VCs attached to the adapter.
  160. //
  161. NPAGED_LOOKASIDE_LIST llistWorkItems;
  162. // Lookaside list of VCCBs from which the control blocks dynamically
  163. // attached to '*ppVcs' are allocated.
  164. //
  165. NPAGED_LOOKASIDE_LIST llistVcs;
  166. // Pool of full frame buffers with pre-attached NDIS_BUFFER descriptors.
  167. // The pool is accessed via the interface defined in bpool.h, which
  168. // handles all locking internally.
  169. //
  170. BUFFERPOOL poolFrameBuffers;
  171. PNDIS_HANDLE phBufferPool;
  172. // Pool of NDIS_PACKET descriptors used in indication of received frames.
  173. // The pool is accessed via the interface defined in ppool.h, which
  174. // handles all locking internally.
  175. //
  176. PACKETPOOL poolPackets;
  177. PNDIS_HANDLE phPacketPool;
  178. // NDIS BOOKKEEPING ------------------------------------------------------
  179. // NDIS's handle for this mini-port adapter passed to us in
  180. // MiniportInitialize. This is passed back to various NdisXxx calls.
  181. //
  182. NDIS_HANDLE MiniportAdapterHandle;
  183. // NDIS's handle for our SAP as passed to our CmRegisterSapHandler or NULL
  184. // if none. Only one SAP handle is supported because (a) the TAPI proxy's
  185. // is expected to be the only one, and (b) there are no PTI SAP properties
  186. // that would ever lead us to direct a call to a second SAP anyway. Any
  187. // client's attempt to register a second SAP will fail. A value of NULL
  188. // indicates no SAP handle is currently registered. Access is via
  189. // Interlocked routines.
  190. //
  191. NDIS_HANDLE NdisSapHandle;
  192. // NDIS's handle for our Address Family as passed to our CmOpenAfHandler
  193. // or NULL if none. Only one is supported. See NdisSapHandle above.
  194. // Access is via Interlocked routines.
  195. //
  196. NDIS_HANDLE NdisAfHandle;
  197. // Reference count on the NdisAfHandle. The reference pairs are:
  198. //
  199. // (a) A reference is added when the address family is opened and removed
  200. // when it is closed.
  201. //
  202. // (b) A reference is added when a SAP is registered on the address family
  203. // and removed when it is deregistered.
  204. //
  205. // (c) A reference is added when a VC is created on the address family and
  206. // removed when it is deleted.
  207. //
  208. // Access is via ReferenceAf and DereferenceAf only.
  209. //
  210. LONG lAfRef;
  211. // Reference count on the NdisSapHandle. The reference pairs are:
  212. //
  213. // (a) A reference is added when the SAP is registered and removed when it
  214. // is de-registered.
  215. //
  216. // (b) A reference is added when a tunnels TCBF_SapReferenced flag is set
  217. // and removed when the flag is cleared before the tunnel control
  218. // block is freed.
  219. //
  220. // (c) A reference is always added before accesses ADAPTERCB.pListenVc and
  221. // removed afterward.
  222. //
  223. // Access is via ReferenceSap and DereferenceSap only, excepting initial
  224. // reference by RegisterSapPassive. Access is protected by 'lockSap'.
  225. //
  226. LONG lSapRef;
  227. // 0-based port index of the port to listen on. Valid only when
  228. // 'NdisSapHandle' is non-NULL.
  229. //
  230. // ??? Is listening on only 1 port at a time a problem?
  231. //
  232. ULONG ulSapPort;
  233. // This lock protects the 'lSapRef' and 'NdisSapHandle' fields.
  234. //
  235. NDIS_SPIN_LOCK lockSap;
  236. // This adapter's capabilities as returned to callers on
  237. // OID_WAN_CO_GET_INFO. These capabilities are also used as defaults for
  238. // the corresponding VCCB.linkinfo settings during MiniportCoCreateVc.
  239. //
  240. NDIS_WAN_CO_INFO info;
  241. }
  242. ADAPTERCB;
  243. // Virtual circuit control block defining the state of a single PTI VC, i.e.
  244. // one line device endpoint and the call, if any, active on it. A VC is never
  245. // used for incoming and outgoing calls simultaneously. A single NDIS VC maps
  246. // to one of these.
  247. //
  248. typedef struct
  249. _VCCB
  250. {
  251. // Set to MTAG_VCCB for easy identification in memory dumps and use in
  252. // assertions.
  253. //
  254. ULONG ulTag;
  255. // Reference count on this VC control block. The reference pairs are:
  256. //
  257. // (a) PtiCoCreateVc adds a reference that is removed by PtiCoDeleteVc.
  258. // This covers all clients that learn of the VCCB via NDIS.
  259. //
  260. // (b) All PtiCmXxx handlers take a reference on entry that is released
  261. // before exit.
  262. //
  263. // (c) For the "listen" VC, a reference is taken when a SAP is registered
  264. // and removed when the SAP is deregistered.
  265. //
  266. // The field is accessed only by the ReferenceVc and DereferenceVc
  267. // routines, which protect with Interlocked routines.
  268. //
  269. LONG lRef;
  270. // Back pointer to owning adapter's control block.
  271. //
  272. ADAPTERCB* pAdapter;
  273. // This lock protects VCCB payload send and receive paths as noted in
  274. // other field descriptions. In cases where both 'lockV' and
  275. // 'pTunnel->lockT' are required 'lockT' must be obtained first.
  276. //
  277. NDIS_SPIN_LOCK lockV;
  278. // Lower edge API stuff --------------------------------------------------
  279. // file handle on the PTILINKx device, <>0 means we have device open
  280. HANDLE hPtiLink;
  281. // Parallel Port Index (0=LPT1) in use for this VC
  282. ULONG ulVcParallelPort;
  283. // pointer to device extension for the PTILINKx device
  284. PVOID Extension;
  285. // pointer to the PTILINK internal extension within the device extension
  286. // this is a bit hacky, but it appears too complex to include the
  287. // internal PtiLink structures (PtiStruc.h) here
  288. // so we'll have PtiInitialize return pointers to both
  289. PVOID PtiExtension;
  290. // CALL SETUP ------------------------------------------------------------
  291. // Our unique call identifier sent back to us by peer in the L2TP header.
  292. // The value is a 1-based index into the 'ADAPTERCB.ppVcs' array.
  293. //
  294. USHORT usCallId;
  295. // VCBF_* bit flags indicating various options and states. Access is via
  296. // the interlocked ReadFlags/SetFlags/ClearFlags routines.
  297. //
  298. // VCBF_IndicateReceivedTime: Set if MakeCall caller sets the
  299. // MediaParameters.Flags RECEIVE_TIME_INDICATION flag requesting the
  300. // TimeReceived field of the NDIS packet be filled with a timestamp.
  301. //
  302. // VCBF_CallClosableByClient: Set when a call is in a state where
  303. // PtiCmCloseCall requests to initiate clean-up should be accepted.
  304. // This may be set when VCBF_CallClosableByPeer is not, which means we
  305. // have indicated an incoming close to client and are waiting for him
  306. // to do a client close in response (in that weird CoNDIS way). The
  307. // flag is protected by 'lockV'.
  308. //
  309. // VCBF_CallClosableByPeer: Set when the call is in a state where an idle
  310. // transition without operations pending should be mapped to a
  311. // PeerClose event. This will never be set when
  312. // VCBF_CallClosableByClient is not. The flag is protected by
  313. // 'lockV'.
  314. //
  315. // VCBF_PeerInitiatedCall: Set when an the active call was initiated by
  316. // the peer, clear if it was initiated by the client.
  317. //
  318. // VCBF_VcCreated: Set when the VC has been created successfully. This is
  319. // the "creation" that occurs with the client, not the mini-port.
  320. // VCBF_VcActivated: Set when the VC has been activated successfully.
  321. // VCBF_VcDispatched: Set when the VC has dispatched an incoming call to
  322. // the client.
  323. // VCBM_VcState: Bit mask that includes each of the 3 NDIS state flags.
  324. //
  325. // The pending bits below are mutually exclusive, and so require lock
  326. // protection by 'lockV':
  327. //
  328. // VCBF_PeerOpenPending: Set when peer attempts to establish a call, and
  329. // the result is not yet known.
  330. // VCBF_ClientOpenPending: Set when client attempts to establish a call,
  331. // and the result is not yet known.
  332. // VCBF_PeerClosePending: Set when peer attempts to close an established
  333. // call and the result is not yet known. Access is protected by
  334. // 'lockV'.
  335. // VCBF_ClientClosePending: Set when client attempts to close an
  336. // established call and the result is not yet known. Access is
  337. // protected by 'lockV'.
  338. // VCBLM_Pending: Bit mask that includes each of the 4 pending flags.
  339. //
  340. // VCBF_ClientCloseCompletion: Set when client close completion is in
  341. // progress.
  342. // VCBF_CallInProgress: Set when incoming packets should not trigger the
  343. // setup of a new incoming call.
  344. //
  345. ULONG ulFlags;
  346. #define VCBF_IndicateTimeReceived 0x00000001
  347. #define VCBF_CallClosableByClient 0x00000002
  348. #define VCBF_CallClosableByPeer 0x00000004
  349. #define VCBF_IncomingFsm 0x00000010
  350. #define VCBF_PeerInitiatedCall 0x00000020
  351. #define VCBF_Sequencing 0x00000040
  352. #define VCBF_VcCreated 0x00000100
  353. #define VCBF_VcActivated 0x00000200
  354. #define VCBF_VcDispatched 0x00000400
  355. #define VCBM_VcState 0x00000700
  356. #define VCBF_VcCloseDispatched 0x00000800
  357. #define VCBF_PeerOpenPending 0x00001000
  358. #define VCBF_ClientOpenPending 0x00002000
  359. #define VCBF_PeerClosePending 0x00004000
  360. #define VCBF_ClientClosePending 0x00008000
  361. #define VCBM_Pending 0x0000F000
  362. #define VCBF_ClientCloseCompletion 0x00010000
  363. #define VCBF_CallInProgress 0x00020000
  364. // Reference count on the active call. References may only be added when
  365. // the VCCB_VcActivated flag is set, and this is enforced by
  366. // ReferenceCall. The reference pairs are:
  367. //
  368. // (a) A reference is added when a VC is activated and removed when it is
  369. // de-activated.
  370. //
  371. // (b) A reference is added when the send handler accepts a packet and
  372. // released by the send complete routine.
  373. //
  374. // (c) A reference is added before entering PtiRx and removed on exit from
  375. // same.
  376. //
  377. // The field is accessed only by the ReferenceCall and DereferenceCall
  378. // routines, which protect the field with 'lockCall'.
  379. //
  380. LONG lCallRef;
  381. NDIS_SPIN_LOCK lockCall;
  382. // This is set to the result to be reported to client and is meaningful
  383. // only when the VC is on the tunnels list of completing VCs.
  384. //
  385. NDIS_STATUS status;
  386. // Address of the call parameters block passed up in
  387. // NdisMCmDispatchIncomingCall, or NULL if none.
  388. //
  389. CO_CALL_PARAMETERS* pInCall;
  390. // Shortcut address of the TAPI-specific call parameters in the 'pInCall'
  391. // incoming call buffer. Valid only when 'pInCall' is valid, i.e.
  392. // non-NULL.
  393. //
  394. CO_AF_TAPI_INCOMING_CALL_PARAMETERS* pTiParams;
  395. // Address of the call parameters passed down in CmMakeCall. This field
  396. // will only be valid until the NdisMCmMakeCallComplete notification for
  397. // the associated call is made, at which time it is reset to NULL. Access
  398. // is via Interlocked routines.
  399. //
  400. CO_CALL_PARAMETERS* pMakeCall;
  401. // Shortcut address of the TAPI-specific call parameters in the
  402. // 'pMakeCall' outgoing call buffer. Valid only when 'pMakeCall' is
  403. // valid, i.e. non-NULL.
  404. //
  405. CO_AF_TAPI_MAKE_CALL_PARAMETERS UNALIGNED* pTmParams;
  406. // The result and error to report in the coming incoming/outgoing call
  407. // reply message.
  408. //
  409. USHORT usResult;
  410. USHORT usError;
  411. // The connect speed in bits/second. This is the value reported to
  412. // NDISWAN.
  413. //
  414. ULONG ulConnectBps;
  415. // Number of packets across the link since PtiOpenPtiLink
  416. //
  417. ULONG ulTotalPackets;
  418. // SEND STATE ------------------------------------------------------------
  419. // Next Sent, the sequence number of next payload packet transmitted on
  420. // this call. The field is initialized to 0 and incremented after
  421. // assignment to an outgoing packet, excepting retransmissions. Access is
  422. // protected by 'lockV'.
  423. //
  424. USHORT usNs;
  425. // Double-linked list of outstanding sends, i.e. PAYLOADSENTs sorted by
  426. // the 'usNs' field with lower values near the head. Access is protected
  427. // by 'lockV'.
  428. //
  429. LIST_ENTRY listSendsOut;
  430. // The number of sent but unacknowledged packets that may be outstanding.
  431. // This value is adjusted dynamically. Per the draft/RFC, when
  432. // 'ulAcksSinceSendTimeout' reaches the current setting, the window is
  433. // increased by one. When a send timeout expires the window is reduced by
  434. // half. The actual send window throttling is done by NDISWAN, based on
  435. // our indications of the changing window size. Access is protected by
  436. // 'lockV'.
  437. //
  438. ULONG ulSendWindow;
  439. // The maximum value of 'ulSendWindow'. Peer chooses this value during
  440. // call setup.
  441. //
  442. ULONG ulMaxSendWindow;
  443. // The number of packets acknowledged since the last timeout. The value
  444. // is reset when a timeout occurs or the send window is adjusted upward.
  445. // See 'ulSendWindow'. Access is protected by 'lockV'.
  446. //
  447. ULONG ulAcksSinceSendTimeout;
  448. // The estimated round trip time in milliseconds. This is the RTT value
  449. // from Appendix A of the draft/RFC. The value is adjusted as each
  450. // acknowledge is received. It is initialized to the Packet Processing
  451. // Delay reported by peer. See 'ulSendTimeoutMs'. Access is protected by
  452. // 'lockV'.
  453. //
  454. ULONG ulRoundTripMs;
  455. // The estimated mean deviation in milliseconds, an approximation of the
  456. // standard deviation. This is the DEV value from Appendix A of the
  457. // draft/RFC. The value is adjusted as each acknowledge is received. It
  458. // is initially 0. See 'ulSendTimeoutMs'. Access is protected by
  459. // 'lockV'.
  460. //
  461. LONG lDeviationMs;
  462. // Milliseconds before it is assumed a sent packet will never be
  463. // acknowledged. This is the ATO value from Appendix A of the draft/RFC.
  464. // This value is adjusted as each acknowledge is received, with a maximum
  465. // of 'ADAPTERCB.ulMaxSendTimeoutMs'. Access is protected by 'lockV'.
  466. //
  467. ULONG ulSendTimeoutMs;
  468. // The timer event descriptor scheduled to occur when it is time to stop
  469. // waiting for an outgoing send on which to piggyback an acknowledge.
  470. // This will be NULL when no delayed acknowledge is pending. Per the
  471. // draft/RFC, the timeout used is 1/4 of the 'ulSendTimeoutMs'. Access is
  472. // protected by 'lockV'.
  473. //
  474. // TIMERQITEM* pTqiDelayedAck;
  475. // RECEIVE STATE ---------------------------------------------------------
  476. // Next Received, the sequence number one higher than that of the last
  477. // payload packet received on this call or 0 if none. Access is protected
  478. // by 'lockV'.
  479. //
  480. USHORT usNr;
  481. // Double-linked list of out-of-order receives, i.e. PAYLOADRECEIVEs
  482. // sorted by the 'usNs' field with lower values near the head. The
  483. // maximum queue length is 'ADAPTERCB.sMaxOutOfOrder'. Access is
  484. // protected by 'lockV'.
  485. //
  486. LIST_ENTRY listOutOfOrder;
  487. // The timer event descriptor scheduled to occur when it is time to assume
  488. // peer's current 'Next Received' packet has been lost, and "receive" the
  489. // first packet in 'listOutOfOrder'. This will be NULL when
  490. // 'listOutOfOrder' is empty. Access is protected by 'lockV'.
  491. //
  492. // TIMERQITEM* pTqiAssumeLost;
  493. // NDIS BOOKKEEPING ------------------------------------------------------
  494. // NDIS's handle for this VC passed to us in MiniportCoCreateVcHandler.
  495. // This is passed back to NDIS in various NdisXxx calls.
  496. //
  497. NDIS_HANDLE NdisVcHandle;
  498. // Configuration settings returned to callers on OID_WAN_CO_GET_INFO and
  499. // modified by callers on OID_WAN_CO_SET_INFO. Older NDISWAN references to
  500. // "LINK" map straight to "VC" in the NDIS 5.0 world. Access is not
  501. // protected because each ULONG in the structure is independent so no
  502. // incoherency can result from multiple access.
  503. //
  504. NDIS_WAN_CO_GET_LINK_INFO linkinfo;
  505. }
  506. VCCB;
  507. //-----------------------------------------------------------------------------
  508. // Macros/inlines
  509. //-----------------------------------------------------------------------------
  510. // These basics are not in the DDK headers for some reason.
  511. //
  512. #define min( a, b ) (((a) < (b)) ? (a) : (b))
  513. #define max( a, b ) (((a) > (b)) ? (a) : (b))
  514. #define InsertBefore( pNewL, pL ) \
  515. { \
  516. (pNewL)->Flink = (pL); \
  517. (pNewL)->Blink = (pL)->Blink; \
  518. (pNewL)->Flink->Blink = (pNewL); \
  519. (pNewL)->Blink->Flink = (pNewL); \
  520. }
  521. #define InsertAfter( pNewL, pL ) \
  522. { \
  523. (pNewL)->Flink = (pL)->Flink; \
  524. (pNewL)->Blink = (pL); \
  525. (pNewL)->Flink->Blink = (pNewL); \
  526. (pNewL)->Blink->Flink = (pNewL); \
  527. }
  528. // Winsock-ish host/network byte order converters for short and long integers.
  529. //
  530. #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037)) || ((defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_FULL_VER > 13009175))
  531. #define htons(x) _byteswap_ushort((USHORT)(x))
  532. #define htonl(x) _byteswap_ulong((ULONG)(x))
  533. #else
  534. #define htons( a ) ((((a) & 0xFF00) >> 8) |\
  535. (((a) & 0x00FF) << 8))
  536. #define htonl( a ) ((((a) & 0xFF000000) >> 24) | \
  537. (((a) & 0x00FF0000) >> 8) | \
  538. (((a) & 0x0000FF00) << 8) | \
  539. (((a) & 0x000000FF) << 24))
  540. #endif
  541. #define ntohs( a ) htons(a)
  542. #define ntohl( a ) htonl(a)
  543. // Place in a TRACE argument list to correspond with a format of "%d.%d.%d.%d"
  544. // to print network byte-ordered IP address 'x' in human readable form.
  545. //
  546. #define IPADDRTRACE(x) ((x) & 0x000000FF), \
  547. (((x) >> 8) & 0x000000FF), \
  548. (((x) >> 16) & 0x000000FF), \
  549. (((x) >> 24) & 0x000000FF)
  550. // All memory allocations and frees are done with these ALLOC_*/FREE_*
  551. // macros/inlines to allow memory management scheme changes without global
  552. // editing. For example, might choose to lump several lookaside lists of
  553. // nearly equal sized items into a single list for efficiency.
  554. //
  555. // NdisFreeMemory requires the length of the allocation as an argument. NT
  556. // currently doesn't use this for non-paged memory, but according to JameelH,
  557. // Windows95 does. These inlines stash the length at the beginning of the
  558. // allocation, providing the traditional malloc/free interface.
  559. //
  560. __inline
  561. VOID*
  562. ALLOC_NONPAGED(
  563. IN ULONG ulBufLength,
  564. IN ULONG ulTag )
  565. {
  566. CHAR* pBuf;
  567. NdisAllocateMemoryWithTag(
  568. &pBuf, (UINT )(ulBufLength + MEMORY_ALLOCATION_ALIGNMENT), ulTag );
  569. if (!pBuf)
  570. {
  571. return NULL;
  572. }
  573. ((ULONG* )pBuf)[ 0 ] = ulBufLength;
  574. ((ULONG* )pBuf)[ 1 ] = ulTag;
  575. return pBuf + MEMORY_ALLOCATION_ALIGNMENT;
  576. }
  577. __inline
  578. VOID
  579. FREE_NONPAGED(
  580. IN VOID* pBuf )
  581. {
  582. ULONG ulBufLen;
  583. ulBufLen = *((ULONG* )(((CHAR* )pBuf) - MEMORY_ALLOCATION_ALIGNMENT));
  584. NdisFreeMemory(
  585. ((CHAR* )pBuf) - MEMORY_ALLOCATION_ALIGNMENT,
  586. (UINT )(ulBufLen + MEMORY_ALLOCATION_ALIGNMENT),
  587. 0 );
  588. }
  589. #define ALLOC_VCCB( pA ) \
  590. NdisAllocateFromNPagedLookasideList( &(pA)->llistVcs )
  591. #define FREE_VCCB( pA, pV ) \
  592. NdisFreeToNPagedLookasideList( &(pA)->llistVcs, (pV) )
  593. #define ALLOC_NDIS_WORK_ITEM( pA ) \
  594. NdisAllocateFromNPagedLookasideList( &(pA)->llistWorkItems )
  595. #define FREE_NDIS_WORK_ITEM( pA, pNwi ) \
  596. NdisFreeToNPagedLookasideList( &(pA)->llistWorkItems, (pNwi) )
  597. //-----------------------------------------------------------------------------
  598. // Prototypes (alphabetically)
  599. //-----------------------------------------------------------------------------
  600. VOID
  601. CallCleanUp(
  602. IN VCCB* pVc );
  603. VOID
  604. CallTransitionComplete(
  605. IN VCCB* pVc );
  606. VOID
  607. ClearFlags(
  608. IN OUT ULONG* pulFlags,
  609. IN ULONG ulMask );
  610. VOID
  611. CloseCallPassive(
  612. IN NDIS_WORK_ITEM* pWork,
  613. IN VOID* pContext );
  614. VOID
  615. CompleteVc(
  616. IN VCCB* pVc );
  617. VOID
  618. DereferenceAdapter(
  619. IN ADAPTERCB* pAdapter );
  620. VOID
  621. DereferenceAf(
  622. IN ADAPTERCB* pAdapter );
  623. VOID
  624. DereferenceCall(
  625. IN VCCB* pVc );
  626. VOID
  627. DereferenceSap(
  628. IN ADAPTERCB* pAdapter );
  629. VOID
  630. DereferenceVc(
  631. IN VCCB* pVc );
  632. BOOLEAN
  633. IsWin9xPeer(
  634. IN VCCB* pVc );
  635. PVOID
  636. PtiCbGetReadBuffer(
  637. IN PVOID pVc,
  638. OUT PULONG BufferSize,
  639. OUT PVOID* RequestContext
  640. );
  641. VOID
  642. PtiRx(
  643. IN PVOID pVc,
  644. IN PVOID ReadBuffer,
  645. IN NTSTATUS Status,
  646. IN ULONG BytesTransfered,
  647. IN PVOID RequestContext
  648. );
  649. VOID
  650. PtiCbLinkEventHandler(
  651. IN PVOID pVc,
  652. IN ULONG PtiLinkEventId,
  653. IN ULONG PtiLinkEventData
  654. );
  655. NDIS_STATUS
  656. PtiCmOpenAf(
  657. IN NDIS_HANDLE CallMgrBindingContext,
  658. IN PCO_ADDRESS_FAMILY AddressFamily,
  659. IN NDIS_HANDLE NdisAfHandle,
  660. OUT PNDIS_HANDLE CallMgrAfContext );
  661. NDIS_STATUS
  662. PtiCmCloseAf(
  663. IN NDIS_HANDLE CallMgrAfContext );
  664. NDIS_STATUS
  665. PtiCmRegisterSap(
  666. IN NDIS_HANDLE CallMgrAfContext,
  667. IN PCO_SAP Sap,
  668. IN NDIS_HANDLE NdisSapHandle,
  669. OUT PNDIS_HANDLE CallMgrSapContext );
  670. VOID
  671. RegisterSapPassive(
  672. IN NDIS_WORK_ITEM* pWork,
  673. IN VOID* pContext );
  674. NDIS_STATUS
  675. PtiCmDeregisterSap(
  676. NDIS_HANDLE CallMgrSapContext );
  677. VOID
  678. DeregisterSapPassive(
  679. IN NDIS_WORK_ITEM* pWork,
  680. IN VOID* pContext );
  681. NDIS_STATUS
  682. PtiCmCreateVc(
  683. IN NDIS_HANDLE ProtocolAfContext,
  684. IN NDIS_HANDLE NdisVcHandle,
  685. OUT PNDIS_HANDLE ProtocolVcContext );
  686. NDIS_STATUS
  687. PtiCmDeleteVc(
  688. IN NDIS_HANDLE ProtocolVcContext );
  689. NDIS_STATUS
  690. PtiCmMakeCall(
  691. IN NDIS_HANDLE CallMgrVcContext,
  692. IN OUT PCO_CALL_PARAMETERS CallParameters,
  693. IN NDIS_HANDLE NdisPartyHandle,
  694. OUT PNDIS_HANDLE CallMgrPartyContext );
  695. VOID
  696. MakeCallPassive(
  697. IN NDIS_WORK_ITEM* pWork,
  698. IN VOID* pContext );
  699. NDIS_STATUS
  700. PtiCmCloseCall(
  701. IN NDIS_HANDLE CallMgrVcContext,
  702. IN NDIS_HANDLE CallMgrPartyContext,
  703. IN PVOID CloseData,
  704. IN UINT Size );
  705. VOID
  706. PtiCmIncomingCallComplete(
  707. IN NDIS_STATUS Status,
  708. IN NDIS_HANDLE CallMgrVcContext,
  709. IN PCO_CALL_PARAMETERS CallParameters );
  710. VOID
  711. PtiCmActivateVcComplete(
  712. IN NDIS_STATUS Status,
  713. IN NDIS_HANDLE CallMgrVcContext,
  714. IN PCO_CALL_PARAMETERS CallParameters );
  715. VOID
  716. PtiCmDeactivateVcComplete(
  717. IN NDIS_STATUS Status,
  718. IN NDIS_HANDLE CallMgrVcContext );
  719. NDIS_STATUS
  720. PtiCmModifyCallQoS(
  721. IN NDIS_HANDLE CallMgrVcContext,
  722. IN PCO_CALL_PARAMETERS CallParameters );
  723. NDIS_STATUS
  724. PtiCmRequest(
  725. IN NDIS_HANDLE CallMgrAfContext,
  726. IN NDIS_HANDLE CallMgrVcContext,
  727. IN NDIS_HANDLE CallMgrPartyContext,
  728. IN OUT PNDIS_REQUEST NdisRequest );
  729. NDIS_STATUS
  730. PtiInit(
  731. OUT PNDIS_STATUS OpenErrorStatus,
  732. OUT PUINT SelectedMediumIndex,
  733. IN PNDIS_MEDIUM MediumArray,
  734. IN UINT MediumArraySize,
  735. IN NDIS_HANDLE MiniportAdapterHandle,
  736. IN NDIS_HANDLE WrapperConfigurationContext );
  737. VOID
  738. PtiHalt(
  739. IN NDIS_HANDLE MiniportAdapterContext );
  740. NDIS_STATUS
  741. PtiReset(
  742. OUT PBOOLEAN AddressingReset,
  743. IN NDIS_HANDLE MiniportAdapterContext );
  744. VOID
  745. PtiReturnPacket(
  746. IN NDIS_HANDLE MiniportAdapterContext,
  747. IN PNDIS_PACKET Packet );
  748. NDIS_STATUS
  749. PtiQueryInformation(
  750. IN NDIS_HANDLE MiniportAdapterContext,
  751. IN NDIS_OID Oid,
  752. IN PVOID InformationBuffer,
  753. IN ULONG InformationBufferLength,
  754. OUT PULONG BytesWritten,
  755. OUT PULONG BytesNeeded );
  756. NDIS_STATUS
  757. PtiSetInformation(
  758. IN NDIS_HANDLE MiniportAdapterContext,
  759. IN NDIS_OID Oid,
  760. IN PVOID InformationBuffer,
  761. IN ULONG InformationBufferLength,
  762. OUT PULONG BytesRead,
  763. OUT PULONG BytesNeeded );
  764. NDIS_STATUS
  765. PtiCoActivateVc(
  766. IN NDIS_HANDLE MiniportVcContext,
  767. IN OUT PCO_CALL_PARAMETERS CallParameters );
  768. NDIS_STATUS
  769. PtiCoDeactivateVc(
  770. IN NDIS_HANDLE MiniportVcContext );
  771. VOID
  772. PtiCoSendPackets(
  773. IN NDIS_HANDLE MiniportVcContext,
  774. IN PPNDIS_PACKET PacketArray,
  775. IN UINT NumberOfPackets );
  776. NDIS_STATUS
  777. PtiCoRequest(
  778. IN NDIS_HANDLE MiniportAdapterContext,
  779. IN NDIS_HANDLE MiniportVcContext,
  780. IN OUT PNDIS_REQUEST NdisRequest );
  781. VOID
  782. PtiReceive(
  783. IN VOID* pAddress,
  784. IN CHAR* pBuffer,
  785. IN ULONG ulOffset,
  786. IN ULONG ulBufferLen );
  787. ULONG
  788. ReadFlags(
  789. IN ULONG* pulFlags );
  790. VOID
  791. ReferenceAdapter(
  792. IN ADAPTERCB* pAdapter );
  793. VOID
  794. ReferenceAf(
  795. IN ADAPTERCB* pAdapter );
  796. BOOLEAN
  797. ReferenceCall(
  798. IN VCCB* pVc );
  799. BOOLEAN
  800. ReferenceSap(
  801. IN ADAPTERCB* pAdapter );
  802. VOID
  803. ReferenceVc(
  804. IN VCCB* pVc );
  805. NDIS_STATUS
  806. ScheduleWork(
  807. IN ADAPTERCB* pAdapter,
  808. IN NDIS_PROC pProc,
  809. IN PVOID pContext );
  810. VOID
  811. SendClientString(
  812. IN PVOID pPtiExtension );
  813. VOID
  814. SetFlags(
  815. IN OUT ULONG* pulFlags,
  816. IN ULONG ulMask );
  817. VOID
  818. SetupVcAsynchronously(
  819. IN ADAPTERCB* pAdapter );
  820. ULONG
  821. StrCmp(
  822. IN LPSTR cs,
  823. IN LPSTR ct,
  824. ULONG n );
  825. ULONG
  826. StrCmpW(
  827. IN WCHAR* psz1,
  828. IN WCHAR* psz2 );
  829. VOID
  830. StrCpyW(
  831. IN WCHAR* psz1,
  832. IN WCHAR* psz2 );
  833. CHAR*
  834. StrDup(
  835. IN CHAR* psz );
  836. CHAR*
  837. StrDupNdisString(
  838. IN NDIS_STRING* pNdisString );
  839. CHAR*
  840. StrDupSized(
  841. IN CHAR* psz,
  842. IN ULONG ulLength,
  843. IN ULONG ulExtra );
  844. ULONG
  845. StrLenW(
  846. IN WCHAR* psz );
  847. #endif // _PTIWAN_H_