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.

1162 lines
32 KiB

  1. //depot/Lab03_N/Net/rras/ndis/raspptp/common/raspptp.h#7 - edit change 19457 (text)
  2. /*****************************************************************************
  3. *
  4. * Copyright (c) 1998-1999 Microsoft Corporation
  5. *
  6. * RASPPTP.H - RASPPTP includes, defines, structures and prototypes
  7. *
  8. * Author: Stan Adermann (stana)
  9. *
  10. * Created: 7/28/1998
  11. *
  12. *****************************************************************************/
  13. #ifndef RASPPTP_H
  14. #define RASPPTP_H
  15. #include "osinc.h"
  16. #ifdef STATIC
  17. #undef STATIC
  18. #endif
  19. #define STATIC
  20. #include "debug.h"
  21. #include "protocol.h"
  22. #include "ctdi.h"
  23. #include <rc4.h>
  24. #include <fipsapi.h>
  25. //
  26. // NDIS version compatibility in OSINC.H
  27. //
  28. // TAPI version compatibility
  29. #define TAPI_EXT_VERSION 0x00010000
  30. // Registry values
  31. extern ULONG PptpMaxTransmit;
  32. extern ULONG PptpWanEndpoints;
  33. extern ULONG PptpBaseCallId;
  34. extern ULONG PptpMaxCallId;
  35. extern ULONG PptpCallIdMask;
  36. extern BOOLEAN PptpClientSide;
  37. extern ULONG PptpEchoTimeout;
  38. extern BOOLEAN PptpEchoAlways;
  39. extern USHORT PptpControlPort;
  40. extern USHORT PptpProtocolNumber;
  41. extern LONG PptpSendRecursionLimit;
  42. extern ULONG PptpValidateAddress;
  43. #define PPTP_SEND_RECURSION_LIMIT_DEFAULT 5
  44. //extern CHAR PptpHostName[MAX_HOSTNAME_LENGTH];
  45. #define CONFIG_INITIATE_UDP BIT(0)
  46. #define CONFIG_ACCEPT_UDP BIT(1)
  47. #define CONFIG_DONT_ACCEPT_GRE BIT(2)
  48. // trace the various pended tx lists
  49. extern ULONG PptpTraceMask;
  50. #define PPTP_TRACE_TX_PKT BIT(0)
  51. #define PPTP_TRACE_TX_IRP BIT(1)
  52. typedef struct {
  53. ULONG Address;
  54. ULONG Mask;
  55. } CLIENT_ADDRESS, *PCLIENT_ADDRESS;
  56. extern ULONG CtdiTcpDisconnectTimeout;
  57. extern ULONG CtdiTcpConnectTimeout;
  58. extern BOOLEAN PptpAuthenticateIncomingCalls;
  59. extern PCLIENT_ADDRESS g_AcceptClientList;
  60. extern ULONG g_ulAcceptClientAddresses;
  61. extern ULONG PptpMaxTunnelsPerIpAddress;
  62. extern PCLIENT_ADDRESS g_TrustedClientList;
  63. extern ULONG g_ulTrustedClientAddresses;
  64. #define TAPI_MAX_LINE_ADDRESS_LENGTH 32
  65. #define TAPI_ADDR_PER_LINE 1
  66. #define TAPI_ADDRESSID 0
  67. #define TAPI_DEVICECLASS_NAME "tapi/line"
  68. #define TAPI_DEVICECLASS_ID 1
  69. #define NDIS_DEVICECLASS_NAME "ndis"
  70. #define NDIS_DEVICECLASS_ID 2
  71. #define PPTP_CLOSE_TIMEOUT 1000 // ms
  72. #define MAX_TARGET_ADDRESSES 16
  73. #define CALL_STATES_MASK (LINECALLSTATE_UNKNOWN | \
  74. LINECALLSTATE_IDLE | \
  75. LINECALLSTATE_OFFERING | \
  76. LINECALLSTATE_DIALING | \
  77. LINECALLSTATE_PROCEEDING | \
  78. LINECALLSTATE_CONNECTED | \
  79. LINECALLSTATE_DISCONNECTED)
  80. // Memory allocation tags
  81. #define TAG(v) ((((v)&0xff)<<24) | (((v)&0xff00)<<8) | (((v)&0xff0000)>>8) | (((v)&0xff000000)>>24))
  82. #define TAG_PPTP_ADAPTER TAG('PTPa')
  83. #define TAG_PPTP_TUNNEL TAG('PTPT')
  84. #define TAG_PPTP_TIMEOUT TAG('PTPt')
  85. #define TAG_PPTP_CALL TAG('PTPC')
  86. #define TAG_PPTP_CALL_LIST TAG('PTPc')
  87. #define TAG_PPTP_ADDR_LIST TAG('PTPL')
  88. #define TAG_CTDI_DATA TAG('PTCD')
  89. #define TAG_CTDI_CONNECT_INFO TAG('PTCN')
  90. #define TAG_CTDI_DGRAM TAG('PTCG')
  91. #define TAG_CTDI_ROUTE TAG('PTCR')
  92. #define TAG_CTDI_IRP TAG('PTCI')
  93. #define TAG_CTDI_MESSAGE TAG('PTCM')
  94. #define TAG_CTL_PACKET TAG('PTTP')
  95. #define TAG_CTL_CONNINFO TAG('PTTI')
  96. #define TAG_WORK_ITEM TAG('PTWI')
  97. #define TAG_THREAD TAG('PTTH')
  98. #define TAG_REG TAG('PTRG')
  99. #define TAG_FREE TAG('FREE')
  100. #define BIT(b) (1<<(b))
  101. #define LOCKED TRUE
  102. #define UNLOCKED FALSE
  103. /* Types and structs -------------------------------------------------------*/
  104. typedef void (*FREEFUNC)(PVOID);
  105. typedef struct {
  106. LONG Count;
  107. FREEFUNC FreeFunction;
  108. } REFERENCE_COUNT;
  109. #define INIT_REFERENCE_OBJECT(o,freefunc) \
  110. { \
  111. (o)->Reference.FreeFunction = (freefunc); \
  112. (o)->Reference.Count = 1; \
  113. DEBUGMSG(DBG_REF, (DTEXT("INIT REF (%08x, %d) %s\n"), (o), (o)->Reference.Count, #o)); \
  114. }
  115. #if DBG
  116. #define REFERENCE_OBJECT(o) \
  117. { \
  118. LONG Ref; \
  119. Ref = NdisInterlockedIncrement(&(o)->Reference.Count); \
  120. ASSERT(Ref != 1); \
  121. DEBUGMSG(DBG_REF, (DTEXT("REFERENCE (%08x, %d) %s %d\n"), (o), (o)->Reference.Count, #o, __LINE__)); \
  122. }
  123. #else
  124. #define REFERENCE_OBJECT(o) \
  125. { \
  126. NdisInterlockedIncrement(&(o)->Reference.Count); \
  127. DEBUGMSG(DBG_REF, (DTEXT("REFERENCE (%08x, %d) %s %d\n"), (o), (o)->Reference.Count, #o, __LINE__)); \
  128. }
  129. #endif
  130. #define DEREFERENCE_OBJECT(o) \
  131. { \
  132. ULONG Ref = NdisInterlockedDecrement(&(o)->Reference.Count); \
  133. DEBUGMSG(DBG_REF, (DTEXT("DEREFERENCE(%08x, %d) %s %d\n"), (o), (o)->Reference.Count, #o, __LINE__)); \
  134. if (Ref==0) \
  135. { \
  136. ASSERT((o)->Reference.FreeFunction); \
  137. DEBUGMSG(DBG_REF, (DTEXT("Last reference released, freeing %08x\n"), (o))); \
  138. (o)->Reference.FreeFunction(o); \
  139. } \
  140. }
  141. #if DBG
  142. #define REFERENCE_OBJECT_EX(o, index) \
  143. { \
  144. NdisInterlockedIncrement(&(o)->arrRef[index]); \
  145. REFERENCE_OBJECT(o); \
  146. }
  147. #define DEREFERENCE_OBJECT_EX(o, index) \
  148. { \
  149. NdisInterlockedDecrement(&(o)->arrRef[index]); \
  150. DEREFERENCE_OBJECT(o); \
  151. }
  152. #else
  153. #define REFERENCE_OBJECT_EX(o, index) \
  154. { \
  155. REFERENCE_OBJECT(o); \
  156. }
  157. #define DEREFERENCE_OBJECT_EX(o, index) \
  158. { \
  159. DEREFERENCE_OBJECT(o); \
  160. }
  161. #endif
  162. #define REFERENCE_COUNT(o) ((o)->Reference.Count)
  163. #define IS_CALL(call) ((call) && (call)->Signature==TAG_PPTP_CALL)
  164. #define IS_CTL(ctl) ((ctl) && (ctl)->Signature==TAG_PPTP_TUNNEL)
  165. #define IS_LINE_UP(call) (!((call)->Close.Checklist&CALL_CLOSE_LINE_DOWN))
  166. // If you change this enum then be sure to change ControlStateToString() also.
  167. typedef enum {
  168. STATE_CTL_INVALID = 0,
  169. STATE_CTL_LISTEN,
  170. STATE_CTL_DIALING,
  171. STATE_CTL_WAIT_REQUEST,
  172. STATE_CTL_WAIT_REPLY,
  173. STATE_CTL_ESTABLISHED,
  174. STATE_CTL_WAIT_STOP,
  175. STATE_CTL_CLEANUP,
  176. NUM_CONTROL_STATES
  177. } CONTROL_STATE;
  178. // If you change this enum then be sure to change CallStateToString() also.
  179. typedef enum {
  180. STATE_CALL_INVALID = 0,
  181. STATE_CALL_CLOSED,
  182. STATE_CALL_IDLE,
  183. STATE_CALL_OFFHOOK,
  184. STATE_CALL_OFFERING,
  185. STATE_CALL_PAC_OFFERING,
  186. STATE_CALL_PAC_WAIT,
  187. STATE_CALL_DIALING,
  188. STATE_CALL_PROCEEDING,
  189. STATE_CALL_ESTABLISHED,
  190. STATE_CALL_WAIT_DISCONNECT,
  191. STATE_CALL_CLEANUP,
  192. NUM_CALL_STATES
  193. } CALL_STATE;
  194. typedef struct PPTP_ADAPTER *PPPTP_ADAPTER;
  195. typedef enum {
  196. CTL_REF_INITIAL = 0,
  197. CTL_REF_PACKET,
  198. CTL_REF_ENUM,
  199. CTL_REF_CLEANUP,
  200. CTL_REF_QUERYCONNINFO,
  201. CTL_REF_QUERYADDRINFO,
  202. CTL_REF_CALLCONNECT,
  203. CTL_REF_CTLCONNECT,
  204. CTL_REF_CONNECTCALLBACK,
  205. CTL_REF_DISCONNECT,
  206. CTL_REF_CLEANUPLOOSEENDS,
  207. CTL_REF_CLEANUPCTLS,
  208. CTL_REF_MAX
  209. } CTL_REF;
  210. typedef struct CONTROL_TUNNEL {
  211. LIST_ENTRY ListEntry;
  212. // Used to attach this control connection to the miniport context.
  213. REFERENCE_COUNT Reference;
  214. // Not protected by spinlock
  215. ULONG Signature;
  216. // PTPT
  217. PPPTP_ADAPTER pAdapter;
  218. // The associated adapter
  219. CONTROL_STATE State;
  220. // State of this control connection
  221. LIST_ENTRY CallList;
  222. // List of calls supported by this control connection.
  223. // Protected by adapter lock
  224. BOOLEAN Inbound;
  225. // Indicates whether this tunnel originated here or elsewhere
  226. UCHAR Padding[sizeof(ULONG_PTR)];
  227. // We pad to protect the portions of the struct protected by different locks
  228. // from alpha alignment problems.
  229. // ^^^^^^ Protected by Adapter->Lock^^^^^^^^
  230. //===================================================================
  231. NDIS_SPIN_LOCK Lock;
  232. // vvvvvv Protected by Ctl->Lock vvvvvvvvvvv
  233. BOOLEAN Cleanup;
  234. // True means a cleanup has been scheduled or is active.
  235. LIST_ENTRY MessageList;
  236. // Each entry represents a pptp message that has been sent and
  237. // is awaiting a response or at least waiting to be acknowledged
  238. // by the transport
  239. HANDLE hCtdiEndpoint;
  240. // Handle for the tunnel local endpoint. The connection must be closed first.
  241. HANDLE hCtdi;
  242. // Handle for control tunnel TCP connection.
  243. UCHAR PartialPacketBuffer[MAX_CONTROL_PACKET_LENGTH];
  244. ULONG BytesInPartialBuffer;
  245. // TCP data received that does not constitute a full packet.
  246. struct {
  247. TA_IP_ADDRESS Address;
  248. ULONG Version;
  249. ULONG Framing;
  250. ULONG Bearer;
  251. UCHAR HostName[MAX_HOSTNAME_LENGTH];
  252. UCHAR Vendor[MAX_VENDOR_LENGTH];
  253. } Remote;
  254. // Information provided by the remote.
  255. ULONG LocalAddress;
  256. PULONG PptpMessageLength;
  257. // Points to an array of precalculated packet lengths, based on version
  258. struct {
  259. NDIS_MINIPORT_TIMER Timer;
  260. ULONG Identifier;
  261. BOOLEAN Needed;
  262. #define PPTP_ECHO_TIMEOUT_DEFAULT 60
  263. } Echo;
  264. #define PPTP_MESSAGE_TIMEOUT_DEFAULT 30
  265. NDIS_MINIPORT_TIMER WaitTimeout;
  266. NDIS_MINIPORT_TIMER StopTimeout;
  267. ULONG Speed;
  268. // Contains line speed of this connect in BPS
  269. #if DBG
  270. ULONG arrRef[CTL_REF_MAX];
  271. #endif
  272. } CONTROL_TUNNEL, *PCONTROL_TUNNEL;
  273. typedef struct CALL_SESSION {
  274. LIST_ENTRY ListEntry;
  275. // Used to attach a call session to a control connection
  276. ULONG Signature;
  277. // PTPC
  278. PPPTP_ADAPTER pAdapter;
  279. // The associated adapter
  280. LIST_ENTRY TxListEntry;
  281. // If we have packets to send, this connects us to the queue of the transmitting thread.
  282. PCONTROL_TUNNEL pCtl;
  283. // Pointer to this call's control connection.
  284. UCHAR Padding[sizeof(ULONG_PTR)];
  285. // We pad to protect the portions of the struct protected by different locks
  286. // from alpha alignment problems.
  287. // ^^^^^^^^^^ Protected by Adapter->Lock ^^^^^^^^^^^^^^
  288. // ============================================================================
  289. REFERENCE_COUNT Reference;
  290. // Not protected by spinlock
  291. NDIS_SPIN_LOCK Lock;
  292. // vvvvvvvvvv Protected by Call->Lock vvvvvvvvvvvvvvvvv
  293. CALL_STATE State;
  294. // State of this call.
  295. LIST_ENTRY TxPacketList;
  296. // Context for each send currently queued
  297. LIST_ENTRY TxActivePacketList;
  298. // Context for each send currently active in transport
  299. LIST_ENTRY RxPacketList;
  300. // Context for each datagram received but not processed
  301. ULONG_PTR RxPacketsPending;
  302. // Count of RxPackets in RxPacketList
  303. BOOLEAN PendingUse;
  304. // This call is being used though it's in STATE_CALL_IDLE
  305. BOOLEAN Inbound;
  306. // TRUE indicates call did not originate here
  307. BOOLEAN Open;
  308. // Open has been called, but not close
  309. BOOLEAN Transferring;
  310. // TRUE means we are on the queue to transmit or receive packets.
  311. HTAPI_CALL hTapiCall;
  312. // Tapi's handle to the specific call
  313. ULONG_PTR DeviceId;
  314. // The ID of this call, essentially the index in the call array
  315. ULONG_PTR FullDeviceId;
  316. // The ID used in PPTP call id field and used as TAPI hdCall
  317. USHORT SerialNumber;
  318. // Unique for this call
  319. NDIS_HANDLE NdisLinkContext;
  320. // Ndis's handle, used in MiniportReceive, etc.
  321. NDIS_WAN_SET_LINK_INFO WanLinkInfo;
  322. struct {
  323. ULONG SequenceNumber;
  324. // Last received GRE sequence number
  325. ULONG AckNumber;
  326. // Last received GRE Ack number
  327. TA_IP_ADDRESS Address;
  328. // Remote address for datagrams
  329. ULONG TxAccm;
  330. ULONG RxAccm;
  331. // PPP configuration
  332. USHORT CallId;
  333. // Peer ID as used in GRE packet
  334. } Remote;
  335. struct {
  336. USHORT CallId;
  337. // My ID as used in GRE packet
  338. ULONG SequenceNumber;
  339. // Next GRE Sequence number to send
  340. ULONG AckNumber;
  341. // Last sent GRE Ack number
  342. } Packet;
  343. // Struct for items used in creating/processing packets
  344. ULONG MediaModeMask;
  345. // Indicates what types of Tapi calls we accept,
  346. // set by OID_TAPI_SET_DEFAULT_MEDIA_DETECTION
  347. ULONG_PTR LineStateMask;
  348. // This is the list of line states tapi is interested in.
  349. // set by OID_TAPI_SET_STATUS_MESSAGES
  350. UCHAR CallerId[MAX_PHONE_NUMBER_LENGTH];
  351. // This is the remote phone number or IP if we recieved the call,
  352. // and the IP or phone number we dialed if we placed the call.
  353. struct {
  354. NDIS_MINIPORT_TIMER Timer;
  355. BOOLEAN Expedited;
  356. BOOLEAN Scheduled;
  357. ULONG Checklist;
  358. #define CALL_CLOSE_CLEANUP_STATE BIT(0)
  359. #define CALL_CLOSE_LINE_DOWN BIT(1)
  360. #define CALL_CLOSE_DROP BIT(2)
  361. #define CALL_CLOSE_DROP_COMPLETE BIT(3)
  362. #define CALL_CLOSE_DISCONNECT BIT(4)
  363. #define CALL_CLOSE_CLOSE_CALL BIT(5)
  364. #define CALL_CLOSE_CLOSE_LINE BIT(6)
  365. #define CALL_CLOSE_RESET BIT(7)
  366. #define CALL_CLOSE_COMPLETE \
  367. (CALL_CLOSE_CLEANUP_STATE |\
  368. CALL_CLOSE_DROP |\
  369. CALL_CLOSE_DROP_COMPLETE |\
  370. CALL_CLOSE_DISCONNECT |\
  371. CALL_CLOSE_CLOSE_CALL |\
  372. CALL_CLOSE_LINE_DOWN |\
  373. CALL_CLOSE_CLOSE_LINE |\
  374. CALL_CLOSE_RESET)
  375. } Close;
  376. ULONG Speed;
  377. // Connection speed
  378. struct {
  379. NDIS_MINIPORT_TIMER Timer;
  380. BOOLEAN PacketQueued;
  381. ULONG_PTR Padding;
  382. NDIS_WAN_PACKET Packet;
  383. ULONG_PTR Padding2;
  384. UCHAR PacketBuffer[sizeof(GRE_HEADER)+sizeof(ULONG)*2];
  385. ULONG_PTR Padding3;
  386. // When we want to send just an ack, we actually create a packet of
  387. // 0 bytes out of this buffer and pass it down. This buffer is touched
  388. // out of our control, so we pad it to protect us from alpha alignment
  389. // problems.
  390. } Ack;
  391. UCHAR LineAddress[TAPI_MAX_LINE_ADDRESS_LENGTH];
  392. LONG SendCompleteRecursion;
  393. NDIS_MINIPORT_TIMER DialTimer;
  394. PPTP_DPC ReceiveDpc;
  395. BOOLEAN Receiving;
  396. struct {
  397. BOOLEAN Cleanup;
  398. UCHAR CleanupReason[80];
  399. CALL_STATE FinalState;
  400. NDIS_STATUS FinalError;
  401. ULONG Event;
  402. #define CALL_EVENT_TAPI_ANSWER BIT(0)
  403. #define CALL_EVENT_TAPI_CLOSE_CALL BIT(1)
  404. #define CALL_EVENT_TAPI_DROP BIT(2)
  405. #define CALL_EVENT_TAPI_LINE_UP BIT(3)
  406. #define CALL_EVENT_TAPI_LINE_DOWN BIT(4)
  407. #define CALL_EVENT_TAPI_GET_CALL_INFO BIT(5)
  408. #define CALL_EVENT_TAPI_MAKE_CALL BIT(6)
  409. #define CALL_EVENT_PPTP_CLEAR_REQUEST BIT(7)
  410. #define CALL_EVENT_PPTP_DISCONNECT BIT(8)
  411. #define CALL_EVENT_PPTP_OUT_REQUEST BIT(9)
  412. #define CALL_EVENT_PPTP_OUT_REPLY BIT(10)
  413. #define CALL_EVENT_TCP_DISCONNECT BIT(11)
  414. #define CALL_EVENT_TCP_NO_ANSWER BIT(12)
  415. #define CALL_EVENT_TUNNEL_ESTABLISHED BIT(13)
  416. } History;
  417. NDIS_WORK_ITEM SendWorkItem;
  418. NDIS_WORK_ITEM RecvWorkItem;
  419. #if DBG
  420. ULONG TraceIndex;
  421. UCHAR DbgTrace[64];
  422. #endif
  423. } CALL_SESSION, *PCALL_SESSION;
  424. typedef struct PPTP_ADAPTER {
  425. NDIS_HANDLE hMiniportAdapter;
  426. // NDIS context
  427. NDIS_SPIN_LOCK Lock;
  428. REFERENCE_COUNT Reference;
  429. PCALL_SESSION *pCallArray;
  430. // Array of all call sessions.
  431. // Size of array is MaxOutboundCalls+MaxInboundCalls
  432. LIST_ENTRY ControlTunnelList;
  433. // List of all active control connections.
  434. HANDLE hCtdiListen;
  435. // This is the one listening handle
  436. HANDLE hCtdiDg;
  437. // Ctdi handle for PPTP datagram sends/recvs
  438. NDIS_WAN_INFO Info;
  439. // NdisWan related info
  440. // Info.Endpoint should equal MaxOutboundCalls+MaxInboundCalls
  441. struct {
  442. ULONG DeviceIdBase;
  443. ULONG_PTR LineStateMask;
  444. // This is the list of line states tapi is interested in.
  445. // set by OID_TAPI_SET_STATUS_MESSAGES
  446. BOOLEAN Open;
  447. HTAPI_LINE hTapiLine;
  448. // Tapi's handle to the line device, for status callbacks
  449. ULONG NumActiveCalls;
  450. } Tapi;
  451. // Struct to track Tapi specific info.
  452. NDIS_MINIPORT_TIMER CleanupTimer;
  453. // FIPS structures for random data generation
  454. FIPS_FUNCTION_TABLE FipsFunctionTable;
  455. PFILE_OBJECT pFipsFileObject;
  456. PDEVICE_OBJECT pFipsDeviceObject;
  457. RC4_KEYSTRUCT Rc4KeyData;
  458. LONG lRandomCount;
  459. BOOLEAN bRekeying;
  460. } PPTP_ADAPTER, *PPPTP_ADAPTER;
  461. typedef struct {
  462. NDIS_SPIN_LOCK Lock;
  463. ULONG InboundConnectAttempts;
  464. ULONG InboundConnectComplete;
  465. ULONG OutboundConnectAttempts;
  466. ULONG OutboundConnectComplete;
  467. ULONG TunnelsMade;
  468. ULONG TunnelsAccepted;
  469. ULONG CallsMade;
  470. ULONG CallsAccepted;
  471. ULONG PacketsSent;
  472. ULONG PacketsSentComplete;
  473. ULONG PacketsSentError;
  474. ULONG PacketsReceived;
  475. ULONG PacketsRejected;
  476. ULONG PacketsMissed;
  477. ULONG ulNewCallNullTapiHandle;
  478. ULONG ulAnswerNullRequest;
  479. ULONG ulAnswerNullCall;
  480. ULONG ulAnswerNullControl;
  481. ULONG ulAnswerNullReply;
  482. ULONG ulAnswerCtlSendFail;
  483. ULONG ulAnswerNotOffering;
  484. ULONG ulDropNullRequest;
  485. ULONG ulDropNullCall;
  486. ULONG ulDropNullControl;
  487. ULONG ulDropNullPacket;
  488. ULONG ulDropCtlSendFail;
  489. ULONG ulCloseCallNullRequest;
  490. ULONG ulCloseCallNullCall;
  491. ULONG ulCleanupWorkItemFail;
  492. ULONG ulCtlAllocPacketNull;
  493. ULONG ulCtlSendFail;
  494. ULONG ulWorkItemFail;
  495. ULONG ulMemAllocFail;
  496. ULONG ulFindCallWithTapiHandle;
  497. ULONG ulIoAllocateIrpFail;
  498. ULONG ulIoBuildIrpFail;
  499. ULONG ulIoAllocateMdlFail;
  500. } COUNTERS;
  501. typedef struct {
  502. LIST_ENTRY ListEntry;
  503. PVOID pBuffer;
  504. PGRE_HEADER pGreHeader;
  505. HANDLE hCtdi;
  506. } DGRAM_CONTEXT, *PDGRAM_CONTEXT;
  507. extern PPPTP_ADAPTER pgAdapter;
  508. extern COUNTERS gCounters;
  509. /* Prototypes --------------------------------------------------------------*/
  510. PPPTP_ADAPTER
  511. AdapterAlloc(NDIS_HANDLE NdisAdapterHandle);
  512. VOID
  513. AdapterFree(PPPTP_ADAPTER pAdapter);
  514. NTSTATUS RngInit();
  515. PCALL_SESSION
  516. CallAlloc(PPPTP_ADAPTER pAdapter);
  517. VOID
  518. CallAssignSerialNumber(PCALL_SESSION pCall);
  519. VOID
  520. CallCleanup(
  521. PCALL_SESSION pCall,
  522. BOOLEAN Locked
  523. );
  524. VOID
  525. CallDetachFromAdapter(PCALL_SESSION pCall);
  526. PCALL_SESSION
  527. CallFindAndLock(
  528. IN PPPTP_ADAPTER pAdapter,
  529. IN CALL_STATE State,
  530. IN ULONG Flags
  531. );
  532. #define FIND_INCOMING BIT(0)
  533. #define FIND_OUTGOING BIT(1)
  534. VOID
  535. CallFree(PCALL_SESSION pCall);
  536. NDIS_STATUS
  537. CallEventCallClearRequest(
  538. PCALL_SESSION pCall,
  539. UNALIGNED PPTP_CALL_CLEAR_REQUEST_PACKET *pPacket,
  540. PCONTROL_TUNNEL pCtl
  541. );
  542. NDIS_STATUS
  543. CallEventCallDisconnectNotify(
  544. PCALL_SESSION pCall,
  545. UNALIGNED PPTP_CALL_DISCONNECT_NOTIFY_PACKET *pPacket
  546. );
  547. NDIS_STATUS
  548. CallEventCallInConnect(
  549. IN PCALL_SESSION pCall,
  550. IN UNALIGNED PPTP_CALL_IN_CONNECT_PACKET *pPacket
  551. );
  552. NDIS_STATUS
  553. CallEventCallInRequest(
  554. IN PPPTP_ADAPTER pAdapter,
  555. IN PCONTROL_TUNNEL pCtl,
  556. IN UNALIGNED PPTP_CALL_IN_REQUEST_PACKET *pPacket
  557. );
  558. NDIS_STATUS
  559. CallEventCallOutReply(
  560. IN PCALL_SESSION pCall,
  561. IN UNALIGNED PPTP_CALL_OUT_REPLY_PACKET *pPacket
  562. );
  563. NDIS_STATUS
  564. CallEventCallOutRequest(
  565. IN PPPTP_ADAPTER pAdapter,
  566. IN PCONTROL_TUNNEL pCtl,
  567. IN UNALIGNED PPTP_CALL_OUT_REQUEST_PACKET *pPacket
  568. );
  569. NDIS_STATUS
  570. CallEventDisconnect(
  571. PCALL_SESSION pCall
  572. );
  573. NDIS_STATUS
  574. CallEventConnectFailure(
  575. PCALL_SESSION pCall,
  576. NDIS_STATUS FailureReason
  577. );
  578. NDIS_STATUS
  579. CallEventOutboundTunnelEstablished(
  580. IN PCALL_SESSION pCall,
  581. IN NDIS_STATUS EventStatus
  582. );
  583. PCALL_SESSION FASTCALL
  584. CallGetCall(
  585. IN PPPTP_ADAPTER pAdapter,
  586. IN ULONG_PTR ulDeviceId
  587. );
  588. #define CallIsValidCall(pAdapter, id) (pAdapter->Tapi.DeviceIdBase == id ? TRUE : FALSE)
  589. #define DeviceIdToIndex(pAdapter, id) ((id)-(pAdapter)->Tapi.DeviceIdBase)
  590. #define CallGetLineCallState(State) (((ULONG)(State)<NUM_CALL_STATES) ? CallStateToLineCallStateMap[State] : LINECALLSTATE_UNKNOWN)
  591. extern ULONG CallStateToLineCallStateMap[];
  592. #define CALL_ID_INDEX_BITS 14
  593. #define CallIdToDeviceId(CallId) PptpClientSide ? ((CallId)&((1<<CALL_ID_INDEX_BITS)-1)) : ((ULONG)(CallId))
  594. NDIS_STATUS
  595. CallReceiveDatagramCallback(
  596. IN PVOID pContext,
  597. IN PTRANSPORT_ADDRESS pAddress,
  598. IN PUCHAR pBuffer,
  599. IN ULONG ulLength
  600. );
  601. NDIS_STATUS
  602. CallQueueReceivePacket(
  603. PCALL_SESSION pCall,
  604. PDGRAM_CONTEXT pDgContext
  605. );
  606. NDIS_STATUS
  607. CallQueueTransmitPacket(
  608. PCALL_SESSION pCall,
  609. PNDIS_WAN_PACKET pWanPacket
  610. );
  611. // CallQueueTransmitPacket is OS-specific and not found in COMMON directory
  612. BOOLEAN
  613. CallConnectToCtl(
  614. IN PCALL_SESSION pCall,
  615. IN PCONTROL_TUNNEL pCtl,
  616. IN BOOLEAN CallLocked
  617. );
  618. VOID
  619. CallDisconnectFromCtl(
  620. IN PCALL_SESSION pCall,
  621. IN PCONTROL_TUNNEL pCtl
  622. );
  623. NDIS_STATUS
  624. CallSetLinkInfo(
  625. PPPTP_ADAPTER pAdapter,
  626. IN PNDIS_WAN_SET_LINK_INFO pRequest
  627. );
  628. VOID
  629. CallSetState(
  630. IN PCALL_SESSION pCall,
  631. IN CALL_STATE State,
  632. IN ULONG_PTR StateParam,
  633. IN BOOLEAN Locked
  634. );
  635. VOID
  636. CallProcessPackets(
  637. PNDIS_WORK_ITEM pNdisWorkItem,
  638. PCALL_SESSION pCall
  639. );
  640. VOID
  641. CallProcessRxPackets(
  642. PNDIS_WORK_ITEM pNdisWorkItem,
  643. PCALL_SESSION pCall
  644. );
  645. #if 0
  646. VOID
  647. CallProcessRxPackets(
  648. IN PVOID SystemSpecific1,
  649. IN PVOID Context,
  650. IN PVOID SystemSpecific2,
  651. IN PVOID SystemSpecific3
  652. );
  653. #endif
  654. PCONTROL_TUNNEL
  655. CtlAlloc(
  656. PPPTP_ADAPTER pAdapter
  657. );
  658. PVOID
  659. CtlAllocPacket(
  660. PCONTROL_TUNNEL pCtl,
  661. PPTP_MESSAGE_TYPE Message
  662. );
  663. VOID
  664. CtlFree(PCONTROL_TUNNEL pCtl);
  665. VOID
  666. CtlFreePacket(
  667. PCONTROL_TUNNEL pCtl,
  668. PVOID pPacket
  669. );
  670. NDIS_STATUS
  671. CtlListen(
  672. IN PPPTP_ADAPTER pAdapter
  673. );
  674. VOID
  675. CtlCleanup(
  676. PCONTROL_TUNNEL pCtl,
  677. BOOLEAN Locked
  678. );
  679. NDIS_STATUS
  680. CtlConnectCall(
  681. IN PPPTP_ADAPTER pAdapter,
  682. IN PCALL_SESSION pCall,
  683. IN PTA_IP_ADDRESS pTargetAddress
  684. );
  685. NDIS_STATUS
  686. CtlDisconnectCall(
  687. IN PCALL_SESSION pCall
  688. );
  689. NDIS_STATUS
  690. CtlSend(
  691. IN PCONTROL_TUNNEL pCtl,
  692. IN PVOID pPacketBuffer
  693. );
  694. VOID
  695. CtlpCleanupCtls(
  696. PPPTP_ADAPTER pAdapter
  697. );
  698. #define FreeWorkItem(_pptp_item) MyMemFree((PVOID)(_pptp_item), sizeof(PPTP_WORK_ITEM))
  699. NDIS_STATUS
  700. InitThreading(
  701. IN NDIS_HANDLE hMiniportAdapter
  702. );
  703. VOID
  704. DeinitThreading();
  705. VOID
  706. InitCallLayer();
  707. VOID
  708. IpAddressToString(
  709. IN ULONG ulIpAddress,
  710. OUT CHAR* pszIpAddress );
  711. VOID
  712. MiniportHalt(
  713. IN NDIS_HANDLE MiniportAdapterContext
  714. );
  715. NDIS_STATUS
  716. MiniportInitialize(
  717. OUT PNDIS_STATUS OpenErrorStatus,
  718. OUT PUINT SelectedMediumIndex,
  719. IN PNDIS_MEDIUM MediumArray,
  720. IN UINT MediumArraySize,
  721. IN NDIS_HANDLE NdisAdapterHandle,
  722. IN NDIS_HANDLE WrapperConfigurationContext
  723. );
  724. NDIS_STATUS
  725. MiniportQueryInformation(
  726. IN NDIS_HANDLE MiniportAdapterContext,
  727. IN NDIS_OID Oid,
  728. IN PVOID InformationBuffer,
  729. IN ULONG InformationBufferLength,
  730. OUT PULONG BytesWritten,
  731. OUT PULONG BytesNeeded
  732. );
  733. NDIS_STATUS
  734. MiniportReset(
  735. OUT PBOOLEAN AddressingReset,
  736. IN NDIS_HANDLE MiniportAdapterContext
  737. );
  738. NDIS_STATUS
  739. MiniportSetInformation(
  740. IN NDIS_HANDLE MiniportAdapterContext,
  741. IN NDIS_OID Oid,
  742. IN PVOID InformationBuffer,
  743. IN ULONG InformationBufferLength,
  744. OUT PULONG BytesRead,
  745. OUT PULONG BytesNeeded
  746. );
  747. NDIS_STATUS
  748. MiniportWanSend(
  749. IN NDIS_HANDLE MiniportAdapterContext,
  750. IN NDIS_HANDLE NdisLinkHandle,
  751. IN PNDIS_WAN_PACKET WanPacket
  752. );
  753. VOID
  754. OsGetTapiLineAddress(ULONG Index, PUCHAR s, ULONG Length);
  755. VOID
  756. OsReadConfig(
  757. NDIS_HANDLE hConfig
  758. );
  759. #if 0
  760. VOID OsGetFullHostName(VOID);
  761. #endif
  762. NDIS_STATUS
  763. OsSpecificTapiGetDevCaps(
  764. ULONG_PTR ulDeviceId,
  765. IN OUT PNDIS_TAPI_GET_DEV_CAPS pRequest
  766. );
  767. extern BOOLEAN PptpInitialized;
  768. NDIS_STATUS
  769. PptpInitialize(
  770. PPPTP_ADAPTER pAdapter
  771. );
  772. NDIS_STATUS
  773. ScheduleWorkItem(
  774. WORK_PROC Callback,
  775. PVOID Context,
  776. PVOID InfoBuf,
  777. ULONG InfoBufLen
  778. );
  779. PUCHAR
  780. StringToIpAddress(
  781. IN PUCHAR pszIpAddress,
  782. IN OUT PTA_IP_ADDRESS pAddress,
  783. OUT PBOOLEAN pValidAddress
  784. );
  785. PWCHAR
  786. StringToIpAddressW(
  787. IN PWCHAR pszIpAddress,
  788. IN OUT PTA_IP_ADDRESS pAddress,
  789. OUT PBOOLEAN pValidAddress
  790. );
  791. NDIS_STATUS
  792. TapiAnswer(
  793. IN PPPTP_ADAPTER pAdapter,
  794. IN PNDIS_TAPI_ANSWER pRequest
  795. );
  796. NDIS_STATUS
  797. TapiClose(
  798. IN PPPTP_ADAPTER pAdapter,
  799. IN PNDIS_TAPI_CLOSE pRequest
  800. );
  801. NDIS_STATUS
  802. TapiCloseCall(
  803. IN PPPTP_ADAPTER pAdapter,
  804. IN PNDIS_TAPI_CLOSE_CALL pRequest
  805. );
  806. NDIS_STATUS
  807. TapiDrop(
  808. IN PPPTP_ADAPTER pAdapter,
  809. IN PNDIS_TAPI_DROP pRequest
  810. );
  811. NDIS_STATUS
  812. TapiGetAddressCaps(
  813. IN PPPTP_ADAPTER pAdapter,
  814. IN OUT PNDIS_TAPI_GET_ADDRESS_CAPS pRequest
  815. );
  816. NDIS_STATUS
  817. TapiGetAddressStatus(
  818. IN PPPTP_ADAPTER pAdapter,
  819. IN OUT PNDIS_TAPI_GET_ADDRESS_STATUS pExtIdQuery
  820. );
  821. NDIS_STATUS
  822. TapiGetCallInfo(
  823. IN PPPTP_ADAPTER pAdapter,
  824. IN OUT PNDIS_TAPI_GET_CALL_INFO pRequest,
  825. IN OUT PULONG pRequiredLength
  826. );
  827. NDIS_STATUS
  828. TapiGetCallStatus(
  829. IN PPPTP_ADAPTER pAdapter,
  830. IN OUT PNDIS_TAPI_GET_CALL_STATUS pRequest
  831. );
  832. NDIS_STATUS
  833. TapiGetDevCaps(
  834. IN PPPTP_ADAPTER pAdapter,
  835. IN OUT PNDIS_TAPI_GET_DEV_CAPS pRequest
  836. );
  837. NDIS_STATUS
  838. TapiGetExtensionId(
  839. IN PPPTP_ADAPTER pAdapter,
  840. IN OUT PNDIS_TAPI_GET_EXTENSION_ID pExtIdQuery
  841. );
  842. NDIS_STATUS
  843. TapiGetId(
  844. IN PPPTP_ADAPTER pAdapter,
  845. IN OUT PNDIS_TAPI_GET_ID pRequest
  846. );
  847. #define TapiLineHandleToId(h) ((h)&0x7fffffff)
  848. #define TapiIdToLineHandle(id) ((id)|0x80000000)
  849. #define LinkHandleToId(h) ((ULONG_PTR)(((ULONG_PTR)(h))&0x7fffffff))
  850. #define DeviceIdToLinkHandle(id) ((id)|0x80000000)
  851. VOID
  852. TapiLineDown(
  853. PCALL_SESSION pCall
  854. );
  855. VOID
  856. TapiLineUp(
  857. PCALL_SESSION pCall
  858. );
  859. NDIS_STATUS
  860. TapiMakeCall(
  861. IN PPPTP_ADAPTER pAdapter,
  862. IN OUT PNDIS_TAPI_MAKE_CALL pRequest
  863. );
  864. NDIS_STATUS
  865. TapiNegotiateExtVersion(
  866. IN PPPTP_ADAPTER pAdapter,
  867. IN OUT PNDIS_TAPI_NEGOTIATE_EXT_VERSION pExtVersion
  868. );
  869. NDIS_STATUS
  870. TapiOpen(
  871. IN PPPTP_ADAPTER pAdapter,
  872. IN OUT PNDIS_TAPI_OPEN pRequest
  873. );
  874. NDIS_STATUS
  875. TapiProviderInitialize(
  876. IN PPPTP_ADAPTER pAdapter,
  877. IN OUT PNDIS_TAPI_PROVIDER_INITIALIZE pInitData
  878. );
  879. NDIS_STATUS
  880. TapiProviderShutdown(
  881. IN PPPTP_ADAPTER pAdapter,
  882. IN OUT PNDIS_TAPI_PROVIDER_SHUTDOWN pRequest
  883. );
  884. NDIS_STATUS
  885. TapiSetDefaultMediaDetection(
  886. IN PPPTP_ADAPTER pAdapter,
  887. IN OUT PNDIS_TAPI_SET_DEFAULT_MEDIA_DETECTION pRequest
  888. );
  889. NDIS_STATUS
  890. TapiSetStatusMessages(
  891. IN PPPTP_ADAPTER pAdapter,
  892. IN OUT PNDIS_TAPI_SET_STATUS_MESSAGES pRequest
  893. );
  894. // Enum
  895. #define ENUM_SIGNATURE TAG('ENUM')
  896. typedef struct {
  897. LIST_ENTRY ListEntry;
  898. ULONG Signature;
  899. } ENUM_CONTEXT, *PENUM_CONTEXT;
  900. #define InitEnumContext(e) \
  901. { \
  902. (e)->ListEntry.Flink = (e)->ListEntry.Blink = NULL; \
  903. (e)->Signature = ENUM_SIGNATURE; \
  904. }
  905. PLIST_ENTRY FASTCALL
  906. EnumListEntry(
  907. IN PLIST_ENTRY pHead,
  908. IN PENUM_CONTEXT pEnum,
  909. IN PNDIS_SPIN_LOCK pLock
  910. );
  911. VOID
  912. EnumComplete(
  913. IN PENUM_CONTEXT pEnum,
  914. IN PNDIS_SPIN_LOCK pLock
  915. );
  916. #endif // RASPPTP_H