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.

221 lines
8.2 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_DISCONNECTED 4 // Used in DP8, but not anymore
  55. #define FRAME_EXOPCODE_SACK 6
  56. // These structures are used to decode network data and so need to be packed
  57. #pragma pack(push, 1)
  58. typedef UNALIGNED struct packetheader PacketHeader, *PPacketHeader;
  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 sackframe_big8 SFBIG8, *PSFBIG8;
  63. typedef UNALIGNED struct dataframe_masks DFMASKS, *PDFMASKS;
  64. typedef UNALIGNED struct dataframe_big DFBIG, *PDFBIG;
  65. // Packet Header is common to all frame formats
  66. #define PACKET_COMMAND_DATA 0x01 // Frame contains user data
  67. #define PACKET_COMMAND_RELIABLE 0x02 // Frame should be delivered reliably
  68. #define PACKET_COMMAND_SEQUENTIAL 0x04 // Frame should be indicated sequentially
  69. #define PACKET_COMMAND_POLL 0x08 // Partner should acknowlege immediately
  70. #define PACKET_COMMAND_NEW_MSG 0x10 // Data frame is first in message
  71. #define PACKET_COMMAND_END_MSG 0x20 // Data frame is last in message
  72. #define PACKET_COMMAND_USER_1 0x40 // First user controlled flag
  73. #define PACKET_COMMAND_USER_2 0x80 // Second user controlled flag
  74. #define PACKET_COMMAND_CFRAME 0x80 // Set high-bit on command frames because first byte must never be zero
  75. #define PACKET_CONTROL_RETRY 0x01 // This flag designates this frame as a retry of a previously xmitted frame
  76. #define PACKET_CONTROL_CORRELATE 0x02 // Respond to this frame with a dedicated reply
  77. #define PACKET_CONTROL_RESPONSE 0x04 // THIS IS NOT CURRENTLY IMPLEMENTED - CORR RESPONSES WILL USE DEDICATED FRAMES
  78. #define PACKET_CONTROL_END_STREAM 0x08 // This packet serves as Disconnect frame.
  79. #define PACKET_CONTROL_SACK_MASK1 0x10 // The low 32-bit SACK mask is included in this frame.
  80. #define PACKET_CONTROL_SACK_MASK2 0x20 // The high 32 bit SACK mask is present
  81. #define PACKET_CONTROL_SEND_MASK1 0x40 // The low 32-bit SEND mask is included in this frame
  82. #define PACKET_CONTROL_SEND_MASK2 0x80 // The high 32-bit SEND mask is included in this frame
  83. #define PACKET_CONTROL_VARIABLE_MASKS 0xF0 // All four mask bits above
  84. struct packetheader
  85. {
  86. BYTE bCommand;
  87. };
  88. /* NEW DATA FRAMES
  89. **
  90. ** Here in the new unified world we have only two frame types! CommandFrames and DataFrames...
  91. **
  92. */
  93. struct dataframe
  94. {
  95. BYTE bCommand;
  96. BYTE bControl;
  97. BYTE bSeq;
  98. BYTE bNRcv;
  99. };
  100. // Following the 4 byte dataframe header will be between zero and four 32-bit masks, as defined by the CONTROL flags,
  101. // representing either Specific Acks (SACK) or unreliable dropped sends (SEND MASK).
  102. struct dataframe_masks
  103. {
  104. ULONG rgMask[1]; // Zero to four 32-bit masks of either SACK info or SEND info
  105. };
  106. struct dataframe_big
  107. {
  108. BYTE bCommand;
  109. BYTE bControl;
  110. BYTE bSeq;
  111. BYTE bNRcv;
  112. ULONG rgMask[4];
  113. };
  114. /*
  115. ** COMMAND FRAMES
  116. **
  117. ** Command frames are everything that is not part of the reliable stream. This is most of the control traffic
  118. ** although some control traffic is part of the stream (keep-alive, End-of-Stream)
  119. */
  120. struct cframe
  121. {
  122. BYTE bCommand;
  123. BYTE bExtOpcode; // CFrame sub-command
  124. BYTE bMsgID; // Correlator in case ExtOpcode requires a response
  125. BYTE bRspID; // Correlator in case this is a response
  126. DWORD dwVersion; // Protocol version #
  127. DWORD dwSessID; // Session identifier
  128. DWORD tTimestamp; // local tick count
  129. };
  130. /*
  131. ** Selective Acknowledgement packet format
  132. **
  133. ** When a specific acknowledgement frame is sent there may be two additional pieces
  134. ** of data included with the frame. One is a bitmask allowing selective acknowledgment
  135. ** of non-sequential frames. The other is timing information about the last frame acked
  136. ** by this ACK (NRcv - 1). Specifically, it includes the lowest Retry number that this
  137. ** node received, and the ms delay between that packets arrival and the sending of this
  138. ** Ack.
  139. */
  140. #define SACK_FLAGS_RESPONSE 0x01 // indicates that Retry and Timestamp fields are valid
  141. #define SACK_FLAGS_SACK_MASK1 0x02
  142. #define SACK_FLAGS_SACK_MASK2 0x04
  143. #define SACK_FLAGS_SEND_MASK1 0x08
  144. #define SACK_FLAGS_SEND_MASK2 0x10
  145. // First format is used when DATAGRAM_INFO flag is clear
  146. struct sackframe8
  147. {
  148. BYTE bCommand; // As above
  149. BYTE bExtOpcode; // As above
  150. BYTE bFlags; // Additional flags for sack frame
  151. BYTE bRetry;
  152. BYTE bNSeq; // Since this frame has no sequence number, this is the next Seq we will send
  153. BYTE bNRcv; // As above
  154. BYTE bReserved1; // We shipped DX8 with bad packing, so these were actually there
  155. BYTE bReserved2; // We shipped DX8 with bad packing, so these were actually there
  156. DWORD tTimestamp; // Local timestamp when packet (NRcv - 1) arrived
  157. };
  158. struct sackframe_big8
  159. {
  160. BYTE bCommand; // As above
  161. BYTE bExtOpcode; // As above
  162. BYTE bFlags; // Additional flags for sack frame
  163. BYTE bRetry;
  164. BYTE bNSeq; // Since this frame has no sequence number, this is the next Seq we
  165. BYTE bNRcv; // As above
  166. BYTE bReserved1; // We shipped DX8 with bad packing, so these were actually there
  167. BYTE bReserved2; // We shipped DX8 with bad packing, so these were actually there
  168. DWORD tTimestamp; // Local stamp when packet arrived
  169. ULONG rgMask[4];
  170. };
  171. #pragma pack(pop)
  172. #endif