Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
7.0 KiB

  1. /*
  2. ** Direct Network Protocol
  3. **
  4. ** This file contains internal prototypes and global definitions.
  5. */
  6. // Protocol Version History /////////////////////////////////////////////////////////////
  7. //
  8. // 1.0 - DPlay8 original
  9. // 1.1 - Fix SACK frame bogus 2 bytes caused by bad packing (DPlay 8.1 beta period only)
  10. // 1.2 - Revert to original sack behavior with packing fixed, ie same as DPlay 8.0 (shipped in DPlay 8.1)
  11. /////////////////////////////////////////////////////////////////////////////////////////
  12. // Global Constants
  13. #define DNET_VERSION_NUMBER 0x00010002 // The current protocol version
  14. #define DELAYED_ACK_TIMEOUT 100 // Delay before sending dedicated ACK packet
  15. #define SHORT_DELAYED_ACK_TIMEOUT 20 // Delay before sending dedicated NACK packet
  16. #define DELAYED_SEND_TIMEOUT 40 // Delay before sending dedicated SEND_INFO packet
  17. #define CONNECT_DEFAULT_TIMEOUT (200) // At .1 we saw too many retries, users can set in SetCaps
  18. #define CONNECT_DEFAULT_RETRIES 14 // Users can set in SetCaps
  19. #define STANDARD_LONG_TIMEOUT_VALUE 30000
  20. #define DEFAULT_KEEPALIVE_INTERVAL 60000
  21. #define ENDPOINT_BACKGROUND_INTERVAL STANDARD_LONG_TIMEOUT_VALUE // this is really what its for...
  22. #define DPF_TIMER_LVL 9 // The level at which to spew calls into the Protocol
  23. #define DPF_CALLIN_LVL 2 // The level at which to spew calls into the Protocol
  24. #define DPF_CALLOUT_LVL 3 // The level at which to spew calls out of the Protocol
  25. #define DPF_ADAPTIVE_LVL 6 // The level at which to spew Adaptive Algorithm spew
  26. #define DPF_FRAMECNT_LVL 7 // The level at which to spew Adaptive Algorithm spew
  27. #define DPF_REFCNT_LVL 8 // The level at which to spew ref counts
  28. #define DPF_REFCNT_FINAL_LVL 5 // The level at which to spew creation and destruction ref counts
  29. // Separate ones for endpoints
  30. #define DPF_EP_REFCNT_LVL 8 // The level at which to spew ref counts
  31. #define DPF_EP_REFCNT_FINAL_LVL 2 // The level at which to spew creation and destruction ref counts
  32. #undef DPF_SUBCOMP
  33. #define DPF_SUBCOMP DN_SUBCOMP_PROTOCOL
  34. typedef void CALLBACK LPCB(UINT, UINT, DWORD, DWORD, DWORD);
  35. // Global Variable definitions
  36. extern LPFPOOL ChkPtPool;
  37. extern LPFPOOL EPDPool;
  38. extern LPFPOOL MSDPool;
  39. extern LPFPOOL FMDPool;
  40. extern LPFPOOL RCDPool;
  41. extern LPFPOOL BufPool;
  42. extern LPFPOOL MedBufPool;
  43. extern LPFPOOL BigBufPool;
  44. // Internal function prototypes
  45. VOID AbortSendsOnConnection(PEPD);
  46. ULONG WINAPI BackgroundThread(PVOID);
  47. BOOL Buf_Allocate(PVOID);
  48. VOID Buf_Get(PVOID);
  49. VOID Buf_GetMed(PVOID);
  50. VOID Buf_GetBig(PVOID);
  51. HRESULT DoCancel(PMSD, HRESULT);
  52. VOID CompleteConnect(PMSD, PSPD, PEPD, HRESULT);
  53. VOID CompleteDisconnect(PMSD pMSD, PSPD pSPD, PEPD pEPD);
  54. VOID CompleteDatagramSend(PSPD, PMSD, HRESULT);
  55. VOID CompleteReliableSend(PSPD, PMSD, HRESULT);
  56. VOID CompleteSPConnect(PMSD, PSPD, HRESULT);
  57. VOID CALLBACK ConnectRetryTimeout(PVOID, UINT, PVOID);
  58. VOID CALLBACK DelayedAckTimeout(PVOID, UINT, PVOID);
  59. VOID DisconnectConnection(PEPD);
  60. VOID DropLink(PEPD);
  61. PMSD BuildDisconnectFrame(PEPD);
  62. VOID EndPointDroppedFrame(PEPD, DWORD);
  63. VOID CALLBACK EndPointBackgroundProcess(PVOID, UINT, PVOID);
  64. VOID EnqueueMessage(PMSD, PEPD);
  65. BOOL EPD_Allocate(PVOID);
  66. VOID EPD_Free(PVOID);
  67. VOID EPD_Get(PVOID);
  68. VOID EPD_Release(PVOID);
  69. VOID FlushCheckPoints(PEPD);
  70. BOOL FMD_Allocate(PVOID);
  71. VOID FMD_Free(PVOID);
  72. VOID FMD_Get(PVOID);
  73. VOID FMD_Release(PVOID);
  74. VOID InitLinkParameters(PEPD, UINT, UINT, UINT, DWORD);
  75. PCHKPT LookupCheckPoint(PEPD, BYTE);
  76. BOOL MSD_Allocate(PVOID);
  77. VOID MSD_Free(PVOID);
  78. VOID MSD_Get(PVOID);
  79. VOID MSD_Release(PVOID);
  80. PEPD NewEndPoint(PSPD, HANDLE);
  81. VOID PerformCheckpoint(PEPD);
  82. BOOL RCD_Allocate(PVOID);
  83. VOID RCD_Free(PVOID);
  84. VOID RCD_Get(PVOID);
  85. VOID RCD_Release(PVOID);
  86. VOID ReceiveComplete(PEPD);
  87. VOID CALLBACK RetryTimeout(PVOID, UINT, PVOID);
  88. VOID CALLBACK ScheduledSend(PVOID, UINT, PVOID);
  89. VOID SendAckFrame(PEPD, BOOL, BOOL fFinalAck = FALSE);
  90. HRESULT SendCommandFrame(PEPD, BYTE, BYTE);
  91. ULONG WINAPI SendThread(PVOID);
  92. VOID ServiceCmdTraffic(PSPD);
  93. VOID ServiceEPD(PSPD, PEPD);
  94. VOID CALLBACK TimeoutSend(PVOID, UINT, PVOID);
  95. VOID UpdateEndPoint(PEPD, UINT, UINT, UINT, DWORD);
  96. VOID UpdateXmitState(PEPD, BYTE, ULONG, ULONG, DWORD);
  97. VOID RejectInvalidPacket(PEPD, BOOL);
  98. // Internal Macro definitions
  99. #define ASSERT(EXP) DNASSERT(EXP)
  100. #define Lock(P) DNEnterCriticalSection(P)
  101. #define Unlock(P) DNLeaveCriticalSection(P)
  102. #define ASSERT_SPD(PTR) ASSERT((PTR) != NULL); ASSERT((PTR)->Sign == SPD_SIGN)
  103. #define ASSERT_EPD(PTR) ASSERT((PTR) != NULL); ASSERT((PTR)->Sign == EPD_SIGN)
  104. #define ASSERT_MSD(PTR) ASSERT((PTR) != NULL); ASSERT((PTR)->Sign == MSD_SIGN)
  105. #define ASSERT_FMD(PTR) ASSERT((PTR) != NULL); ASSERT((PTR)->Sign == FMD_SIGN)
  106. #define ASSERT_RCD(PTR) ASSERT((PTR) != NULL); ASSERT((PTR)->Sign == RCD_SIGN)
  107. #define INTER_INC(PTR) InterlockedIncrement(&(PTR)->lRefCnt)
  108. #define INTER_DEC(PTR) InterlockedDecrement(&(PTR)->lRefCnt)
  109. #ifdef DEBUG
  110. BOOL LockEPD(PEPD, PCHAR);
  111. VOID ReleaseEPD(PEPD, PCHAR);
  112. VOID DecrementEPD(PEPD, PCHAR);
  113. VOID LockMSD(PMSD, PCHAR);
  114. VOID ReleaseMSD(PMSD, PCHAR);
  115. VOID DecrementMSD(PMSD, PCHAR);
  116. VOID ReleaseFMD(PFMD, PCHAR);
  117. VOID LockFMD(PFMD, PCHAR);
  118. #define LOCK_EPD(a, b) LockEPD(a, b)
  119. #define RELEASE_EPD(a, b) ReleaseEPD(a, b)
  120. #define DECREMENT_EPD(a, b) DecrementEPD(a, b)
  121. #define LOCK_MSD(a, b) LockMSD(a, b)
  122. #define RELEASE_MSD(a, b) ReleaseMSD(a, b)
  123. #define DECREMENT_MSD(a, b) DecrementMSD(a, b)
  124. #define RELEASE_FMD(a, b) ReleaseFMD(a, b)
  125. #define LOCK_FMD(a, b) LockFMD(a, b)
  126. #else // !DEBUG
  127. BOOL LockEPD(PEPD);
  128. VOID ReleaseEPD(PEPD);
  129. VOID DecrementEPD(PEPD);
  130. VOID LockMSD(PMSD);
  131. VOID ReleaseMSD(PMSD);
  132. VOID DecrementMSD(PMSD);
  133. VOID ReleaseFMD(PFMD);
  134. VOID LockFMD(PFMD);
  135. #define LOCK_EPD(a, b) LockEPD(a)
  136. #define RELEASE_EPD(a, b) ReleaseEPD(a)
  137. #define DECREMENT_EPD(a, b) DecrementEPD(a)
  138. #define LOCK_MSD(a, b) LockMSD(a)
  139. #define RELEASE_MSD(a, b) ReleaseMSD(a)
  140. #define DECREMENT_MSD(a, b) DecrementMSD(a)
  141. #define RELEASE_FMD(a, b) ReleaseFMD(a)
  142. #define LOCK_FMD(a, b) LockFMD(a)
  143. #endif // DEBUG
  144. #define LOCK_RCD(PTR) (INTER_INC(PTR))
  145. #define RELEASE_RCD(PTR) ASSERT((PTR)->lRefCnt > 0); if( INTER_DEC(PTR) == 0) { RCDPool->Release(RCDPool, (PTR)); }
  146. // This links the passed in pRcvBuff onto a local variable of the same name, and NULLs the passed in one.
  147. #define RELEASE_SP_BUFFER(PTR) if((PTR) != NULL) { (PTR)->pNext = pRcvBuff; pRcvBuff = (PTR); (PTR) = NULL;}
  148. #ifndef CONTAINING_RECORD
  149. #define CONTAINING_RECORD(address, type, field) ((type *)( \
  150. (PCHAR)(address) - \
  151. (UINT_PTR)(&((type *)0)->field)))
  152. #endif
  153. #define RIGHT_SHIFT_64(HIGH_MASK, LOW_MASK) { ((LOW_MASK) >>= 1); if((HIGH_MASK) & 1){ (LOW_MASK) |= 0x80000000; } ((HIGH_MASK) >>= 1); }
  154. #define MAX(A, B) ( (A) > (B) ? (A) : (B) )
  155. #define MIN(A, B) ( (A) < (B) ? (A) : (B) )
  156. #define ABS(A) ( (A) < 0 ? -(A) : (A) )
  157. // CONVERT TO AND FROM 16.16 FIXED POINT REPRESENTATION
  158. #define TO_FP(X) ((X) << 16)
  159. #define FP_INT(X) ((X) >> 16)