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

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