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.

236 lines
9.7 KiB

  1. /*===
  2. Direct Network Protocl -- Frame format header file
  3. Evan Schrier 10/98
  4. */
  5. /*
  6. Direct Network Protocol
  7. | MEDIA HEADER | Var Len DN Header | Client Data |
  8. There are two types of packets that may be exchanged between Direct Network
  9. endpoints:
  10. Data Packets (D Frame) User data transmission
  11. Control Packets (C Frame) Internal link-state packets with no user data
  12. */
  13. /*
  14. COMMAND FIELD
  15. The command field is the first byte of all frames. The first BIT of the command frame is always
  16. the COMMAND FRAME vs DATA FRAME opcode. The seven high bits of the Command field are flags. We have
  17. a requirement that the command field of all protocol packets must never be all zeros. Therefore, when
  18. the opcode bit is zero (COMMAND FRAME) we must be sure that one flag bit is always set. The highest flag bit,
  19. the USER2 flag is not relevant to COMMAND frames so we will always set the most significant bit when the opcode
  20. bit is zero.
  21. The seven command field flag bits are defined as follows:
  22. RELIABLE - Data delivery of this frame is guarenteed
  23. SEQUENTIAL - Data in this frame must be delivered in the order it was sent, with respect to other SEQ frames
  24. POLL - Protocol requests an immediate acknowledgement to this frame
  25. NEW MESSAGE - This frame is the first or only frame in a message
  26. END MESSAGE - This frame is the last or only frame in a message
  27. USER1 - First flag controlled by the higher layer (direct play core)
  28. USER2 - Second flag controlled by core. These flags are specified in the send API and are delivered with the data
  29. DATA FRAMES
  30. Data frames are between 4 and 20 bytes in length. They should typically be only 4 bytes. Following the
  31. Command byte in all data frames in the Control byte. This byte contains a 3-bit retry counter and 5 additional
  32. flags. The Control byte flags are defined as follows:
  33. END OF STREAM - This frame is the last data frame the transmitting partner will send.
  34. SACK_MASK_ONE - The low 32-bit Selective Acknowledgment mask is present in this header
  35. SACK_MASK_TWO - The high 32-bit Selective Acknowledgment mask is present in this header
  36. SEND_MASK_ONE - The low 32-bit Cancel Send mask is present in this header
  37. SEND_MASK_TWO - The high 32-bit Cancel Send mask is present in this header
  38. After Control byte come two one byte values: Sequence number for this frame, and Next Receive sequence number
  39. expected by this partner. After these two bytes comes zero through four bitmasks as specified by the control flags.
  40. After the bitmasks, the rest of the frame is user data to be delivered to the direct play core.
  41. */
  42. #ifndef _DNET_FRAMES_
  43. #define _DNET_FRAMES_
  44. /*
  45. Command FRAME Extended Opcodes
  46. A CFrame without an opcode is a vehicle for non-piggybacked acknowledgement
  47. information. The following sub-commands are defined at this time:
  48. SACK - Only Ack/Nack info present
  49. CONNECT - Initialize a reliable connection
  50. CONNECTED - Response to CONNECT request, or CONNECTED depending on which side of the handshake
  51. */
  52. #define FRAME_EXOPCODE_CONNECT 1
  53. #define FRAME_EXOPCODE_CONNECTED 2
  54. #define FRAME_EXOPCODE_CONNECTED_SIGNED 3
  55. #define FRAME_EXOPCODE_HARD_DISCONNECT 4
  56. #define FRAME_EXOPCODE_SACK 6
  57. // These structures are used to decode network data and so need to be packed
  58. #pragma pack(push, 1)
  59. typedef UNALIGNED struct dataframe DFRAME, *PDFRAME;
  60. typedef UNALIGNED struct cframe CFRAME, *PCFRAME;
  61. typedef UNALIGNED struct sackframe8 SACKFRAME8, *PSACKFRAME8;
  62. typedef UNALIGNED struct cframe_connectedsigned CFRAME_CONNECTEDSIGNED, * PCFRAME_CONNECTEDSIGNED;
  63. #ifndef DPNBUILD_NOMULTICAST
  64. typedef UNALIGNED struct multicastframe MCASTFRAME, *PMCASTFRAME;
  65. #endif // !DPNBUILD_NOMULTICAST
  66. typedef UNALIGNED struct coalesceheader COALESCEHEADER, *PCOALESCEHEADER;
  67. // Packet Header is common to all frame formats
  68. #define PACKET_COMMAND_DATA 0x01 // Frame contains user data
  69. #define PACKET_COMMAND_END_COALESCE 0x01 // This is the last coalesced subframe
  70. #define PACKET_COMMAND_RELIABLE 0x02 // Frame should be delivered reliably
  71. #define PACKET_COMMAND_SEQUENTIAL 0x04 // Frame should be indicated sequentially
  72. #define PACKET_COMMAND_POLL 0x08 // Partner should acknowlege immediately
  73. #define PACKET_COMMAND_COALESCE_BIG_1 0x08 // This coalesced subframe is over 255 bytes
  74. #define PACKET_COMMAND_NEW_MSG 0x10 // Data frame is first in message
  75. #define PACKET_COMMAND_COALESCE_BIG_2 0x10 // This coalesced subframe is over 511 bytes
  76. #define PACKET_COMMAND_END_MSG 0x20 // Data frame is last in message
  77. #define PACKET_COMMAND_COALESCE_BIG_3 0x20 // This coalesced subframe is over 1023 bytes
  78. #define PACKET_COMMAND_USER_1 0x40 // First user controlled flag
  79. #define PACKET_COMMAND_USER_2 0x80 // Second user controlled flag
  80. #define PACKET_COMMAND_CFRAME 0x80 // Set high-bit on command frames because first byte must never be zero
  81. #define PACKET_CONTROL_RETRY 0x01 // This flag designates this frame as a retry of a previously xmitted frame
  82. #define PACKET_CONTROL_KEEPALIVE 0x02 // Designates this frame as a keep alive frame for dx9 and onwards
  83. #define PACKET_CONTROL_CORRELATE 0x02 // For pre-dx9 this bit in a frame meant 'please send an immediate ack'
  84. #define PACKET_CONTROL_COALESCE 0x04 // This packet contains multiple coalesced packets
  85. #define PACKET_CONTROL_END_STREAM 0x08 // This packet serves as Disconnect frame.
  86. #define PACKET_CONTROL_SACK_MASK1 0x10 // The low 32-bit SACK mask is included in this frame.
  87. #define PACKET_CONTROL_SACK_MASK2 0x20 // The high 32 bit SACK mask is present
  88. #define PACKET_CONTROL_SEND_MASK1 0x40 // The low 32-bit SEND mask is included in this frame
  89. #define PACKET_CONTROL_SEND_MASK2 0x80 // The high 32-bit SEND mask is included in this frame
  90. #define PACKET_CONTROL_VARIABLE_MASKS 0xF0 // All four mask bits above
  91. // Options for signing in connected signed frames (cframe_connectedsigned::dwSigningOpts)
  92. #define PACKET_SIGNING_FAST 0x00000001 //packets over link should be fast signed
  93. #define PACKET_SIGNING_FULL 0x00000002 //packets over link should be full signed
  94. /* NEW DATA FRAMES
  95. **
  96. ** Here in the new unified world we have only two frame types! CommandFrames and DataFrames...
  97. **
  98. */
  99. struct dataframe
  100. {
  101. BYTE bCommand;
  102. BYTE bControl;
  103. BYTE bSeq;
  104. BYTE bNRcv;
  105. };
  106. /*
  107. ** COMMAND FRAMES
  108. **
  109. ** Command frames are everything that is not part of the reliable stream. This is most of the control traffic
  110. ** although some control traffic is part of the stream (keep-alive, End-of-Stream)
  111. */
  112. struct cframe
  113. {
  114. BYTE bCommand;
  115. BYTE bExtOpcode; // CFrame sub-command
  116. BYTE bMsgID; // Correlator in case ExtOpcode requires a response
  117. BYTE bRspID; // Correlator in case this is a response
  118. // For Hard Disconnects this is set to the seq # of the next dataframe that would be sent
  119. DWORD dwVersion; // Protocol version #
  120. DWORD dwSessID; // Session identifier
  121. DWORD tTimestamp; // local tick count
  122. };
  123. struct cframe_connectedsigned
  124. {
  125. //first set of members match cframe exactly
  126. BYTE bCommand;
  127. BYTE bExtOpcode; // CFrame sub-command. Always FRAME_EXOPCODE_CONNECTED_SIGNED
  128. BYTE bMsgID; // Correlator in case ExtOpcode requires a response
  129. BYTE bRspID; // Correlator in case this is a response
  130. DWORD dwVersion; // Protocol version #
  131. DWORD dwSessID; // Session identifier
  132. DWORD tTimestamp; // local tick count
  133. //additional members for cframe_signedconnected
  134. ULONGLONG ullConnectSig; // used to verify the connect sequence
  135. ULONGLONG ullSenderSecret; // secret used to sign packets by the sender of this frame
  136. ULONGLONG ullReceiverSecret; // secret that should be used to sign packets by the receiver of this frame
  137. DWORD dwSigningOpts; // used to signal the signing settings
  138. DWORD dwEchoTimestamp; // contains the original timestamp from the connect or connectsigned that
  139. // provoked this frame as a reply. Allows the receiver to calculate the RTT
  140. };
  141. /*
  142. ** Selective Acknowledgement packet format
  143. **
  144. ** When a specific acknowledgement frame is sent there may be two additional pieces
  145. ** of data included with the frame. One is a bitmask allowing selective acknowledgment
  146. ** of non-sequential frames. The other is timing information about the last frame acked
  147. ** by this ACK (NRcv - 1). Specifically, it includes the lowest Retry number that this
  148. ** node received, and the ms delay between that packets arrival and the sending of this
  149. ** Ack.
  150. */
  151. #define SACK_FLAGS_RESPONSE 0x01 // indicates that Retry and Timestamp fields are valid
  152. #define SACK_FLAGS_SACK_MASK1 0x02
  153. #define SACK_FLAGS_SACK_MASK2 0x04
  154. #define SACK_FLAGS_SEND_MASK1 0x08
  155. #define SACK_FLAGS_SEND_MASK2 0x10
  156. // First format is used when DATAGRAM_INFO flag is clear
  157. struct sackframe8
  158. {
  159. BYTE bCommand; // As above
  160. BYTE bExtOpcode; // As above
  161. BYTE bFlags; // Additional flags for sack frame
  162. BYTE bRetry;
  163. BYTE bNSeq; // Since this frame has no sequence number, this is the next Seq we will send
  164. BYTE bNRcv; // As above
  165. BYTE bReserved1; // We shipped DX8 with bad packing, so these were actually there
  166. BYTE bReserved2; // We shipped DX8 with bad packing, so these were actually there
  167. DWORD tTimestamp; // Local timestamp when packet (NRcv - 1) arrived
  168. };
  169. #ifndef DPNBUILD_NOMULTICAST
  170. struct multicastframe
  171. {
  172. DWORD dwVersion; // Protocol version #
  173. DWORD dwSessID; // Session identifier
  174. };
  175. #endif // !DPNBUILD_NOMULTICAST
  176. struct coalesceheader
  177. {
  178. BYTE bSize; // The 8 least significant bits of the size of the data for this coalesced message
  179. BYTE bCommand; // PACKET_COMMAND_XXX values
  180. };
  181. #pragma pack(pop)
  182. #endif // _DNET_FRAMES_