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.

2705 lines
86 KiB

  1. // Copyright (c) 1997, Microsoft Corporation, all rights reserved
  2. //
  3. // l2tpp.h
  4. // RAS L2TP WAN mini-port/call-manager driver
  5. // Main private header (precompiled)
  6. //
  7. // 01/07/97 Steve Cobb
  8. //
  9. //
  10. // About naming:
  11. //
  12. // This driver contains code for both the L2TP mini-port and the L2TP call
  13. // manager. All handler routines exported to NDIS are prefixed with either
  14. // 'Lmp' for the mini-port handlers or 'Lcm' for the call manager handlers.
  15. //
  16. //
  17. // About locks:
  18. //
  19. // Data structures that may change during simultaneous requests to different
  20. // processors in a multi-processor system must be protected with spin-locks or
  21. // accessed only with interlocked routines. Where locking is required to
  22. // access a data field in this header, the comment for that field indicates
  23. // same. A CoNDIS client is a trusted kernel mode component and presumed to
  24. // follow the documented call sequences of CoNDIS. Some access conflicts that
  25. // might be caused by goofy clients are not checked, though the easy ones are.
  26. // Cases where multiple clients might conflict are protected even though, for
  27. // now, the TAPI proxy is expected to be the only client.
  28. //
  29. //
  30. // About TDI and NDIS compliance:
  31. //
  32. // This driver is generally compliant with documented TDI and NDIS procedures,
  33. // but there are two compliance issues worth mentioning. First, it takes
  34. // performance advantage from the fact that NDIS_BUFFERs and TDI I/O buffers
  35. // are both defined as MDLs (see NDISBUFFERISMDL in tdix.c). Second, it is
  36. // built by default to take advantage of an IRP handling optimization which
  37. // may be non-TDI-compliant though the docs are not real clear on the point
  38. // (see ALLOCATEIRPS in tdix.c). The driver could be made fully compliant on
  39. // the first point in one hour and on the second by changing a #if
  40. // option...but there would be a performance penalty. Finally,
  41. // InterlockedExchangePointer and InterlockedCompareExchangePointer are used,
  42. // though there don't currently appear to be any NDIS equivalents.
  43. #ifndef _L2TPP_H_
  44. #define _L2TPP_H_
  45. // If set, less commom allocations such as 1-per-call control blocks are made
  46. // from lookaside lists. Otherwise they are made using heap calls. This
  47. // option makes sense where a large number of calls are expected to be
  48. // handled.
  49. //
  50. #define LLISTALL 0
  51. // If set, ReadFlags translates into a simple assigment, otherwise it is an
  52. // Interlocked operation. Set this to 1 if a bus read of ULONG size is
  53. // atomic.
  54. //
  55. #define READFLAGSDIRECT 1
  56. #include <ntddk.h>
  57. #include <tdi.h>
  58. #include <tdikrnl.h>
  59. #include <tdiinfo.h>
  60. #include <ntddtcp.h>
  61. #include <ntddip.h>
  62. #include <ntddndis.h>
  63. #include <ipinfo.h>
  64. #include <tcpinfo.h>
  65. #include <ndis.h>
  66. #include <ndiswan.h>
  67. #include <ndistapi.h>
  68. //#include <ndisadd.h> // Temporary
  69. #include <md5.h>
  70. #include <bpool.h>
  71. #include <ppool.h>
  72. #include <timer.h>
  73. #include <debug.h>
  74. #include <tdix.h>
  75. #include <l2tp.h>
  76. #include <l2tprfc.h>
  77. //-----------------------------------------------------------------------------
  78. // Constants
  79. //-----------------------------------------------------------------------------
  80. // The NDIS version we report when registering mini-port and address family.
  81. //
  82. #define NDIS_MajorVersion 5
  83. #define NDIS_MinorVersion 0
  84. // The maximum number of bytes in a frame including the largest L2TP payload
  85. // header, plus the 32 bytes the OID_WAN_GET_INFO documentation says should be
  86. // reserved internally for "bridging and additional protocols". This value is
  87. // used for receive buffer allocations internally. The L2TP draft/RFC
  88. // guarantees that control messages will fit in L2TP_MaxFrameSize, so a buffer
  89. // of this size is capable of receiving either payload or control packets.
  90. //
  91. #define L2TP_FrameBufferSize (L2TP_MaxFrameSize + L2TP_MaxPayloadHeader + 32)
  92. // The maximum number of bytes in an L2TP control or payload header. This
  93. // value is used for buffer allocations internally.
  94. //
  95. #define L2TP_HeaderBufferSize L2TP_MaxHeaderSize
  96. // Size of an IPv4 header. Because the RawIp driver returns the IP header on
  97. // received datagrams, this must be added onto the allocated buffer size. We
  98. // assume there will be no rarely used IP-option fields on L2TP traffic.
  99. //
  100. // Note: Suggested to PradeepB that RawIp should strip the IP header, and he
  101. // is considering adding an open-address option. This can be removed if
  102. // said option materializes.
  103. //
  104. #define IpFixedHeaderSize 20
  105. // Reported speed of a LAN tunnel in bits/second.
  106. //
  107. #define L2TP_LanBps 10000000
  108. // The vendor name passed to peer during tunnel creation.
  109. //
  110. #define L2TP_VendorName "Microsoft"
  111. // The firmware/software revision passed to peer during tunnel creation. The
  112. // value indicates "NT 5.0".
  113. //
  114. #define L2TP_FirmwareRevision 0x0500
  115. // The maximum length of an IP address string of the form "a.b.c.d".
  116. //
  117. #define L2TP_MaxDottedIpLen 15
  118. // Milliseconds in a Hello timer interval. Not to be confused with the Hello
  119. // timeout which is generally much longer than this. See '*Hello*' fields in
  120. // the TUNNELCB.
  121. //
  122. #define L2TP_HelloIntervalMs 10000
  123. //-----------------------------------------------------------------------------
  124. // Data types
  125. //-----------------------------------------------------------------------------
  126. // Forward declarations.
  127. //
  128. typedef struct _VCCB VCCB;
  129. typedef struct _INCALLSETUP INCALLSETUP;
  130. typedef struct _TUNNELWORK TUNNELWORK;
  131. // Adapter control block defining the state of a single L2TP mini-port
  132. // adapter. An adapter commonly supports multiple VPN devices. Adapter
  133. // blocks are allocated in MiniportInitialize and deallocated in MiniportHalt.
  134. //
  135. typedef struct
  136. _ADAPTERCB
  137. {
  138. // Set to MTAG_ADAPTERCB for easy identification in memory dumps and use
  139. // in assertions.
  140. //
  141. ULONG ulTag;
  142. // Reference count on this control block. The reference pairs are:
  143. //
  144. // (a) A reference is added when the MiniportAdapterHandle field is set,
  145. // i.e. when LmpInitialize succeeds and cleared when the LmpHalt
  146. // handler is called. The adapter block is actually passed to NDIS
  147. // before it's known if LmpInitialize will succeed but according to
  148. // ArvindM NDIS will not call halt unless it succeeds.
  149. //
  150. // (b) A reference is added when the NdisAfHandle field is set and removed
  151. // when it is cleared.
  152. //
  153. // (c) A reference is added when the NdisSapHandle field is set and
  154. // removed when it is cleared.
  155. //
  156. // (d) A reference is added for the VCCB's back pointer and removed when
  157. // the VCCB is freed.
  158. //
  159. // (e) A reference is added for the TUNNELCB's back pointer and removed
  160. // when the TUNNELCB is freed.
  161. //
  162. // (f) A reference is added when an NDIS_WORK_ITEM is scheduled and
  163. // removed when it has completed.
  164. //
  165. // Access is via ReferenceAdapter and DereferenceAdapter only.
  166. //
  167. LONG lRef;
  168. // ACBF_* bit flags indicating various options. Access restrictions are
  169. // indicated for each individual flag. Many of these flags are set
  170. // permanently at initialization and so have no access limitation.
  171. //
  172. // ACBF_OutgoingRoleLac: Set when the driver is to assume the role of the
  173. // L2TP Access Concentrator (LAC) as opposed to the L2TP Network
  174. // Server (LNS) when making outgoing calls. It would be simple to act
  175. // either as LAC or LNS based on a CALL_PARAMETER field, if necessary,
  176. // though this is not currently implemented.
  177. //
  178. // ACBF_IgnoreFramingMismatch: Set when a received framing type bit of
  179. // "asynchronous" is to be ignored, rather than failing the
  180. // negotiation. This is a hedge against buggy peers as there are late
  181. // draft changes to the order of the framing type bits.
  182. //
  183. // ACBF_ExclusiveTunnels: Set when an exclusive tunnel is to be created to
  184. // the peer for each outgoing call even if another tunnel already
  185. // exists to the peer. This is a default and may be overridden in the
  186. // L2TP specific call parameters.
  187. //
  188. // ACBF_SapActive: Set when the TDI open associated with the NdisSapHandle
  189. // is successful and cleared when the corresponding TDI close is
  190. // scheduled. Access is protected by 'lockSap'.
  191. //
  192. // ACBF_UpdatePeerAddress: Set when changes in peer's source IP address
  193. // and/or UDP port are to result in the destination of outbound
  194. // packets changing accordingly.
  195. //
  196. ULONG ulFlags;
  197. #define ACBF_OutgoingRoleLac 0x00000001
  198. #define ACBF_IgnoreFramingMismatch 0x00000002
  199. #define ACBF_ExclusiveTunnels 0x00000004
  200. #define ACBF_SapActive 0x00000010
  201. #define ACBF_UpdatePeerAddress 0x00000100
  202. // The maximum number of out-of-order packets that may be queued on any
  203. // tunnel or link. The value is read from the registry. The value 0
  204. // effectively disables out-of-order handling.
  205. //
  206. SHORT sMaxOutOfOrder;
  207. // The maximum receive window we send to peer during tunnel setup for the
  208. // control session. The value is read from the registry. The value 0
  209. // means the Receive Window Size AVP should not be sent, though for
  210. // control this just results in peer using a default of 4.
  211. //
  212. USHORT usControlReceiveWindow;
  213. // The maximum receive window we send to peer during call setup for the
  214. // payload session. The value is read from the registry. The value 0
  215. // means the Receive Window Size AVP should not be sent, which results in
  216. // no sequence/acknowledge numbers being used for calls we initiate. Note
  217. // that on peer originatated calls where peer specifies a window, 0 will
  218. // result in the default of 4 being offered.
  219. //
  220. USHORT usPayloadReceiveWindow;
  221. // The Hello timeout in milliseconds, i.e. the time that must elapse from
  222. // the last incoming packet before a "Hello" message is sent to verify the
  223. // media is still up. The value is read from the registry. A value of 0
  224. // effectively disables the Hello mechanism.
  225. //
  226. ULONG ulHelloMs;
  227. // The maximum milliseconds to wait for an acknowledge after sending a
  228. // control or payload packet. The value is read from the registry.
  229. //
  230. ULONG ulMaxSendTimeoutMs;
  231. // The initial milliseconds to wait for an acknowledge after sending a
  232. // control or payload packet. The send timeout is adaptive, so this value
  233. // is the seed only. The value is read from the registry.
  234. //
  235. ULONG ulInitialSendTimeoutMs;
  236. // The maximum milliseconds to wait for an outgoing packet on which to
  237. // piggyback an acknowledge before sending a zero data acknowledge. If
  238. // the value is greater than 1/4 of the current send timeout, the former
  239. // is used, i.e. this is the "maximum adaptive maximum".
  240. //
  241. ULONG ulMaxAckDelayMs;
  242. // The maximum number of times a control packet is retransmitted before
  243. // the owning tunnel is reset. The value is read from the registry.
  244. //
  245. ULONG ulMaxRetransmits;
  246. // The randomly unique tie-breaker AVP value sent with all SCCRQ messages.
  247. // This field is currently unused. After due consideration, I have
  248. // decided not to send tie-breaker AVPs in our SCCRQs. The mechanism is
  249. // way too complicated for a rare case. If peer really doesn't want two
  250. // tunnels he will simply ignore ours and let it timeout and fail anyway.
  251. // This is a minor, and I believe harmless, incompliance with the
  252. // draft/RFC. My guess is that others will reach this same conclusion and
  253. // not send tie-breakers either.
  254. //
  255. CHAR achTieBreaker[ 8 ];
  256. // The password shared with peer for tunnel identification. The value is
  257. // read from the registry. Currently, only a single password for all
  258. // peers is used, though a password indexed by 'hostname' will likely be
  259. // added in the future.
  260. //
  261. CHAR* pszPassword;
  262. // The driver description read from the registry. The value is used as
  263. // the L2TP line name when reporting up capabilities.
  264. //
  265. WCHAR* pszDriverDesc;
  266. // Our framing and bearer capablities bit masks as passed in SCCRQ.
  267. //
  268. ULONG ulFramingCaps;
  269. ULONG ulBearerCaps;
  270. // The string sent as the host name, or NULL if none. The value is read
  271. // from the registry.
  272. //
  273. CHAR* pszHostName;
  274. // The next progressively increasing reference number likely to be unique
  275. // for all interconnected LACs/LNSs for a significant period of time. It
  276. // is for use by administrators on either end of the tunnel to use when
  277. // investigating call failure problems. Access is via Interlocked
  278. // routines.
  279. //
  280. ULONG ulCallSerialNumber;
  281. // VC TABLE --------------------------------------------------------------
  282. // The array of VC control block addresses allocated during adapter
  283. // initialization. The VC control blocks themselves are created and hung
  284. // off this table dynamically. Our Call-ID context returned to us by peer
  285. // in each L2TP packet is a 1-based index into this table. (The 0 Call-ID
  286. // is reserved by L2TP to mean "not call specific").
  287. //
  288. // If an element is NULL, it means the Call-ID is not in use. If an
  289. // element is -1, it means the Call-ID has been reserved, but messages
  290. // with the Call-ID are not yet acceptable. Any other value is the
  291. // address of a VCCB for which messages can be accepted. 'VCCB.pTunnel'
  292. // is guaranteed valid while a VCCB is in the array.
  293. //
  294. // Access to the array is protected by 'lockVcs'.
  295. //
  296. VCCB** ppVcs;
  297. // The number of elements in the 'ppVcs' array. This corresponds to the
  298. // number of configured VPN devices read from the registry during
  299. // initialization.
  300. //
  301. USHORT usMaxVcs;
  302. // Number of slots in 'usMaxVcs' that are available, i.e. NULL. Access is
  303. // protected by 'lockVcs'
  304. //
  305. LONG lAvailableVcSlots;
  306. // Lock protecting the VC table, "available" counter, and 'listVcs'.
  307. //
  308. NDIS_SPIN_LOCK lockVcs;
  309. // The next Call-ID above 'usMaxVcs' for use only in terminating a call
  310. // gracefully. Access is by the GetNextTerminationCallId routine only.
  311. //
  312. USHORT usNextTerminationCallId;
  313. // TUNNEL CHAIN ----------------------------------------------------------
  314. // Head of a double-linked list of active TUNNELCBs. At no time will two
  315. // tunnels in the list have the same 'TUNNELCB.usTunnelId' or same
  316. // 'TUNNELCB.ulIpAddress'/'TUNNELCB.usAssignedTunnelId' pair. Access to
  317. // the list links is protected by 'lockTunnels'.
  318. //
  319. LIST_ENTRY listTunnels;
  320. NDIS_SPIN_LOCK lockTunnels;
  321. // The tunnel identifier to assign to the next tunnel created. Only the
  322. // GetNextTunnelId routine should access this field.
  323. //
  324. USHORT usNextTunnelId;
  325. // TDI -------------------------------------------------------------------
  326. // TDI extension context containing TDI state information for the adapter.
  327. // Access is via Tdix* interface routines, which handle all locking
  328. // internally.
  329. //
  330. TDIXCONTEXT tdix;
  331. // NDIS BOOKKEEPING ------------------------------------------------------
  332. // NDIS's handle for this mini-port adapter passed to us in
  333. // MiniportInitialize. This is passed back to various NdisXxx calls.
  334. //
  335. NDIS_HANDLE MiniportAdapterHandle;
  336. // NDIS's handle for our SAP as passed to our CmRegisterSapHandler or NULL
  337. // if none. Only one SAP handle is supported because (a) the TAPI proxy's
  338. // is expected to be the only one, and (b) there are no L2TP SAP
  339. // properties that would ever lead us to direct a call to a second SAP
  340. // anyway. Any client's attempt to register a second SAP will fail. A
  341. // value of NULL indicates no SAP handle is currently registered. Writers
  342. // must hold 'lockSap'. Readers must hold 'lockSap' or a SAP reference.
  343. //
  344. NDIS_HANDLE NdisSapHandle;
  345. // Line and address IDs assigned by NDIS to the active SAP.
  346. //
  347. ULONG ulSapLineId;
  348. ULONG ulSapAddressId;
  349. // NDIS's handle for our Address Family as passed to our CmOpenAfHandler
  350. // or NULL if none. Only one is supported. See NdisSapHandle above.
  351. // Access is via Interlocked routines.
  352. //
  353. NDIS_HANDLE NdisAfHandle;
  354. // This adapter's capabilities as returned to callers on
  355. // OID_WAN_CO_GET_INFO. These capabilities are also used as defaults for
  356. // the corresponding VCCB.linkinfo settings during MiniportCoCreateVc.
  357. //
  358. NDIS_WAN_CO_INFO info;
  359. // Reference count on the NdisAfHandle. The reference pairs are:
  360. //
  361. // (a) A reference is added when the address family is opened and removed
  362. // when it is closed.
  363. //
  364. // (b) A reference is added when a SAP is registered on the address family
  365. // and removed when it is deregistered.
  366. //
  367. // (c) A reference is added when a VC is created on the address family and
  368. // removed when it is deleted.
  369. //
  370. // Access is via ReferenceAf and DereferenceAf only.
  371. //
  372. LONG lAfRef;
  373. // Reference count on the NdisSapHandle. The reference pairs are:
  374. //
  375. // (a) A reference is added when the SAP is registered and removed when it
  376. // is de-registered.
  377. //
  378. // (b) A reference is added and immediately removed in FsmTunnelIdle to
  379. // test for an active SAP in order to immediately reject requested
  380. // tunnels when no SAP is active.
  381. //
  382. // (c) A reference is added when before calling
  383. // NdisMCmDispatchIncomingCall and removed when the call returns.
  384. //
  385. // Access is via ReferenceSap and DereferenceSap only, excepting initial
  386. // reference by RegisterSapPassive. Access is protected by 'lockSap'.
  387. //
  388. LONG lSapRef;
  389. // This lock protects the 'lSapRef' and 'NdisSapHandle' fields.
  390. //
  391. NDIS_SPIN_LOCK lockSap;
  392. // RESOURCE POOLS --------------------------------------------------------
  393. // Count of initialized but not yet completed timers. We cannot allow a
  394. // Halt to complete until this goes to 0, because if we did our driver
  395. // could be unloaded with running timers in our memory which results in a
  396. // bugcheck.
  397. //
  398. ULONG ulTimers;
  399. // Pool of full frame buffers with pre-attached NDIS_BUFFER descriptors.
  400. // The pool is accessed via the interface defined in bpool.h, which
  401. // handles all locking internally.
  402. //
  403. BUFFERPOOL poolFrameBuffers;
  404. // Pool of L2TP header buffers with pre-attached NDIS_BUFFER descriptors.
  405. // The pool is accessed via the interface defined in bpool.h, which
  406. // handles all locking internally.
  407. //
  408. BUFFERPOOL poolHeaderBuffers;
  409. // Pool of NDIS_PACKET descriptors used in indication of received frames.
  410. // The pool is accessed via the interface defined in ppool.h, which
  411. // handles all locking internally.
  412. //
  413. PACKETPOOL poolPackets;
  414. // Lookaside list of NDIS_WORK_ITEM scheduling descriptors with extra
  415. // context space used by all tunnels and VCs attached to the adapter.
  416. //
  417. NPAGED_LOOKASIDE_LIST llistWorkItems;
  418. // Lookaside list of TIMERQITEM timer event descriptors used by all
  419. // tunnels and VCs attached to the adapter.
  420. //
  421. NPAGED_LOOKASIDE_LIST llistTimerQItems;
  422. // Lookaside list of CONTROLSENT sent control packet contexts used by all
  423. // tunnels attached to the adapter.
  424. //
  425. NPAGED_LOOKASIDE_LIST llistControlSents;
  426. // Lookaside list of PAYLOADLSENT sent payload packet contexts used by all
  427. // VCs attached to the adapter.
  428. //
  429. NPAGED_LOOKASIDE_LIST llistPayloadSents;
  430. // Lookaside list of TUNNELWORK incoming VC setup contexts used for all
  431. // tunnels attached to the adapter.
  432. //
  433. NPAGED_LOOKASIDE_LIST llistTunnelWorks;
  434. // Lookaside list of CONTROLMSGINFO contexts used for all tunnels and VCs
  435. // attached to the adapter.
  436. //
  437. NPAGED_LOOKASIDE_LIST llistControlMsgInfos;
  438. #if LLISTALL
  439. // Lookaside list of TUNNELCBs from which the 'listTunnels' control blocks
  440. // are allocated.
  441. //
  442. NPAGED_LOOKASIDE_LIST llistTunnels;
  443. // Lookaside list of VCCBs from which the control blocks dynamically
  444. // attached to '*ppVcs' are allocated.
  445. //
  446. NPAGED_LOOKASIDE_LIST llistVcs;
  447. // Lookaside list of TIMERQ descriptors used by all tunnels attached to
  448. // the adapter.
  449. //
  450. NPAGED_LOOKASIDE_LIST llistTimerQs;
  451. // Lookaside list of CONTROLRECEIVED received control packet contexts used
  452. // by all tunnels attached to the adapter.
  453. //
  454. NPAGED_LOOKASIDE_LIST llistControlReceiveds;
  455. // Lookaside list of PAYLOADRECEIVED received payload packet contexts used
  456. // by all VCs attached to the adapter.
  457. //
  458. NPAGED_LOOKASIDE_LIST llistPayloadReceiveds;
  459. // Lookaside list of CALLSETUP incoming VC setup contexts used for all
  460. // incoming VCs attached to the adapter.
  461. //
  462. NPAGED_LOOKASIDE_LIST llistInCallSetups;
  463. #endif
  464. }
  465. ADAPTERCB;
  466. // Tunnel control block, describing the state of an L2TP tunnel, i.e. an L2TP
  467. // control channel session to another L2TP LNS or LAC. Each tunnel may have
  468. // zero or more VCs associated with it. Tunnel control blocks are allocated
  469. // from 'ADAPTERCB.llistTunnels' in CmMakeCall and ReceiveControl. Blocks are
  470. // deallocated when the last reference is removed, e.g. when the control
  471. // connection FSM terminates the tunnel.
  472. //
  473. typedef struct
  474. _TUNNELCB
  475. {
  476. // Links to the prev/next TUNNELCB in the owning adapter's tunnel list.
  477. // Access to the list links is protected by 'ADAPTERCB.lockTunnels'.
  478. //
  479. LIST_ENTRY linkTunnels;
  480. // Set to MTAG_TUNNELCB for easy identification in memory dumps and use in
  481. // assertions.
  482. //
  483. ULONG ulTag;
  484. // Reference count on this control block. The reference pairs are:
  485. //
  486. // (a) A reference is added when a call on a VCCB is active or becoming
  487. // active and removed when it is deactivated, i.e. during the period
  488. // the VCCB is on 'listVcs'. This covers the back pointer in the
  489. // VCCB.
  490. //
  491. // (b) A reference is added when peer initiates a tunnel and removed when
  492. // the tunnel transitions to idle state. This keeps peer-initiated
  493. // tunnels from terminating when there are no no calls, since by
  494. // convention, it is peer who closes the tunnel in that case.
  495. //
  496. // (c) A reference is added when a graceful tunnel close is initiated and
  497. // removed when the tunnel transitions to idle state.
  498. //
  499. // (d) A reference is added when the delayed control acknowledge timer is
  500. // scheduled and removed by the timer event handler.
  501. //
  502. // (e) LookUpTunnelAndVcCbs adds a reference that is removed at the end of
  503. // the L2tpReceive handler. This covers the receive path.
  504. //
  505. // (f) A reference is added when a CONTROLSENT context is assigned a
  506. // tunnel back pointer and removed when the context is freed.
  507. //
  508. // (g) A reference is added when a PAYLOADSENT context is assigned a
  509. // tunnel back pointer and removed when the context is freed.
  510. //
  511. // (h) ScheduleTunnelWork adds a reference that is removed by TunnelWork
  512. // after executing the work. This covers the tunnel pointer passed as
  513. // a context to NdisScheduleWorkItem.
  514. //
  515. // Access is via ReferenceTunnel and DereferenceTunnel only which use
  516. // 'ADAPTERCB.lockTunnels' for protection.
  517. //
  518. LONG lRef;
  519. // Back pointer to owning adapter's control block.
  520. //
  521. ADAPTERCB* pAdapter;
  522. // This lock protects TUNNELCB send, receive, and state fields as noted in
  523. // other field descriptions.
  524. //
  525. NDIS_SPIN_LOCK lockT;
  526. // TUNNEL SETUP ----------------------------------------------------------
  527. // IP address and UDP port of the remote end of the tunnel in network byte
  528. // order. The IP address is pulled from the call parameters passed to
  529. // CmMakeCall. It is updated with the last source IP address received
  530. // from a peer passing this tunnel's ID, per the L2TP draft/RFC section
  531. // 8.1 on "L2TP over IP/UDP media". However, it is assumed that the
  532. // updated source address will not match the address of another existing
  533. // tunnel. The UDP port (not used in raw IP mode) is initially the well
  534. // known L2TP port (1701). It is updated with the last source UDP port
  535. // received from peer on this tunnel. Access is protected by
  536. // 'pAdapter->lockTunnels'.
  537. //
  538. TDIXIPADDRESS address;
  539. // IP address and ifindex of my end of the tunnel in network byte
  540. // used to get the media speed and build IP header
  541. TDIXIPADDRESS myaddress;
  542. TDIXUDPCONNECTCONTEXT udpContext;
  543. // "Connection" cookie returned by TdixAddHostRoute. This may be passed
  544. // to TdixSendDatagram to send on the connected channel (used for sent
  545. // payloads) as opposed to the unconnected channel (used for receives and
  546. // sent controls). The address is invalid after TdixDeleteHostRoute is
  547. // called.
  548. //
  549. TDIXROUTE* pRoute;
  550. // Our unique tunnel identifier sent back to us by peer in the L2TP
  551. // header. The value is chosen, using GetNextTunnelId, from a sequential
  552. // counter in ADAPTERCB and has no further meaning.
  553. //
  554. USHORT usTunnelId;
  555. // The tunnel identifier chosen by peer that we send back to him in the
  556. // L2TP header Tunnel-ID field for all packets on this tunnel. A value of
  557. // 0 indicates no ID has been assigned.
  558. //
  559. USHORT usAssignedTunnelId;
  560. // TCBF_* bit flags indicating various options and states. Access is via
  561. // the interlocked ReadFlags/SetFlags/ClearFlags routines only.
  562. //
  563. // TCBF_TdixReferenced: Set when the tunnel has referenced the adapter's
  564. // TDI extension context by successfully calling TdixOpen.
  565. // DereferenceTunnel uses this to automatically dereference the
  566. // context when the tunnel is dereferenced.
  567. //
  568. // TCBF_CcInTransition: Set when the control connection FSM has begun but
  569. // not finished a sequence of state changes that will end up in either
  570. // Idle or Established state. When this flag is set new requests to
  571. // bring the tunnel up or down are queued on 'listRequestingVcs' for
  572. // re-execution when a result is known. Access to the bit is
  573. // protected by 'lockT'.
  574. //
  575. // TCBF_PeerInitiated: Set when the tunnel was initiated by the peer,
  576. // rather than a local request. If all calls are dropped and this bit
  577. // is not set, we close the tunnel gracefully.
  578. //
  579. // TCBF_PeerInitRef: Set when a reference for peer initation is taken on
  580. // the tunnel and cleared when the reference is removed.
  581. //
  582. // TCBF_HostRouteAdded: Set when the host route is successfully added and
  583. // referenced and removed when it is dereferenced.
  584. //
  585. // TCBF_HostRouteChanged: Set when a host route changed has been attempted
  586. // on the tunnel, and never cleared.
  587. //
  588. // TCBF_PeerNotResponding: Set when the tunnel is closed due to lack of
  589. // response from peer, i.e. after all retries have been exhausted.
  590. //
  591. // TCBF_Closing: Set as soon as the tunnel is known to be transitioning to
  592. // idle state. Access is protected by 'lockT'.
  593. //
  594. // TCBF_FsmCloseRef: Set when a graceful closing exchange is initiated by
  595. // FsmClose and cleared when the tunnel reaches idle state.
  596. //
  597. // TCBF_InWork: Set when an APC is scheduled to execute work from the
  598. // 'listWork' queue. Access is protected by 'lockWork'.
  599. //
  600. ULONG ulFlags;
  601. #define TCBF_TdixReferenced 0x00000001
  602. #define TCBF_CcInTransition 0x00000002
  603. #define TCBF_PeerInitiated 0x00000004
  604. #define TCBF_PeerInitRef 0x00000008
  605. #define TCBF_HostRouteAdded 0x00000010
  606. #define TCBF_PeerNotResponding 0x00000020
  607. #define TCBF_HostRouteChanged 0x00000040
  608. #define TCBF_Closing 0x00000100
  609. #define TCBF_FsmCloseRef 0x00000200
  610. #define TCBF_InWork 0x00001000
  611. #define TCBF_SendConnected 0x00002000
  612. // The current state of the tunnel's control connection creation FSM. See
  613. // also 'VCCB.state'.
  614. //
  615. // Only one tunnel creation session may be underway even if CmMakeCall has
  616. // been called on multiple VCs over this tunnel. For this reason,
  617. // transitions to/from the Idle or Established states must be protected by
  618. // 'lockT'. See also TCBF_CcInTransition flag and 'listRequestingVcs'.
  619. //
  620. // The protocol sorts out the case of simultaneous originate and receive
  621. // requests ensuring that one gets dropped before it reaches Established
  622. // state when either provides a tie-breaker. We always provide a
  623. // tie-breaker for IP media. For QOS-enabled medias where one control
  624. // channel per call makes sense and no tie-breakers are passed, a lower
  625. // level VC ID will be used to distinguish tunnel control blocks on
  626. // receive. So, a single TUNNELCB will never have both originated and
  627. // received control channels in Established state.
  628. //
  629. L2TPCCSTATE state;
  630. // Double-linked queue of all VCCBs waiting for the tunnel to open. New
  631. // VCs must not be linked on closing tunnels, i.e. those with the
  632. // TCBF_Closing flag set. Access is protected by 'lockT'.
  633. //
  634. LIST_ENTRY listRequestingVcs;
  635. // Double-linked queue of VCCBs whose VCBF_XxxPending operation has
  636. // completed. 'VCCB.status' is the status that will be indicated. This
  637. // mechanism is necessary to avoid the spin-lock issues that results when
  638. // one tries to call NDIS completion APIs from the bowels of the FSMs.
  639. //
  640. LIST_ENTRY listCompletingVcs;
  641. // Peer's framing and bearer capablities.
  642. //
  643. ULONG ulFramingCaps;
  644. ULONG ulBearerCaps;
  645. // The challenge and challenge response sent to peer. These are in the
  646. // control block for convenience, as they must be passed thru the work
  647. // scheduling mechanism and don't fit easily into the generic arguments.
  648. //
  649. CHAR achChallengeToSend[ 16 ];
  650. CHAR achResponseToSend[ 16 ];
  651. // SEND STATE ------------------------------------------------------------
  652. // Next Sent, the sequence number of next control packet transmitted on
  653. // this tunnel. The field is initialized to 0 and incremented after
  654. // assignment to an outgoing packet, excepting retransmissions. Access is
  655. // protected by 'lockT'.
  656. //
  657. USHORT usNs;
  658. // Double-linked list of outstanding sends, i.e. CONTROLSENTs sorted by
  659. // the 'usNs' field with lower values near the head. The list contains
  660. // all active unacknowledged CONTROLSENT contexts, even those that may be
  661. // waiting for their first transmission. Access is protected by 'lockT'.
  662. //
  663. LIST_ENTRY listSendsOut;
  664. // The number of control packets sent but not acknowledged or timed out.
  665. // Access is protected by 'lockT'.
  666. //
  667. ULONG ulSendsOut;
  668. // The number of sent but unacknowledged packets that may be outstanding.
  669. // This value is adjusted dynamically. Per the draft/RFC, when
  670. // 'ulAcksSinceSendTimeout' reaches the current setting, the window is
  671. // increased by one. When a send timeout expires the window is reduced by
  672. // half. Access is protected by 'lockT'.
  673. //
  674. ULONG ulSendWindow;
  675. // The maximum value of 'ulSendWindow'. Peer chooses this value during
  676. // call setup by offering a receive window.
  677. //
  678. ULONG ulMaxSendWindow;
  679. // The number of packets acknowledged since the last timeout. The value
  680. // is reset when a timeout occurs or the send window is adjusted upward.
  681. // See 'ulSendWindow'. Access is protected by 'lockT'.
  682. //
  683. ULONG ulAcksSinceSendTimeout;
  684. // The estimated round trip time in milliseconds. This is the RTT value
  685. // from Appendix A of the draft/RFC. The value is adjusted as each
  686. // acknowledge is received. It is initialized to the Packet Processing
  687. // Delay reported by peer. See 'ulSendTimeoutMs'. Access is protected by
  688. // 'lockT'.
  689. //
  690. ULONG ulRoundTripMs;
  691. // The estimated mean deviation in milliseconds, an approximation of the
  692. // standard deviation. This is the DEV value from Appendix A of the
  693. // draft/RFC. The value is adjusted as each acknowledge is received. It
  694. // is initially 0. See 'ulSendTimeoutMs'. Access is protected by
  695. // 'lockT'.
  696. //
  697. LONG lDeviationMs;
  698. // Milliseconds before it is assumed a sent packet will not be
  699. // acknowledged and needs to be retransmitted. This is the ATO value from
  700. // Appendix A of the draft/RFC. This value is adjusted as each
  701. // acknowledge is received, with a maximum of
  702. // 'ADAPTERCB.ulMaxSendTimeoutMs'. Access is protected by 'lockT'.
  703. //
  704. ULONG ulSendTimeoutMs;
  705. // The timer event descriptor scheduled to occur when it is time to stop
  706. // waiting for an outgoing send on which to piggyback an acknowledge.
  707. // This will be NULL when no delayed acknowledge is pending. Per the
  708. // draft/RFC, the timeout used is 1/4 of the 'ulSendTimeoutMs'. Access is
  709. // protected by 'lockT'.
  710. //
  711. TIMERQITEM* pTqiDelayedAck;
  712. // The timer event descriptor which expires when it's time to check for
  713. // lack of any incoming packets. To reduce the cost of constantly
  714. // resetting a Hello timer with a full timeout (which with unsequenced
  715. // payloads usually results in an NdisCancelTimer/NdisSetTimer on each
  716. // received packet), the timeout is broken into intervals of
  717. // L2TP_HelloIntervalMs. If it expires and both 'ulRemainingHelloMs' and
  718. // 'ulHelloResetsThisInterval' are 0, a "Hello" message is sent to the
  719. // peer to verify that the media is still up. Access to this field is
  720. // protected by 'lockT'.
  721. //
  722. TIMERQITEM* pTqiHello;
  723. // The milliseconds left to wait in all remaining Hello intervals and the
  724. // number of resets since the last Hello interval timeout.
  725. //
  726. ULONG ulRemainingHelloMs;
  727. ULONG ulHelloResetsThisInterval;
  728. // RECEIVE STATE ---------------------------------------------------------
  729. // Next Received, the sequence number one higher than that of the last
  730. // control packet received on this tunnel or 0 if none. Access is
  731. // protected by 'lockT'.
  732. //
  733. USHORT usNr;
  734. // Double-linked list of out-of-order receives, i.e. CONTROLRECEIVEs
  735. // sorted by the 'usNs' field with lower values near the head. The
  736. // maximum queue length is 'ADAPTERCB.sMaxOutOfOrder'. Access is
  737. // protected by 'lockT'.
  738. //
  739. LIST_ENTRY listOutOfOrder;
  740. // TIMER QUEUE -----------------------------------------------------------
  741. // Timer queue for both the control and data channels. The timer queue is
  742. // accessed via the interface defined in timer.h, which handles all
  743. // locking internally.
  744. //
  745. TIMERQ* pTimerQ;
  746. // WORK QUEUE ------------------------------------------------------------
  747. // Double-linked list NDIS_WORK_ITEMs queued for serialized execution at
  748. // PASSIVE IRQL. The next item to be executed is at the head of the list.
  749. // Access is protected via the ScheduleTunnelWork routine, which protects
  750. // the list with 'lockWork'. See also TCBF_InWork.
  751. //
  752. LIST_ENTRY listWork;
  753. NDIS_SPIN_LOCK lockWork;
  754. // VC CHAIN --------------------------------------------------------------
  755. // Head of a double-linked list of VCCBs associated with the tunnel, i.e.
  756. // with calls active or in the process of becoming active. New VCs must
  757. // not be linked on closing tunnels, i.e. those with the TCBF_Closing flag
  758. // set. Access to the links is protected by 'lockVcs'.
  759. //
  760. LIST_ENTRY listVcs;
  761. NDIS_SPIN_LOCK lockVcs;
  762. // media speed
  763. ULONG ulMediaSpeed;
  764. }
  765. TUNNELCB;
  766. // Call statistics block.
  767. //
  768. typedef struct
  769. _CALLSTATS
  770. {
  771. // System time call reached established state. When the block is being
  772. // used for cumulative statistics of multiple calls, this is the number of
  773. // calls instead.
  774. //
  775. LONGLONG llCallUp;
  776. // Duration in seconds of now idle call.
  777. //
  778. ULONG ulSeconds;
  779. // Total data bytes received and sent.
  780. //
  781. ULONG ulDataBytesRecd;
  782. ULONG ulDataBytesSent;
  783. // Number of received packets indicated up.
  784. //
  785. ULONG ulRecdDataPackets;
  786. // Number of received packets linked on the out-of-order queue before
  787. // being indicated up.
  788. //
  789. ULONG ulDataPacketsDequeued;
  790. // Number of received packets of zero length. Includes packets with the
  791. // R-bit set.
  792. //
  793. ULONG ulRecdZlbs;
  794. // Number of received packets with R-bit set.
  795. //
  796. ULONG ulRecdResets;
  797. // Number of received packets with R-bit set that are out of date.
  798. //
  799. ULONG ulRecdResetsIgnored;
  800. // Number of data packets sent with and without sequence numbers. The sum
  801. // of the two is the total data packets sent.
  802. //
  803. ULONG ulSentDataPacketsSeq;
  804. ULONG ulSentDataPacketsUnSeq;
  805. // Number of packets sent that were acknowledged and timed out. If the
  806. // call is cancelled with packets outstanding the sum of the two may be
  807. // less than 'ulSentDataPacketsSeq'.
  808. //
  809. ULONG ulSentPacketsAcked;
  810. ULONG ulSentPacketsTimedOut;
  811. // Number of zero length acknowledges sent.
  812. //
  813. ULONG ulSentZAcks;
  814. // Number of packets sent with the R-bit set.
  815. //
  816. ULONG ulSentResets;
  817. // Number of times the send window was changed.
  818. //
  819. ULONG ulSendWindowChanges;
  820. // Total of all send window sizes, one for each 'ulSentDataPacketsSeq'.
  821. //
  822. ULONG ulSendWindowTotal;
  823. // Largest send window.
  824. //
  825. ULONG ulMaxSendWindow;
  826. // Smallest send window.
  827. //
  828. ULONG ulMinSendWindow;
  829. // Number of sample round trips. (sequenced packets only)
  830. //
  831. ULONG ulRoundTrips;
  832. // Total of all round trips in milliseconds. (sequenced packets only)
  833. //
  834. ULONG ulRoundTripMsTotal;
  835. // Longest round trip, (sequenced packets only)
  836. //
  837. ULONG ulMaxRoundTripMs;
  838. // Shortest round trip. (sequenced packets only)
  839. //
  840. ULONG ulMinRoundTripMs;
  841. }
  842. CALLSTATS;
  843. // Virtual circuit control block defining the state of a single L2TP VC, i.e.
  844. // one line device endpoint and the call, if any, active on it. A VC is never
  845. // used for incoming and outgoing calls simultaneously. A single NDIS VC maps
  846. // to one of these.
  847. //
  848. typedef struct
  849. _VCCB
  850. {
  851. // Links to the prev/next VCCB in the owning tunnel's active VC list.
  852. // Access is protected by 'TUNNELCB.lockVcs'.
  853. //
  854. LIST_ENTRY linkVcs;
  855. // Set to MTAG_VCCB for easy identification in memory dumps and use in
  856. // assertions.
  857. //
  858. ULONG ulTag;
  859. // Reference count on this VC control block. The reference pairs are:
  860. //
  861. // (a) LmpCoCreateVc adds a reference that is removed by LmpCoDeleteVc.
  862. // This covers all clients that learn of the VCCB via NDIS.
  863. //
  864. // (b) LookUpTunnelAndVcCbs adds a reference that is removed at the end of
  865. // the L2tpReceive handler. This covers the receive path.
  866. //
  867. // (c) A reference is added when a CONTROLSENT context with 'pVc'
  868. // referring to this VCCB is assigned the back pointer and removed
  869. // when the context is freed.
  870. //
  871. // (d) A reference is added when a PAYLOADSENT context with 'pVc'
  872. // referring to this VCCB is assigned the back pointer and removed
  873. // when the context is freed.
  874. //
  875. // (e) ScheduleTunnelWork adds a reference that is removed by TunnelWork
  876. // after executing the work.
  877. //
  878. // (f) A reference is added before scheduling the delayed payload
  879. // acknowledge timer and removed in the timer event handler.
  880. //
  881. // (g) A reference is taken by CompleteVcs covering use of the VC popped
  882. // from the tunnel's completing list, and released after use.
  883. //
  884. // (h) A reference is taken prior to calling NdisMCmDispatchIncomingCall
  885. // and removed by the completion handler.
  886. //
  887. // (i) A reference is added when a CONTROLRECEIVED context with 'pVc'
  888. // referring to this VCCB is assigned the back pointer and removed
  889. // when the context is freed.
  890. //
  891. // The field is accessed only by the ReferenceVc and DereferenceVc
  892. // routines, which protect with Interlocked routines.
  893. //
  894. LONG lRef;
  895. // Back pointer to owning adapter's control block.
  896. //
  897. ADAPTERCB* pAdapter;
  898. // Back pointer to owning tunnel's control block or NULL if none.
  899. // Guaranteed valid whenever the VC is linked into a tunnel's 'listVcs',
  900. // i.e. when it holds a reference on the tunnel. It is safe to use this
  901. // if you hold a reference on the call. Otherwise, it is not. Be very
  902. // careful here.
  903. //
  904. TUNNELCB* pTunnel;
  905. // This lock protects VCCB payload send and receive paths as noted in
  906. // other field descriptions. In cases where both 'lockV' and
  907. // 'pTunnel->lockT' are required 'lockT' must be obtained first.
  908. //
  909. NDIS_SPIN_LOCK lockV;
  910. // CALL SETUP ------------------------------------------------------------
  911. // Our unique call identifier sent back to us by peer in the L2TP header.
  912. // The value is a 1-based index into the 'ADAPTERCB.ppVcs' array.
  913. //
  914. USHORT usCallId;
  915. // The call identifier, chosen by peer, that we send back to him in the
  916. // L2TP header Call-ID field for all packets on this call. A value of 0
  917. // indicates no Call-ID has been assigned.
  918. //
  919. USHORT usAssignedCallId;
  920. // VCBF_* bit flags indicating various options and states. Access is via
  921. // the interlocked ReadFlags/SetFlags/ClearFlags routines.
  922. //
  923. // VCBF_IndicateReceivedTime: Set if MakeCall caller sets the
  924. // MediaParameters.Flags RECEIVE_TIME_INDICATION flag requesting the
  925. // TimeReceived field of the NDIS packet be filled with a timestamp.
  926. //
  927. // VCBF_CallClosableByClient: Set when a call is in a state where
  928. // LcmCmCloseCall requests to initiate clean-up should be accepted.
  929. // This may be set when VCBF_CallClosableByPeer is not, which means we
  930. // have indicated an incoming close to client and are waiting for him
  931. // to do a client close in response (in that weird CoNDIS way). The
  932. // flag is protected by 'lockV'.
  933. //
  934. // VCBF_CallClosableByPeer: Set when the call is in a state where an idle
  935. // transition without operations pending should be mapped to a
  936. // PeerClose event. This will never be set when
  937. // VCBF_CallClosableByClient is not. The flag is protected by
  938. // 'lockV'.
  939. //
  940. // VCBF_DefaultLcParams: Set when the 'pLcParams' field was allocated by
  941. // us rather than being owned by client.
  942. //
  943. // VCBF_IncomingFsm: Set when the VC is executing the Incoming Call FSM
  944. // rather than Outgoing Call FSM in the active incoming/outgoing call.
  945. // For client initiated calls this will set if the adapter's
  946. // ACBF_OutgoingRoleLac flag, read from the registry, is set.
  947. //
  948. // VCBF_PeerInitiatedCall: Set when an the active call was initiated by
  949. // the peer, clear if it was initiated by the client.
  950. //
  951. // VCBF_Sequencing: Set unless no Receive Window AVP is provided/received
  952. // during call setup, resulting in "no sequencing" mode where Ns/Nr
  953. // fields are not sent in the payload header. This also effectively
  954. // disables out-of-order processing.
  955. //
  956. // VCBF_VcCreated: Set when the VC has been created successfully. This is
  957. // the "creation" that occurs with the client, not the mini-port.
  958. // VCBF_VcActivated: Set when the VC has been activated successfully.
  959. // VCBF_VcDispatched: Set when the VC has dispatched an incoming call to
  960. // the client and client has returned success or pended.
  961. // VCBM_VcState: Bit mask including each of the above 3 NDIS state flags.
  962. //
  963. // VCBF_VcDeleted: Set when the DeleteVC handler has been called on this
  964. // VC. This guards against NDPROXY double-deleting VCs which it has
  965. // been known to do.
  966. //
  967. // The pending bits below are mutually exclusive (except ClientClose which
  968. // may occur after but simultaneous with ClientOpen), and so require lock
  969. // protection by 'lockV':
  970. //
  971. // VCBF_PeerOpenPending: Set when peer attempts to establish a call, and
  972. // the result is not yet known.
  973. // VCBF_ClientOpenPending: Set when client attempts to establish a call,
  974. // and the result is not yet known.
  975. // VCBF_PeerClosePending: Set when peer attempts to close an established
  976. // call and the result is not yet known. Access is protected by
  977. // 'lockV'.
  978. // VCBF_ClientClosePending: Set when client attempts to close an
  979. // established call and the result is not yet known. Access is
  980. // protected by 'lockV'.
  981. // VCBM_Pending: Bit mask that includes each of the 4 pending flags.
  982. //
  983. // VCBF_ClientCloseCompletion: Set when client close completion is in
  984. // progress.
  985. //
  986. // VCBF_IcsAlloc: Set when the 'pInCall' block has been locked for
  987. // allocation and cleared when the call is torn down. Accessed only
  988. // by the LockIcs/UnlockIcs routines.
  989. // VCBF_IcsGrace: Set when the 'pInCall' pointer has been locked for a
  990. // grace period during which the response to the incoming call message
  991. // is sent. Accessed only by the LockIcs/UnlockIcs routines.
  992. //
  993. // VCBF_WaitInCallComplete: Set when the client is expected to call our
  994. // call manager's IncomingCallComplete handler. This guards against
  995. // NDPROXY double completing calls which it has been known to do.
  996. // VCBF_WaitCloseCall: Set when the client is expected to call our call
  997. // manager's CloseCall handler. This is strictly a debug aid.
  998. //
  999. ULONG ulFlags;
  1000. #define VCBF_IndicateTimeReceived 0x00000001
  1001. #define VCBF_CallClosableByClient 0x00000002
  1002. #define VCBF_CallClosableByPeer 0x00000004
  1003. #define VCBF_DefaultLcParams 0x00000008
  1004. #define VCBF_IncomingFsm 0x00000010
  1005. #define VCBF_PeerInitiatedCall 0x00000020
  1006. #define VCBF_Sequencing 0x00000040
  1007. #define VCBF_VcCreated 0x00000100
  1008. #define VCBF_VcActivated 0x00000200
  1009. #define VCBF_VcDispatched 0x00000400
  1010. #define VCBM_VcState 0x00000700
  1011. #define VCBF_PeerOpenPending 0x00001000
  1012. #define VCBF_ClientOpenPending 0x00002000
  1013. #define VCBF_PeerClosePending 0x00004000
  1014. #define VCBF_ClientClosePending 0x00008000
  1015. #define VCBM_Pending 0x0000F000
  1016. #define VCBF_VcDeleted 0x00010000
  1017. #define VCBF_ClientCloseCompletion 0x00020000
  1018. #define VCBF_IcsAlloc 0x00040000
  1019. #define VCBF_IcsGrace 0x00080000
  1020. #define VCBF_WaitInCallComplete 0x00100000
  1021. #define VCBF_WaitCloseCall 0x00200000
  1022. // Reference count on the active call. Fields in this CALL SETUP section
  1023. // and in the CALL STATISTICS section should not be accessed without a
  1024. // call reference while the VC is activated. References may only be added
  1025. // when the VCCB_VcActivated flag is set, and this is enforced by
  1026. // ReferenceCall. The reference pairs are:
  1027. //
  1028. // (a) A reference is added when a VC is activated and removed when it is
  1029. // de-activated.
  1030. //
  1031. // (b) A reference is added when the send handler accepts a packet. For
  1032. // unsequenced sends the reference is removed by the send complete
  1033. // routine. For sequenced sends it it removed when the PAYLOADSENT
  1034. // context is destroyed.
  1035. //
  1036. // (c) A reference is added before scheduling a ZLB send and removed by
  1037. // the send completion routine.
  1038. //
  1039. // (d) A reference is added before entering ReceivePayload and removed on
  1040. // exit from same.
  1041. //
  1042. // (e) A reference is added before dispatching the call that is removed
  1043. // when the dispatch is completed.
  1044. //
  1045. // The field is accessed only by the ReferenceCall and DereferenceCall
  1046. // routines, which protect the field with 'lockCall'.
  1047. //
  1048. LONG lCallRef;
  1049. NDIS_SPIN_LOCK lockCall;
  1050. // The current state of the VCs call creation, i.e. the control channel's
  1051. // data channel setup for this VC. Access is protected by 'lockV' once
  1052. // the VC is set up to receive call control messages.
  1053. //
  1054. L2TPCALLSTATE state;
  1055. // Links to the prev/next VCCB in the owning tunnel's requesting VC list
  1056. // VC list. Access is protected by 'TUNNELCB.lockT'.
  1057. //
  1058. LIST_ENTRY linkRequestingVcs;
  1059. // Links to the prev/next VCCB in the owning tunnel's completing VC list.
  1060. // Access is protected by 'TUNNELCB.lockT'.
  1061. //
  1062. LIST_ENTRY linkCompletingVcs;
  1063. // This is set to the pending peer open/close or client open operation
  1064. // result to be reported to client.
  1065. //
  1066. NDIS_STATUS status;
  1067. // The received call setup message context. When peer initiates a call,
  1068. // we must create a VC and dispatch the incoming call to the client above.
  1069. // This is an asynchronous operation that must occur right in the middle
  1070. // of receive processing. This context stores information about the
  1071. // received message so it can be processed when it is known if client will
  1072. // accept the call. It also includes the CO_CALL_PARAMETERS buffer
  1073. // dispatched to client on incoming calls. The field is valid only until
  1074. // LcmCmIncomingCallComplete handler is called, at which time it is set to
  1075. // NULL.
  1076. //
  1077. // Shortcut addresses of the TAPI call info passed up in the
  1078. // NdisMCmDispatchIncomingCall. Obviously, they are valid only when
  1079. // 'pInCall' is valid. When invalid they are set to NULL.
  1080. //
  1081. INCALLSETUP* pInCall;
  1082. CO_AF_TAPI_INCOMING_CALL_PARAMETERS UNALIGNED * pTiParams;
  1083. LINE_CALL_INFO* pTcInfo;
  1084. // Reference count on the 'pInCall' context. The reference pairs are:
  1085. //
  1086. // (a) A reference is added when the context is allocated and removed
  1087. // by CallSetupComplete.
  1088. //
  1089. // (b) A reference is added before passing addresses within the context to
  1090. // ReceiveControlExpected and removed after that routine returns.
  1091. //
  1092. // The field is accessed only by the ReferenceIcs and DereferenceIcs
  1093. // routines, which protect with Interlocked routines. An exception is
  1094. // initializion to 1 by SetupVcAsynchronously.
  1095. //
  1096. LONG lInCallRef;
  1097. // Address of the call parameters passed down in CmMakeCall. This field
  1098. // will only be valid until the NdisMCmMakeCallComplete notification for
  1099. // the associated call is made, at which time it is reset to NULL. Access
  1100. // is via Interlocked routines.
  1101. //
  1102. // Shortcut addresses of the TAPI call parameters (both levels) and the
  1103. // L2TP-specific call parameters in the 'pMakeCall' buffer. Obviously,
  1104. // they are valid only when 'pMakeCall' is valid. When invalid they are
  1105. // set to NULL.
  1106. //
  1107. CO_CALL_PARAMETERS* pMakeCall;
  1108. CO_AF_TAPI_MAKE_CALL_PARAMETERS UNALIGNED* pTmParams;
  1109. LINE_CALL_PARAMS* pTcParams;
  1110. // Shortcut address of the L2TP-specific call parameters in the
  1111. // 'pMakeCall' or 'pInCall' buffer. Obviously, this is only valid when
  1112. // 'pMakeCall' or 'pInCall' is non-NULL. When invalid this is NULL. On
  1113. // MakeCall, caller may not provide 'pLcParams' in which case one is
  1114. // allocated and initialized to defaults for the convenience of the rest
  1115. // of the code. This temporary buffer is not reported to caller on
  1116. // MakeCallComplete.
  1117. //
  1118. L2TP_CALL_PARAMETERS* pLcParams;
  1119. // The result and error to report in the coming incoming/outgoing call
  1120. // reply message.
  1121. //
  1122. USHORT usResult;
  1123. USHORT usError;
  1124. // The connect speed in bits/second. This is the transmit speed value
  1125. // reported by the peer LAC, or the value we reported to the peer LNS and
  1126. // to NDISWAN. Since we have no real knowledge of connect speed, we
  1127. // report the minimum of the maximum rate acceptable to peer and
  1128. // L2TP_LanBps.
  1129. //
  1130. ULONG ulConnectBps;
  1131. // SEND STATE ------------------------------------------------------------
  1132. // Next Sent, the sequence number of next payload packet transmitted on
  1133. // this call. The field is initialized to 0 and incremented after
  1134. // assignment to an outgoing packet, excepting retransmissions. Access is
  1135. // protected by 'lockV'.
  1136. //
  1137. USHORT usNs;
  1138. // Double-linked list of outstanding sends, i.e. PAYLOADSENTs sorted by
  1139. // the 'usNs' field with lower values near the head. Access is protected
  1140. // by 'lockV'.
  1141. //
  1142. LIST_ENTRY listSendsOut;
  1143. // The number of sent but unacknowledged packets that may be outstanding.
  1144. // This value is adjusted dynamically. Per the draft/RFC, when
  1145. // 'ulAcksSinceSendTimeout' reaches the current setting, the window is
  1146. // increased by one. When a send timeout expires the window is reduced by
  1147. // half. The actual send window throttling is done by NDISWAN, based on
  1148. // our indications of the changing window size. Access is protected by
  1149. // 'lockV'.
  1150. //
  1151. ULONG ulSendWindow;
  1152. // The maximum value of 'ulSendWindow'. Peer chooses this value during
  1153. // call setup.
  1154. //
  1155. ULONG ulMaxSendWindow;
  1156. // The number of packets acknowledged since the last timeout. The value
  1157. // is reset when a timeout occurs or the send window is adjusted upward.
  1158. // See 'ulSendWindow'. Access is protected by 'lockV'.
  1159. //
  1160. ULONG ulAcksSinceSendTimeout;
  1161. // The estimated round trip time in milliseconds. This is the RTT value
  1162. // from Appendix A of the draft/RFC. The value is adjusted as each
  1163. // acknowledge is received. It is initialized to the Packet Processing
  1164. // Delay reported by peer. See 'ulSendTimeoutMs'. Access is protected by
  1165. // 'lockV'.
  1166. //
  1167. ULONG ulRoundTripMs;
  1168. // The estimated mean deviation in milliseconds, an approximation of the
  1169. // standard deviation. This is the DEV value from Appendix A of the
  1170. // draft/RFC. The value is adjusted as each acknowledge is received. It
  1171. // is initially 0. See 'ulSendTimeoutMs'. Access is protected by
  1172. // 'lockV'.
  1173. //
  1174. LONG lDeviationMs;
  1175. // Milliseconds before it is assumed a sent packet will never be
  1176. // acknowledged. This is the ATO value from Appendix A of the draft/RFC.
  1177. // This value is adjusted as each acknowledge is received, with a maximum
  1178. // of 'ADAPTERCB.ulMaxSendTimeoutMs'. Access is protected by 'lockV'.
  1179. //
  1180. ULONG ulSendTimeoutMs;
  1181. // The timer event descriptor scheduled to occur when it is time to stop
  1182. // waiting for an outgoing send on which to piggyback an acknowledge.
  1183. // This will be NULL when no delayed acknowledge is pending. Per the
  1184. // draft/RFC, the timeout used is 1/4 of the 'ulSendTimeoutMs'. Access is
  1185. // protected by 'lockV'.
  1186. //
  1187. TIMERQITEM* pTqiDelayedAck;
  1188. // RECEIVE STATE ---------------------------------------------------------
  1189. // Next Received, the sequence number one higher than that of the last
  1190. // payload packet received on this call or 0 if none. Access is protected
  1191. // by 'lockV'.
  1192. //
  1193. USHORT usNr;
  1194. // Double-linked list of out-of-order receives, i.e. PAYLOADRECEIVEs
  1195. // sorted by the 'usNs' field with lower values near the head. The
  1196. // maximum queue length is 'ADAPTERCB.sMaxOutOfOrder'. Access is
  1197. // protected by 'lockV'.
  1198. //
  1199. LIST_ENTRY listOutOfOrder;
  1200. // NDIS BOOKKEEPING ------------------------------------------------------
  1201. // NDIS's handle for this VC passed to us in MiniportCoCreateVcHandler.
  1202. // This is passed back to NDIS in various NdisXxx calls.
  1203. //
  1204. NDIS_HANDLE NdisVcHandle;
  1205. // Configuration settings returned to callers on OID_WAN_CO_GET_INFO and
  1206. // modified by callers on OID_WAN_CO_SET_INFO. Older NDISWAN references to
  1207. // "LINK" map straight to "VC" in the NDIS 5.0 world. Access is not
  1208. // protected because each ULONG in the structure is independent so no
  1209. // incoherency can result from multiple access.
  1210. //
  1211. NDIS_WAN_CO_GET_LINK_INFO linkinfo;
  1212. // STATISTICS ------------------------------------------------------------
  1213. // Statistics for the current call. Access is protected by 'lockV'.
  1214. //
  1215. CALLSTATS stats;
  1216. }
  1217. VCCB;
  1218. // The "exploded" description of an L2TP header, as output by
  1219. // ExplodeL2tpHeader.
  1220. //
  1221. typedef struct
  1222. _L2TPHEADERINFO
  1223. {
  1224. // Addresses of header fields. Some may be NULL indicating the field was
  1225. // not present in the header.
  1226. //
  1227. USHORT* pusBits;
  1228. USHORT* pusLength;
  1229. USHORT* pusTunnelId;
  1230. USHORT* pusCallId;
  1231. USHORT* pusNs;
  1232. USHORT* pusNr;
  1233. // Length of the variable length header in bytes.
  1234. //
  1235. ULONG ulHeaderLength;
  1236. // Address and length in bytes of the data following the variable length
  1237. // header.
  1238. //
  1239. CHAR* pData;
  1240. ULONG ulDataLength;
  1241. }
  1242. L2TPHEADERINFO;
  1243. // The "exploded" description of an Attribute/Value Pair (AVP), as output by
  1244. // ExplodeAvpHeader. The "value" is located and sized but not interpreted or
  1245. // byte-ordered until a GetAvpValueXxx routine is applied.
  1246. //
  1247. typedef struct
  1248. _AVPINFO
  1249. {
  1250. // Addresses of header fields. All are always present.
  1251. //
  1252. UNALIGNED USHORT* pusBits;
  1253. UNALIGNED USHORT* pusVendorId;
  1254. UNALIGNED USHORT* pusAttribute;
  1255. // The length of the entire AVP, extracted from '*pusBits'.
  1256. //
  1257. USHORT usOverallLength;
  1258. // Length of the value in bytes and the address of the value.
  1259. //
  1260. USHORT usValueLength;
  1261. CHAR* pValue;
  1262. }
  1263. AVPINFO;
  1264. // The "exploded" description of a control message, as output by
  1265. // ExplodeControlAvps.
  1266. //
  1267. typedef struct
  1268. _CONTROLMSGINFO
  1269. {
  1270. // GERR_* code indicating the result of the ExplodeControlAvps operation.
  1271. // Other fields should not be referenced unless this is GERR_None.
  1272. //
  1273. USHORT usXError;
  1274. // True when the message is a tunnel setup message, false if it is a call
  1275. // setup message.
  1276. //
  1277. BOOLEAN fTunnelMsg;
  1278. // Address of message type AVP value. The message type AVP is present in
  1279. // all valid control messages.
  1280. //
  1281. UNALIGNED USHORT* pusMsgType;
  1282. // Addresses of additional AVP values. These may be NULL indicating the
  1283. // AVP was not found in the message. The length field following variable
  1284. // length fields is valid whenever the value address is non-NULL.
  1285. //
  1286. USHORT* pusResult;
  1287. USHORT* pusError;
  1288. CHAR* pchResultMsg;
  1289. USHORT usResultMsgLength;
  1290. UNALIGNED USHORT* pusProtocolVersion;
  1291. UNALIGNED ULONG* pulFramingCaps;
  1292. UNALIGNED ULONG* pulBearerCaps;
  1293. CHAR* pchTieBreaker;
  1294. CHAR* pchHostName;
  1295. USHORT usHostNameLength;
  1296. UNALIGNED USHORT* pusAssignedTunnelId;
  1297. UNALIGNED USHORT* pusRWindowSize;
  1298. UNALIGNED USHORT* pusAssignedCallId;
  1299. UNALIGNED ULONG* pulCallSerialNumber;
  1300. UNALIGNED ULONG* pulMinimumBps;
  1301. UNALIGNED ULONG* pulMaximumBps;
  1302. UNALIGNED ULONG* pulBearerType;
  1303. UNALIGNED ULONG* pulFramingType;
  1304. UNALIGNED USHORT* pusPacketProcDelay;
  1305. CHAR* pchDialedNumber;
  1306. USHORT usDialedNumberLength;
  1307. CHAR* pchDialingNumber;
  1308. USHORT usDialingNumberLength;
  1309. UNALIGNED ULONG* pulTxConnectSpeed;
  1310. UNALIGNED ULONG* pulPhysicalChannelId;
  1311. CHAR* pchSubAddress;
  1312. USHORT usSubAddressLength;
  1313. CHAR* pchChallenge;
  1314. USHORT usChallengeLength;
  1315. CHAR* pchResponse;
  1316. UNALIGNED USHORT* pusProxyAuthType;
  1317. CHAR* pchProxyAuthResponse;
  1318. USHORT usProxyAuthResponseLength;
  1319. UNALIGNED ULONG* pulCallErrors;
  1320. UNALIGNED ULONG* pulAccm;
  1321. BOOLEAN fSequencingRequired;
  1322. }
  1323. CONTROLMSGINFO;
  1324. // Context for a control packet received out of order which is queued rather
  1325. // than discarding in the hope that the missing packet will arrive.
  1326. //
  1327. typedef struct
  1328. _CONTROLRECEIVED
  1329. {
  1330. // Link to the prev/next link in the 'TUNNELCB.listOutOfOrder' list.
  1331. //
  1332. LIST_ENTRY linkOutOfOrder;
  1333. // 'Next Sent' sequence number received in the packet.
  1334. //
  1335. USHORT usNs;
  1336. // Associated VC or NULL if none.
  1337. //
  1338. VCCB* pVc;
  1339. // The received GetBufferFromPool buffer.
  1340. //
  1341. CHAR* pBuffer;
  1342. // The "exploded" description of the control message.
  1343. //
  1344. CONTROLMSGINFO control;
  1345. }
  1346. CONTROLRECEIVED;
  1347. // Context for a control packet sent but not yet acknowledged. This block is
  1348. // queued on the 'TUNNELCB.listSendsOut' and 'TUNNELCB.listSendsPending'
  1349. // lists, and is associated with SendControlTimerEvents.
  1350. //
  1351. typedef struct
  1352. _CONTROLSENT
  1353. {
  1354. // Link to the prev/next link in the 'TUNNELCB.listSendsOut' list.
  1355. //
  1356. LIST_ENTRY linkSendsOut;
  1357. // Reference count on this context. The reference pairs are:
  1358. //
  1359. // (a) A reference is added when the context is queued into the
  1360. // 'listSendsOut' list, and removed by the de-queuer.
  1361. //
  1362. // (b) A reference is added before sending (and also before
  1363. // 'pTqiSendTimeout' is scheduled) and is removed by the send
  1364. // completion routine.
  1365. //
  1366. // (c) A reference is added before 'pTqiSendTimeout' is scheduled and
  1367. // removed as the timer event handler exits.
  1368. //
  1369. LONG lRef;
  1370. // 'Next Sent' sequence number sent with the packet.
  1371. //
  1372. USHORT usNs;
  1373. // The message type of the packet. (debug use only)
  1374. //
  1375. USHORT usMsgType;
  1376. // Timer event descriptor scheduled for the packet.
  1377. //
  1378. TIMERQITEM* pTqiSendTimeout;
  1379. // Number of times the packet has been retransmitted.
  1380. //
  1381. ULONG ulRetransmits;
  1382. // CSF_* flags indicating various options.
  1383. //
  1384. // CSF_Pending: Set when transmission or retransmission of the packet is
  1385. // pending. Access is protected by 'pTunnel->lockT'.
  1386. //
  1387. // CSF_TunnelIdleOnAck: Set when TunnelTransitionComplete is to be
  1388. // executed when the message is acknowledged, moving to CCS_Idle
  1389. // state.
  1390. //
  1391. // CSF_CallIdleOnAck: Set when CallTransitionComplete is to be executed
  1392. // when the message is acknowledged, moving to CS_Idle state.
  1393. //
  1394. ULONG ulFlags;
  1395. #define CSF_Pending 0x00000001
  1396. #define CSF_TunnelIdleOnAck 0x00000010
  1397. #define CSF_CallIdleOnAck 0x00000020
  1398. #define CSF_QueryMediaSpeed 0x00000040
  1399. // The outstanding packet's buffer, as passed to TDI.
  1400. //
  1401. CHAR* pBuffer;
  1402. // The length of the data to send in 'pBuffer'.
  1403. //
  1404. ULONG ulBufferLength;
  1405. // Back pointer to owning tunnel.
  1406. //
  1407. TUNNELCB* pTunnel;
  1408. // Back pointer to owning VC, or NULL if none.
  1409. //
  1410. VCCB* pVc;
  1411. // The NDIS system time at which the packet was originally sent.
  1412. //
  1413. LONGLONG llTimeSent;
  1414. // The IRP passed to TDI by the TDIX extension library, or NULL if none or
  1415. // it's already been completed. (for debug purposes only)
  1416. //
  1417. IRP* pIrp;
  1418. }
  1419. CONTROLSENT;
  1420. // Context for a payload packet received out of order which is queued for a
  1421. // time rather than discarding in the hope that the missing packet will
  1422. // arrive.
  1423. //
  1424. typedef struct
  1425. _PAYLOADRECEIVED
  1426. {
  1427. // Link to the prev/next link in the 'VCCB.listOutOfOrder' list.
  1428. //
  1429. LIST_ENTRY linkOutOfOrder;
  1430. // 'Next Sent' sequence number received in the packet.
  1431. //
  1432. USHORT usNs;
  1433. // The received GetBufferFromPool buffer.
  1434. //
  1435. CHAR* pBuffer;
  1436. // Offset of the payload to indicate received in 'pBuffer'.
  1437. //
  1438. ULONG ulPayloadOffset;
  1439. // Length in bytes of the payload to indicate received in 'pBuffer'.
  1440. //
  1441. ULONG ulPayloadLength;
  1442. // NDIS time the packet was received from the net, or 0 if caller did not
  1443. // choose the RECEIVE_TIME_INDICATION option in his call parameters.
  1444. //
  1445. LONGLONG llTimeReceived;
  1446. }
  1447. PAYLOADRECEIVED;
  1448. // Context for a payload packet sent but not yet acknowledged. This block is
  1449. // queued on the 'VCCB.listSendsOut', and is associated with
  1450. // SendPayloadTimerEvents.
  1451. //
  1452. typedef struct
  1453. _PAYLOADSENT
  1454. {
  1455. // Link to the prev/next link in the 'VCCB.listSendsOut' list.
  1456. //
  1457. LIST_ENTRY linkSendsOut;
  1458. // Link to the prev/next link in the 'g_listDebugPs' list. The list is
  1459. // maintained only when PSDEBUG is defined, but this is included always
  1460. // for the convenience of KD extension users. (for debug purposes only)
  1461. //
  1462. LIST_ENTRY linkDebugPs;
  1463. // Reference count on this context. The reference pairs are:
  1464. //
  1465. // (a) A reference is added when the context is queued into the
  1466. // 'listSendsOut' list, and removed by the de-queuer.
  1467. //
  1468. // (b) A reference is added before sending (and also before the time is
  1469. // scheduled) and removed by the send completion routine.
  1470. //
  1471. // (c) A reference is added before scheduling the timer and removed by the
  1472. // timer event handler.
  1473. //
  1474. LONG lRef;
  1475. // 'Next Sent' sequence number sent with the packet.
  1476. //
  1477. USHORT usNs;
  1478. // Timer event descriptor scheduled to fire when it's time to give up on
  1479. // receiving an acknowledge of the packet.
  1480. //
  1481. TIMERQITEM* pTqiSendTimeout;
  1482. // The built NDIS packet.
  1483. //
  1484. NDIS_PACKET* pPacket;
  1485. // The L2TP header buffer prepended to the payload buffer.
  1486. //
  1487. CHAR* pBuffer;
  1488. // Back pointer to the owning tunnel control block.
  1489. //
  1490. TUNNELCB* pTunnel;
  1491. // Back pointer to the owning VC control block.
  1492. //
  1493. VCCB* pVc;
  1494. // Status of the completed packet.
  1495. //
  1496. NDIS_STATUS status;
  1497. // The NDIS system time at which the packet was originally sent.
  1498. //
  1499. LONGLONG llTimeSent;
  1500. // The IRP passed to TDI by the TDIX extension library, or NULL if none or
  1501. // it's already been completed. (for debug purposes only)
  1502. //
  1503. IRP* pIrp;
  1504. }
  1505. PAYLOADSENT;
  1506. // Tunnel work handler that executes tunnel related work at PASSIVE IRQL.
  1507. // 'PWork' is the work context that should be freed with FREE_TUNNELWORK when
  1508. // the handler is done accessing the 'punpArgs' array. 'PTunnel' is the
  1509. // owning tunnel. 'PVc' is the owning VC, or NULL if none. 'PunpArgs' is an
  1510. // array of 4 auxillary arguments as passed to ScheduleTunnelWork.
  1511. //
  1512. typedef
  1513. VOID
  1514. (*PTUNNELWORK)(
  1515. IN TUNNELWORK* pWork,
  1516. IN TUNNELCB* pTunnel,
  1517. IN VCCB* pVc,
  1518. IN ULONG_PTR* punpArgs );
  1519. // Tunnel work item describing a single unit of tunnel related work to be
  1520. // executed serially at PASSIVE IRQL by the TunnelWork mechanism.
  1521. //
  1522. typedef struct
  1523. _TUNNELWORK
  1524. {
  1525. // Link to the prev/next link in the 'TUNNELCB.listWork' queue.
  1526. //
  1527. LIST_ENTRY linkWork;
  1528. // Handler that executes this work item.
  1529. //
  1530. PTUNNELWORK pHandler;
  1531. // The associated VC, if any.
  1532. //
  1533. VCCB* pVc;
  1534. // Auxillary arguments passed to handler.
  1535. //
  1536. ULONG_PTR aunpArgs[ 4 ];
  1537. }
  1538. TUNNELWORK;
  1539. // Context of call setup for an incoming call. The information is used to
  1540. // store and later resume receive processing of an peer's call initiation
  1541. // across the asynchronous CoNdis calls, and for building the call parameter
  1542. // buffer to dispatch to client.
  1543. //
  1544. typedef struct
  1545. _INCALLSETUP
  1546. {
  1547. // See ReceiveControl for descriptions.
  1548. //
  1549. CHAR* pBuffer;
  1550. L2TPHEADERINFO info;
  1551. CONTROLMSGINFO control;
  1552. // Buffer in which the incoming call parameters to be dispatched to caller
  1553. // are built.
  1554. //
  1555. PVOID pvDummyPointerAligner;
  1556. CHAR achCallParams[ sizeof(CO_CALL_PARAMETERS)
  1557. + sizeof(PVOID)
  1558. + sizeof(CO_CALL_MANAGER_PARAMETERS)
  1559. + sizeof(PVOID)
  1560. + sizeof(CO_MEDIA_PARAMETERS)
  1561. + sizeof(CO_AF_TAPI_INCOMING_CALL_PARAMETERS)
  1562. + sizeof(PVOID)
  1563. + sizeof(LINE_CALL_INFO)
  1564. + sizeof(PVOID)
  1565. + sizeof(L2TP_CALL_PARAMETERS)
  1566. + ((L2TP_MaxDottedIpLen + 1) * sizeof(WCHAR)) ];
  1567. }
  1568. INCALLSETUP;
  1569. // The L2TP role played by an L2TP peer. The values may be read from the
  1570. // registry, so don't change randomly.
  1571. //
  1572. typedef enum
  1573. _L2TPROLE
  1574. {
  1575. LR_Lns = 1,
  1576. LR_Lac = 2
  1577. }
  1578. L2TPROLE;
  1579. // The strategy employed when it is time to add a host route and that route is
  1580. // found to already exists.
  1581. //
  1582. // Note: The values currently match the those of the registry parameter
  1583. // "UseExistingRoutes". Check GetRegistrySettings code before changing.
  1584. //
  1585. typedef enum
  1586. _HOSTROUTEEXISTS
  1587. {
  1588. HRE_Use = 0,
  1589. HRE_Fail = 1,
  1590. HRE_Reference = 2
  1591. }
  1592. HOSTROUTEEXISTS;
  1593. // Link status block for transfer across locks. See TransferLinkStatusInfo
  1594. // and IndicateLinkStatus.
  1595. //
  1596. typedef struct
  1597. _LINKSTATUSINFO
  1598. {
  1599. NDIS_HANDLE MiniportAdapterHandle;
  1600. NDIS_HANDLE NdisVcHandle;
  1601. WAN_CO_LINKPARAMS params;
  1602. }
  1603. LINKSTATUSINFO;
  1604. //-----------------------------------------------------------------------------
  1605. // Macros/inlines
  1606. //-----------------------------------------------------------------------------
  1607. #define CtrlObjFromUdpContext(_x) \
  1608. (_x)->pCtrlAddr
  1609. #define PayloadObjFromUdpContext(_x) \
  1610. (_x)->pPayloadAddr
  1611. // These basics are not in the DDK headers for some reason.
  1612. //
  1613. #define min( a, b ) (((a) < (b)) ? (a) : (b))
  1614. #define max( a, b ) (((a) > (b)) ? (a) : (b))
  1615. #define InsertBefore( pNewL, pL ) \
  1616. { \
  1617. (pNewL)->Flink = (pL); \
  1618. (pNewL)->Blink = (pL)->Blink; \
  1619. (pNewL)->Flink->Blink = (pNewL); \
  1620. (pNewL)->Blink->Flink = (pNewL); \
  1621. }
  1622. #define InsertAfter( pNewL, pL ) \
  1623. { \
  1624. (pNewL)->Flink = (pL)->Flink; \
  1625. (pNewL)->Blink = (pL); \
  1626. (pNewL)->Flink->Blink = (pNewL); \
  1627. (pNewL)->Blink->Flink = (pNewL); \
  1628. }
  1629. // Pad to the size of the given datatype. (Borrowed from wdm.h which is not
  1630. // otherwise needed)
  1631. //
  1632. #define ALIGN_DOWN(length, type) \
  1633. ((ULONG)(length) & ~(sizeof(type) - 1))
  1634. #define ALIGN_UP(length, type) \
  1635. (ALIGN_DOWN(((ULONG)(length) + sizeof(type) - 1), type))
  1636. // Winsock-ish host/network byte order converters for short and long integers.
  1637. //
  1638. #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037)) || ((defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_FULL_VER > 13009175))
  1639. #define htons(x) _byteswap_ushort((USHORT)(x))
  1640. #define htonl(x) _byteswap_ulong((ULONG)(x))
  1641. #else
  1642. #define htons( a ) ((((a) & 0xFF00) >> 8) |\
  1643. (((a) & 0x00FF) << 8))
  1644. #define htonl( a ) ((((a) & 0xFF000000) >> 24) | \
  1645. (((a) & 0x00FF0000) >> 8) | \
  1646. (((a) & 0x0000FF00) << 8) | \
  1647. (((a) & 0x000000FF) << 24))
  1648. #endif
  1649. #define ntohs( a ) htons(a)
  1650. #define ntohl( a ) htonl(a)
  1651. // Place in a TRACE argument list to correspond with a format of "%d.%d.%d.%d"
  1652. // to print network byte-ordered IP address 'x' in human readable form.
  1653. //
  1654. #define IPADDRTRACE( x ) ((x) & 0x000000FF), \
  1655. (((x) >> 8) & 0x000000FF), \
  1656. (((x) >> 16) & 0x000000FF), \
  1657. (((x) >> 24) & 0x000000FF)
  1658. // Place in a TRACE argument list to correspond with a format of "%d" to print
  1659. // a percentage of two integers, or an average of two integers, or those
  1660. // values rounded.
  1661. //
  1662. #define PCTTRACE( n, d ) ((d) ? (((n) * 100) / (d)) : 0)
  1663. #define AVGTRACE( t, c ) ((c) ? ((t) / (c)) : 0)
  1664. #define PCTRNDTRACE( n, d ) ((d) ? (((((n) * 1000) / (d)) + 5) / 10) : 0)
  1665. #define AVGRNDTRACE( t, c ) ((c) ? (((((t) * 10) / (c)) + 5) / 10) : 0)
  1666. // All memory allocations and frees are done with these ALLOC_*/FREE_*
  1667. // macros/inlines to allow memory management scheme changes without global
  1668. // editing. For example, might choose to lump several lookaside lists of
  1669. // nearly equal sized items into a single list for efficiency.
  1670. //
  1671. // NdisFreeMemory requires the length of the allocation as an argument. NT
  1672. // currently doesn't use this for non-paged memory, but according to JameelH,
  1673. // Windows95 does. These inlines stash the length at the beginning of the
  1674. // allocation, providing the traditional malloc/free interface. The
  1675. // stash-area is a ULONGLONG so that all allocated blocks remain ULONGLONG
  1676. // aligned as they would be otherwise, preventing problems on Alphas.
  1677. //
  1678. __inline
  1679. VOID*
  1680. ALLOC_NONPAGED(
  1681. IN ULONG ulBufLength,
  1682. IN ULONG ulTag )
  1683. {
  1684. CHAR* pBuf;
  1685. NdisAllocateMemoryWithTag(
  1686. &pBuf, (UINT )(ulBufLength + MEMORY_ALLOCATION_ALIGNMENT), ulTag );
  1687. if (!pBuf)
  1688. {
  1689. return NULL;
  1690. }
  1691. ((ULONG* )pBuf)[ 0 ] = ulBufLength;
  1692. ((ULONG* )pBuf)[ 1 ] = 0xC0BBC0DE;
  1693. return pBuf + MEMORY_ALLOCATION_ALIGNMENT;
  1694. }
  1695. __inline
  1696. VOID
  1697. FREE_NONPAGED(
  1698. IN VOID* pBuf )
  1699. {
  1700. ULONG ulBufLen;
  1701. ulBufLen = *((ULONG* )(((CHAR* )pBuf) - MEMORY_ALLOCATION_ALIGNMENT));
  1702. NdisFreeMemory(
  1703. ((CHAR* )pBuf) - MEMORY_ALLOCATION_ALIGNMENT,
  1704. (UINT )(ulBufLen + MEMORY_ALLOCATION_ALIGNMENT),
  1705. 0 );
  1706. }
  1707. #define ALLOC_NDIS_WORK_ITEM( pA ) \
  1708. NdisAllocateFromNPagedLookasideList( &(pA)->llistWorkItems )
  1709. #define FREE_NDIS_WORK_ITEM( pA, pNwi ) \
  1710. NdisFreeToNPagedLookasideList( &(pA)->llistWorkItems, (pNwi) )
  1711. #define ALLOC_TIMERQITEM( pA ) \
  1712. NdisAllocateFromNPagedLookasideList( &(pA)->llistTimerQItems )
  1713. #define FREE_TIMERQITEM( pA, pTqi ) \
  1714. NdisFreeToNPagedLookasideList( &(pA)->llistTimerQItems, (pTqi) )
  1715. #define ALLOC_CONTROLSENT( pA ) \
  1716. NdisAllocateFromNPagedLookasideList( &(pA)->llistControlSents )
  1717. #define FREE_CONTROLSENT( pA, pCs ) \
  1718. NdisFreeToNPagedLookasideList( &(pA)->llistControlSents, (pCs) )
  1719. #define ALLOC_PAYLOADSENT( pA ) \
  1720. NdisAllocateFromNPagedLookasideList( &(pA)->llistPayloadSents )
  1721. #define FREE_PAYLOADSENT( pA, pPs ) \
  1722. NdisFreeToNPagedLookasideList( &(pA)->llistPayloadSents, (pPs) )
  1723. #define ALLOC_TUNNELWORK( pA ) \
  1724. NdisAllocateFromNPagedLookasideList( &(pA)->llistTunnelWorks )
  1725. #define FREE_TUNNELWORK( pA, pCs ) \
  1726. NdisFreeToNPagedLookasideList( &(pA)->llistTunnelWorks, (pCs) )
  1727. #if LLISTALL
  1728. #define ALLOC_TUNNELCB( pA ) \
  1729. NdisAllocateFromNPagedLookasideList( &(pA)->llistTunnels )
  1730. #define FREE_TUNNELCB( pA, pT ) \
  1731. NdisFreeToNPagedLookasideList( &(pA)->llistTunnels, (pT) )
  1732. #define ALLOC_VCCB( pA ) \
  1733. NdisAllocateFromNPagedLookasideList( &(pA)->llistVcs )
  1734. #define FREE_VCCB( pA, pV ) \
  1735. NdisFreeToNPagedLookasideList( &(pA)->llistVcs, (pV) )
  1736. #define ALLOC_TIMERQ( pA ) \
  1737. NdisAllocateFromNPagedLookasideList( &(pA)->llistTimerQs )
  1738. #define FREE_TIMERQ( pA, pTq ) \
  1739. NdisFreeToNPagedLookasideList( &(pA)->llistTimerQs, (pTq) )
  1740. #define ALLOC_CONTROLRECEIVED( pA ) \
  1741. NdisAllocateFromNPagedLookasideList( &(pA)->llistControlReceiveds )
  1742. #define FREE_CONTROLRECEIVED( pA, pCr ) \
  1743. NdisFreeToNPagedLookasideList( &(pA)->llistControlReceiveds, (pCr) )
  1744. #define ALLOC_PAYLOADRECEIVED( pA ) \
  1745. NdisAllocateFromNPagedLookasideList( &(pA)->llistPayloadReceiveds )
  1746. #define FREE_PAYLOADRECEIVED( pA, pPr ) \
  1747. NdisFreeToNPagedLookasideList( &(pA)->llistPayloadReceiveds, (pPr) )
  1748. #define ALLOC_INCALLSETUP( pA ) \
  1749. NdisAllocateFromNPagedLookasideList( &(pA)->llistInCallSetups )
  1750. #define FREE_INCALLSETUP( pA, pCs ) \
  1751. NdisFreeToNPagedLookasideList( &(pA)->llistInCallSetups, (pCs) )
  1752. #else // !LLISTALL
  1753. #define ALLOC_TUNNELCB( pA ) \
  1754. ALLOC_NONPAGED( sizeof(TUNNELCB), MTAG_TUNNELCB )
  1755. #define FREE_TUNNELCB( pA, pT ) \
  1756. FREE_NONPAGED( pT )
  1757. #define ALLOC_VCCB( pA ) \
  1758. ALLOC_NONPAGED( sizeof(VCCB), MTAG_VCCB )
  1759. #define FREE_VCCB( pA, pV ) \
  1760. FREE_NONPAGED( pV )
  1761. #define ALLOC_TIMERQ( pA ) \
  1762. ALLOC_NONPAGED( sizeof(TIMERQ), MTAG_TIMERQ )
  1763. #define FREE_TIMERQ( pA, pTq ) \
  1764. FREE_NONPAGED( pTq )
  1765. #define ALLOC_CONTROLRECEIVED( pA ) \
  1766. ALLOC_NONPAGED( sizeof(CONTROLRECEIVED), MTAG_CTRLRECD )
  1767. #define FREE_CONTROLRECEIVED( pA, pCr ) \
  1768. FREE_NONPAGED( pCr )
  1769. #define ALLOC_PAYLOADRECEIVED( pA ) \
  1770. ALLOC_NONPAGED( sizeof(PAYLOADRECEIVED), MTAG_PAYLRECD )
  1771. #define FREE_PAYLOADRECEIVED( pA, pPr ) \
  1772. FREE_NONPAGED( pPr )
  1773. #define ALLOC_INCALLSETUP( pA ) \
  1774. ALLOC_NONPAGED( sizeof(INCALLSETUP), MTAG_INCALL )
  1775. #define FREE_INCALLSETUP( pA, pCs ) \
  1776. FREE_NONPAGED( pCs )
  1777. #define ALLOC_CONTROLMSGINFO( pA ) \
  1778. NdisAllocateFromNPagedLookasideList( &(pA)->llistControlMsgInfos )
  1779. #define FREE_CONTROLMSGINFO( pA, pCmi ) \
  1780. NdisFreeToNPagedLookasideList( &(pA)->llistControlMsgInfos, (pCmi) )
  1781. #endif // !LLISTALL
  1782. #if READFLAGSDIRECT
  1783. #define ReadFlags( pulFlags ) \
  1784. (*pulFlags)
  1785. #endif
  1786. //-----------------------------------------------------------------------------
  1787. // Prototypes (alphabetically)
  1788. //-----------------------------------------------------------------------------
  1789. VOID
  1790. ActivateCallIdSlot(
  1791. IN VCCB* pVc );
  1792. VOID
  1793. AddHostRoute(
  1794. IN TUNNELWORK* pWork,
  1795. IN TUNNELCB* pTunnel,
  1796. IN VCCB* pVc,
  1797. IN ULONG_PTR* punpArgs );
  1798. BOOLEAN
  1799. AdjustSendWindowAtAckReceived(
  1800. IN ULONG ulMaxSendWindow,
  1801. IN OUT ULONG* pulAcksSinceSendTimeout,
  1802. IN OUT ULONG* pulSendWindow );
  1803. VOID
  1804. AdjustTimeoutsAtAckReceived(
  1805. IN LONGLONG llSendTime,
  1806. IN ULONG ulMaxSendTimeoutMs,
  1807. OUT ULONG* pulSendTimeoutMs,
  1808. IN OUT ULONG* pulRoundTripMs,
  1809. IN OUT LONG* plDeviationMs );
  1810. VOID
  1811. AdjustTimeoutsAndSendWindowAtTimeout(
  1812. IN ULONG ulMaxSendTimeoutMs,
  1813. IN LONG lDeviationMs,
  1814. OUT ULONG* pulSendTimeoutMs,
  1815. IN OUT ULONG* pulRoundTripMs,
  1816. IN OUT ULONG* pulSendWindow,
  1817. OUT ULONG* pulAcksSinceSendTimeout );
  1818. #if 0
  1819. VOID
  1820. BuildWanAddress(
  1821. IN CHAR* pArg1,
  1822. IN ULONG ulLength1,
  1823. IN CHAR* pArg2,
  1824. IN ULONG ulLength2,
  1825. IN CHAR* pArg3,
  1826. IN ULONG ulLength3,
  1827. OUT WAN_ADDRESS* pWanAddress );
  1828. #endif
  1829. VOID
  1830. CalculateResponse(
  1831. IN UCHAR* puchChallenge,
  1832. IN ULONG ulChallengeLength,
  1833. IN CHAR* pszPassword,
  1834. IN UCHAR uchId,
  1835. OUT UCHAR* puchResponse );
  1836. VOID
  1837. CallCleanUp(
  1838. IN VCCB* pVc );
  1839. VOID
  1840. CallTransitionComplete(
  1841. IN TUNNELCB* pTunnel,
  1842. IN VCCB* pVc,
  1843. IN L2TPCALLSTATE state );
  1844. VOID
  1845. ChangeHostRoute(
  1846. IN TUNNELWORK* pWork,
  1847. IN TUNNELCB* pTunnel,
  1848. IN VCCB* pVc,
  1849. IN ULONG_PTR* punpArgs );
  1850. VOID
  1851. ClearFlags(
  1852. IN OUT ULONG* pulFlags,
  1853. IN ULONG ulMask );
  1854. VOID
  1855. CloseCall(
  1856. IN TUNNELWORK* pWork,
  1857. IN TUNNELCB* pTunnel,
  1858. IN VCCB* pVc,
  1859. IN ULONG_PTR* punpArgs );
  1860. BOOLEAN
  1861. CloseCall2(
  1862. IN TUNNELCB* pTunnel,
  1863. IN VCCB* pVc,
  1864. IN USHORT usResult,
  1865. IN USHORT usError );
  1866. VOID
  1867. CloseTdix(
  1868. IN TUNNELWORK* pWork,
  1869. IN TUNNELCB* pTunnel,
  1870. IN VCCB* pVc,
  1871. IN ULONG_PTR* punpArgs );
  1872. VOID
  1873. CloseTunnel(
  1874. IN TUNNELWORK* pWork,
  1875. IN TUNNELCB* pTunnel,
  1876. IN VCCB* pVc,
  1877. IN ULONG_PTR* punpArgs );
  1878. VOID
  1879. CloseTunnel2(
  1880. IN TUNNELCB* pTunnel );
  1881. VOID
  1882. CompleteVcs(
  1883. IN TUNNELCB* pTunnel );
  1884. VOID
  1885. DeleteHostRoute(
  1886. IN TUNNELWORK* pWork,
  1887. IN TUNNELCB* pTunnel,
  1888. IN VCCB* pVc,
  1889. IN ULONG_PTR* punpArgs );
  1890. VOID
  1891. DereferenceAdapter(
  1892. IN ADAPTERCB* pAdapter );
  1893. VOID
  1894. DereferenceCall(
  1895. IN VCCB* pVc );
  1896. LONG
  1897. DereferenceControlSent(
  1898. IN CONTROLSENT* pSent );
  1899. LONG
  1900. DereferencePayloadSent(
  1901. IN PAYLOADSENT* pPs );
  1902. VOID
  1903. DereferenceSap(
  1904. IN ADAPTERCB* pAdapter );
  1905. LONG
  1906. DereferenceTunnel(
  1907. IN TUNNELCB* pTunnel );
  1908. VOID
  1909. DereferenceVc(
  1910. IN VCCB* pVc );
  1911. VOID
  1912. DottedFromIpAddress(
  1913. IN ULONG ulIpAddress,
  1914. OUT CHAR* pszIpAddress,
  1915. IN BOOLEAN fUnicode );
  1916. NDIS_STATUS
  1917. ExecuteWork(
  1918. IN ADAPTERCB* pAdapter,
  1919. IN NDIS_PROC pProc,
  1920. IN PVOID pContext,
  1921. IN ULONG ulArg1,
  1922. IN ULONG ulArg2,
  1923. IN ULONG ulArg3,
  1924. IN ULONG ulArg4 );
  1925. #if 0
  1926. VOID
  1927. ExplodeWanAddress(
  1928. IN WAN_ADDRESS* pWanAddress,
  1929. OUT CHAR** ppArg1,
  1930. OUT ULONG* pulLength1,
  1931. OUT CHAR** ppArg2,
  1932. OUT ULONG* pulLength2,
  1933. OUT CHAR** ppArg3,
  1934. OUT ULONG* pulLength3 );
  1935. #endif
  1936. VOID
  1937. FsmCloseCall(
  1938. IN TUNNELWORK* pWork,
  1939. IN TUNNELCB* pTunnel,
  1940. IN VCCB* pVc,
  1941. IN ULONG_PTR* punpArgs );
  1942. VOID
  1943. FsmCloseTunnel(
  1944. IN TUNNELWORK* pWork,
  1945. IN TUNNELCB* pTunnel,
  1946. IN VCCB* pVc,
  1947. IN ULONG_PTR* punpArgs );
  1948. VOID
  1949. FsmOpenCall(
  1950. IN TUNNELCB* pTunnel,
  1951. IN VCCB* pVc );
  1952. VOID
  1953. FsmOpenTunnel(
  1954. IN TUNNELWORK* pWork,
  1955. IN TUNNELCB* pTunnel,
  1956. IN VCCB* pVc,
  1957. IN ULONG_PTR* punpArgs );
  1958. VOID
  1959. FsmOpenIdleTunnel(
  1960. IN TUNNELCB* pTunnel,
  1961. IN VCCB* pVc );
  1962. BOOLEAN
  1963. FsmReceive(
  1964. IN TUNNELCB* pTunnel,
  1965. IN VCCB* pVc,
  1966. IN CHAR* pBuffer,
  1967. IN CONTROLMSGINFO* pControl );
  1968. CHAR*
  1969. GetFullHostNameFromRegistry(
  1970. VOID );
  1971. USHORT
  1972. GetNextTerminationCallId(
  1973. IN ADAPTERCB* pAdapter );
  1974. USHORT
  1975. GetNextTunnelId(
  1976. IN ADAPTERCB* pAdapter );
  1977. VOID
  1978. IndicateLinkStatus(
  1979. IN VCCB* pVc,
  1980. IN LINKSTATUSINFO* pInfo );
  1981. ULONG
  1982. IpAddressFromDotted(
  1983. IN CHAR* pchIpAddress );
  1984. NDIS_STATUS
  1985. LcmCmOpenAf(
  1986. IN NDIS_HANDLE CallMgrBindingContext,
  1987. IN PCO_ADDRESS_FAMILY AddressFamily,
  1988. IN NDIS_HANDLE NdisAfHandle,
  1989. OUT PNDIS_HANDLE CallMgrAfContext );
  1990. NDIS_STATUS
  1991. LcmCmCloseAf(
  1992. IN NDIS_HANDLE CallMgrAfContext );
  1993. NDIS_STATUS
  1994. LcmCmRegisterSap(
  1995. IN NDIS_HANDLE CallMgrAfContext,
  1996. IN PCO_SAP Sap,
  1997. IN NDIS_HANDLE NdisSapHandle,
  1998. OUT PNDIS_HANDLE CallMgrSapContext );
  1999. NDIS_STATUS
  2000. LcmCmDeregisterSap(
  2001. NDIS_HANDLE CallMgrSapContext );
  2002. #ifndef OLDMCM
  2003. NDIS_STATUS
  2004. LcmCmCreateVc(
  2005. IN NDIS_HANDLE ProtocolAfContext,
  2006. IN NDIS_HANDLE NdisVcHandle,
  2007. OUT PNDIS_HANDLE ProtocolVcContext );
  2008. NDIS_STATUS
  2009. LcmCmDeleteVc(
  2010. IN NDIS_HANDLE ProtocolVcContext );
  2011. #endif // !OLDMCM
  2012. NDIS_STATUS
  2013. LcmCmMakeCall(
  2014. IN NDIS_HANDLE CallMgrVcContext,
  2015. IN OUT PCO_CALL_PARAMETERS CallParameters,
  2016. IN NDIS_HANDLE NdisPartyHandle,
  2017. OUT PNDIS_HANDLE CallMgrPartyContext );
  2018. NDIS_STATUS
  2019. LcmCmCloseCall(
  2020. IN NDIS_HANDLE CallMgrVcContext,
  2021. IN NDIS_HANDLE CallMgrPartyContext,
  2022. IN PVOID CloseData,
  2023. IN UINT Size );
  2024. VOID
  2025. LcmCmIncomingCallComplete(
  2026. IN NDIS_STATUS Status,
  2027. IN NDIS_HANDLE CallMgrVcContext,
  2028. IN PCO_CALL_PARAMETERS CallParameters );
  2029. VOID
  2030. LcmCmActivateVcComplete(
  2031. IN NDIS_STATUS Status,
  2032. IN NDIS_HANDLE CallMgrVcContext,
  2033. IN PCO_CALL_PARAMETERS CallParameters );
  2034. VOID
  2035. LcmCmDeactivateVcComplete(
  2036. IN NDIS_STATUS Status,
  2037. IN NDIS_HANDLE CallMgrVcContext );
  2038. NDIS_STATUS
  2039. LcmCmModifyCallQoS(
  2040. IN NDIS_HANDLE CallMgrVcContext,
  2041. IN PCO_CALL_PARAMETERS CallParameters );
  2042. NDIS_STATUS
  2043. LcmCmRequest(
  2044. IN NDIS_HANDLE CallMgrAfContext,
  2045. IN NDIS_HANDLE CallMgrVcContext,
  2046. IN NDIS_HANDLE CallMgrPartyContext,
  2047. IN OUT PNDIS_REQUEST NdisRequest );
  2048. NDIS_STATUS
  2049. LmpInitialize(
  2050. OUT PNDIS_STATUS OpenErrorStatus,
  2051. OUT PUINT SelectedMediumIndex,
  2052. IN PNDIS_MEDIUM MediumArray,
  2053. IN UINT MediumArraySize,
  2054. IN NDIS_HANDLE MiniportAdapterHandle,
  2055. IN NDIS_HANDLE WrapperConfigurationContext );
  2056. VOID
  2057. LmpHalt(
  2058. IN NDIS_HANDLE MiniportAdapterContext );
  2059. NDIS_STATUS
  2060. LmpReset(
  2061. OUT PBOOLEAN AddressingReset,
  2062. IN NDIS_HANDLE MiniportAdapterContext );
  2063. VOID
  2064. LmpReturnPacket(
  2065. IN NDIS_HANDLE MiniportAdapterContext,
  2066. IN PNDIS_PACKET Packet );
  2067. NDIS_STATUS
  2068. LmpQueryInformation(
  2069. IN NDIS_HANDLE MiniportAdapterContext,
  2070. IN NDIS_OID Oid,
  2071. IN PVOID InformationBuffer,
  2072. IN ULONG InformationBufferLength,
  2073. OUT PULONG BytesWritten,
  2074. OUT PULONG BytesNeeded );
  2075. NDIS_STATUS
  2076. LmpSetInformation(
  2077. IN NDIS_HANDLE MiniportAdapterContext,
  2078. IN NDIS_OID Oid,
  2079. IN PVOID InformationBuffer,
  2080. IN ULONG InformationBufferLength,
  2081. OUT PULONG BytesRead,
  2082. OUT PULONG BytesNeeded );
  2083. #ifdef OLDMCM
  2084. NDIS_STATUS
  2085. LmpCoCreateVc(
  2086. IN NDIS_HANDLE MiniportAdapterContext,
  2087. IN NDIS_HANDLE NdisVcHandle,
  2088. IN PNDIS_HANDLE MiniportVcContext );
  2089. NDIS_STATUS
  2090. LmpCoDeleteVc(
  2091. IN NDIS_HANDLE MiniportVcContext );
  2092. #endif // OLDMCM
  2093. NDIS_STATUS
  2094. LmpCoActivateVc(
  2095. IN NDIS_HANDLE MiniportVcContext,
  2096. IN OUT PCO_CALL_PARAMETERS CallParameters );
  2097. NDIS_STATUS
  2098. LmpCoDeactivateVc(
  2099. IN NDIS_HANDLE MiniportVcContext );
  2100. VOID
  2101. LmpCoSendPackets(
  2102. IN NDIS_HANDLE MiniportVcContext,
  2103. IN PPNDIS_PACKET PacketArray,
  2104. IN UINT NumberOfPackets );
  2105. NDIS_STATUS
  2106. LmpCoRequest(
  2107. IN NDIS_HANDLE MiniportAdapterContext,
  2108. IN NDIS_HANDLE MiniportVcContext,
  2109. IN OUT PNDIS_REQUEST NdisRequest );
  2110. VOID
  2111. L2tpReceive(
  2112. IN TDIXCONTEXT* pTdix,
  2113. IN TDIXRDGINFO* pRdg,
  2114. IN CHAR* pBuffer,
  2115. IN ULONG ulOffset,
  2116. IN ULONG ulBufferLen );
  2117. CHAR*
  2118. MsgTypePszFromUs(
  2119. IN USHORT usMsgType );
  2120. #if READFLAGSDIRECT == 0
  2121. ULONG
  2122. ReadFlags(
  2123. IN ULONG* pulFlags );
  2124. #endif
  2125. BOOLEAN
  2126. ReceiveControlExpected(
  2127. IN TUNNELCB* pTunnel,
  2128. IN VCCB* pVc,
  2129. IN CHAR* pBuffer,
  2130. IN CONTROLMSGINFO* pControl );
  2131. VOID
  2132. ReferenceAdapter(
  2133. IN ADAPTERCB* pAdapter );
  2134. BOOLEAN
  2135. ReferenceCall(
  2136. IN VCCB* pVc );
  2137. VOID
  2138. ReferenceControlSent(
  2139. IN CONTROLSENT* pSent );
  2140. VOID
  2141. ReferencePayloadSent(
  2142. IN PAYLOADSENT* pPs );
  2143. BOOLEAN
  2144. ReferenceSap(
  2145. IN ADAPTERCB* pAdapter );
  2146. LONG
  2147. ReferenceTunnel(
  2148. IN TUNNELCB* pTunnel,
  2149. IN BOOLEAN fHaveLockTunnels );
  2150. VOID
  2151. ReferenceVc(
  2152. IN VCCB* pVc );
  2153. BOOLEAN
  2154. ReleaseCallIdSlot(
  2155. IN VCCB* pVc );
  2156. NDIS_STATUS
  2157. ReserveCallIdSlot(
  2158. IN VCCB* pVc );
  2159. VOID
  2160. ResetHelloTimer(
  2161. IN TUNNELCB* pTunnel );
  2162. VOID
  2163. ScheduleTunnelWork(
  2164. IN TUNNELCB* pTunnel,
  2165. IN VCCB* pVc,
  2166. IN PTUNNELWORK pHandler,
  2167. IN ULONG_PTR unpArg0,
  2168. IN ULONG_PTR unpArg1,
  2169. IN ULONG_PTR unpArg2,
  2170. IN ULONG_PTR unpArg3,
  2171. IN BOOLEAN fTcbPreReferenced,
  2172. IN BOOLEAN fHighPriority );
  2173. NDIS_STATUS
  2174. ScheduleWork(
  2175. IN ADAPTERCB* pAdapter,
  2176. IN NDIS_PROC pProc,
  2177. IN PVOID pContext );
  2178. VOID
  2179. SendControlAck(
  2180. IN TUNNELWORK* pWork,
  2181. IN TUNNELCB* pTunnel,
  2182. IN VCCB* pVc,
  2183. IN ULONG_PTR* punpArgs );
  2184. VOID
  2185. SendControl(
  2186. IN TUNNELCB* pTunnel,
  2187. IN VCCB* pVc,
  2188. IN USHORT usMsgType,
  2189. IN ULONG ulBuildAvpsArg1,
  2190. IN ULONG ulBuildAvpsArg2,
  2191. IN PVOID pvBuildAvpsArg3,
  2192. IN ULONG ulFlags );
  2193. VOID
  2194. SendControlTimerEvent(
  2195. IN TIMERQITEM* pItem,
  2196. IN VOID* pContext,
  2197. IN TIMERQEVENT event );
  2198. VOID
  2199. SendPayload(
  2200. IN VCCB* pVc,
  2201. IN NDIS_PACKET* pPacket );
  2202. VOID
  2203. SendPayloadAck(
  2204. IN TUNNELWORK* pWork,
  2205. IN TUNNELCB* pTunnel,
  2206. IN VCCB* pVc,
  2207. IN ULONG_PTR* punpArgs );
  2208. VOID
  2209. SendPending(
  2210. IN TUNNELWORK* pWork,
  2211. IN TUNNELCB* pTunnel,
  2212. IN VCCB* pVc,
  2213. IN ULONG_PTR* punpArgs );
  2214. VOID
  2215. SetFlags(
  2216. IN OUT ULONG* pulFlags,
  2217. IN ULONG ulMask );
  2218. TUNNELCB*
  2219. SetupTunnel(
  2220. IN ADAPTERCB* pAdapter,
  2221. IN ULONG ulIpAddress,
  2222. IN USHORT usAssignedTunnelId,
  2223. IN BOOLEAN fExclusive );
  2224. VOID
  2225. SetupVcAsynchronously(
  2226. IN TUNNELCB* pTunnel,
  2227. IN ULONG ulIpAddress,
  2228. IN CHAR* pBuffer,
  2229. IN CONTROLMSGINFO* pControl );
  2230. VOID
  2231. StrCpyW(
  2232. IN WCHAR* psz1,
  2233. IN WCHAR* psz2 );
  2234. CHAR*
  2235. StrDup(
  2236. IN CHAR* psz );
  2237. WCHAR*
  2238. StrDupAsciiToUnicode(
  2239. IN CHAR* psz,
  2240. IN ULONG ulPszBytes );
  2241. WCHAR*
  2242. StrDupNdisString(
  2243. IN NDIS_STRING* pNdisString );
  2244. CHAR*
  2245. StrDupNdisVarDataDescStringA(
  2246. IN NDIS_VAR_DATA_DESC* pDesc );
  2247. CHAR*
  2248. StrDupNdisVarDataDescStringToA(
  2249. IN NDIS_VAR_DATA_DESC UNALIGNED* pDesc );
  2250. CHAR*
  2251. StrDupNdisStringToA(
  2252. IN NDIS_STRING* pNdisString );
  2253. CHAR*
  2254. StrDupSized(
  2255. IN CHAR* psz,
  2256. IN ULONG ulLength,
  2257. IN ULONG ulExtra );
  2258. CHAR*
  2259. StrDupUnicodeToAscii(
  2260. IN WCHAR* pwsz,
  2261. IN ULONG ulPwszBytes );
  2262. ULONG
  2263. StrLenW(
  2264. IN WCHAR* psz );
  2265. VOID
  2266. TransferLinkStatusInfo(
  2267. IN VCCB* pVc,
  2268. OUT LINKSTATUSINFO* pInfo );
  2269. TUNNELCB*
  2270. TunnelCbFromIpAddressAndAssignedTunnelId(
  2271. IN ADAPTERCB* pAdapter,
  2272. IN ULONG ulIpAddress,
  2273. IN USHORT usAssignedTunnelId );
  2274. VOID
  2275. TunnelTransitionComplete(
  2276. IN TUNNELCB* pTunnel,
  2277. IN L2TPCCSTATE state );
  2278. VOID
  2279. UpdateGlobalCallStats(
  2280. IN VCCB* pVc );
  2281. VCCB*
  2282. VcCbFromCallId(
  2283. IN TUNNELCB* pTunnel,
  2284. IN USHORT usCallId );
  2285. #endif // _L2TPP_H_