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.

285 lines
11 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. nbfhdrs.h
  5. Abstract:
  6. This module defines private structure definitions describing the layout
  7. of the NetBIOS Frames Protocol headers for the NT NBF transport
  8. provider.
  9. Author:
  10. Stephen E. Jones (stevej) 25-Oct-1989
  11. Revision History:
  12. David Beaver (dbeaver) 24-Sep-1990
  13. remove pc586 and PDI specific code; add NDIS support
  14. --*/
  15. #ifndef _NBFHDRS_
  16. #define _NBFHDRS_
  17. //
  18. // Pack these headers, as they are sent fully packed on the network.
  19. //
  20. #ifdef PACKING
  21. #ifdef __STDC__
  22. #pragma Off(Align_members)
  23. #else
  24. #pragma pack(1)
  25. #endif // def __STDC__
  26. #endif // def PACKING
  27. #define NETBIOS_SIGNATURE_1 0xef // signature in NetBIOS frames.
  28. #define NETBIOS_SIGNATURE_0 0xff // 1st byte.
  29. #define NETBIOS_SIGNATURE 0xefff
  30. //
  31. // NetBIOS Frames Protocol Command Codes.
  32. //
  33. #define NBF_CMD_ADD_GROUP_NAME_QUERY 0x00
  34. #define NBF_CMD_ADD_NAME_QUERY 0x01
  35. #define NBF_CMD_NAME_IN_CONFLICT 0x02
  36. #define NBF_CMD_STATUS_QUERY 0x03
  37. #define NBF_CMD_TERMINATE_TRACE 0x07
  38. #define NBF_CMD_DATAGRAM 0x08
  39. #define NBF_CMD_DATAGRAM_BROADCAST 0x09
  40. #define NBF_CMD_NAME_QUERY 0x0a
  41. #define NBF_CMD_ADD_NAME_RESPONSE 0x0d
  42. #define NBF_CMD_NAME_RECOGNIZED 0x0e
  43. #define NBF_CMD_STATUS_RESPONSE 0x0f
  44. #define NBF_CMD_TERMINATE_TRACE2 0x13
  45. #define NBF_CMD_DATA_ACK 0x14
  46. #define NBF_CMD_DATA_FIRST_MIDDLE 0x15
  47. #define NBF_CMD_DATA_ONLY_LAST 0x16
  48. #define NBF_CMD_SESSION_CONFIRM 0x17
  49. #define NBF_CMD_SESSION_END 0x18
  50. #define NBF_CMD_SESSION_INITIALIZE 0x19
  51. #define NBF_CMD_NO_RECEIVE 0x1a
  52. #define NBF_CMD_RECEIVE_OUTSTANDING 0x1b
  53. #define NBF_CMD_RECEIVE_CONTINUE 0x1c
  54. #define NBF_CMD_SESSION_ALIVE 0x1f
  55. //
  56. // NBF Transport Layer Header.
  57. //
  58. typedef struct _NBF_HDR_GENERIC {
  59. USHORT Length; // Length of this header in bytes.
  60. UCHAR Signature [2]; // always {0xef, 0xff} for NBF.
  61. UCHAR Command; // command code, NBF_CMD_xxx.
  62. UCHAR Data1; // optional parameter.
  63. USHORT Data2; // optional parameter.
  64. USHORT TransmitCorrelator; // transmit correlator parameter.
  65. USHORT ResponseCorrelator; // response correlator parameter.
  66. } NBF_HDR_GENERIC;
  67. typedef NBF_HDR_GENERIC UNALIGNED *PNBF_HDR_GENERIC;
  68. typedef struct _NBF_HDR_CONNECTION {
  69. USHORT Length; // length of the header in bytes (14).
  70. USHORT Signature; // always {0xef, 0xff} for NBF.
  71. UCHAR Command; // command code, NBF_CMD_xxx.
  72. UCHAR Data1; // optional parameter.
  73. UCHAR Data2Low, Data2High; // Intel-formatted DW parameter.
  74. USHORT TransmitCorrelator; // Intel-formatted DW param. (transmit correlator).
  75. USHORT ResponseCorrelator; // Intel-formatted DW param. (response correlator).
  76. UCHAR DestinationSessionNumber; // connection identifier of packet receiver.
  77. UCHAR SourceSessionNumber; // connection identifier of packet sender.
  78. } NBF_HDR_CONNECTION;
  79. typedef NBF_HDR_CONNECTION UNALIGNED *PNBF_HDR_CONNECTION;
  80. typedef struct _NBF_HDR_CONNECTIONLESS {
  81. USHORT Length; // length of the header in bytes (44).
  82. USHORT Signature; // always {0xef, 0xff} for NBF.
  83. UCHAR Command; // command code, NBF_CMD_xxx.
  84. UCHAR Data1; // optional parameter.
  85. UCHAR Data2Low, Data2High; // Intel-formatted DW parameter.
  86. USHORT TransmitCorrelator; // Intel-formatted DW param. (transmit correlator).
  87. USHORT ResponseCorrelator; // Intel-formatted DW param. (response correlator).
  88. UCHAR DestinationName [NETBIOS_NAME_LENGTH]; // name of packet receiver.
  89. UCHAR SourceName [NETBIOS_NAME_LENGTH]; // name of packet sender.
  90. } NBF_HDR_CONNECTIONLESS;
  91. typedef NBF_HDR_CONNECTIONLESS UNALIGNED *PNBF_HDR_CONNECTIONLESS;
  92. //
  93. // These macros are used to retrieve the transmit and response
  94. // correlators from an NBF_HDR_CONNECTION(LESS). The first two
  95. // are general, the second two are used when the correlators
  96. // are known to be WORD aligned.
  97. //
  98. #define TRANSMIT_CORR_A(_Hdr) ((_Hdr)->TransmitCorrelator)
  99. #define RESPONSE_CORR_A(_Hdr) ((_Hdr)->ResponseCorrelator)
  100. #ifdef _IA64_
  101. //
  102. // BUGBUG This is a workaround for a bug in the IA64 compiler version
  103. // 13.00.8837 (bug #utc_p7#15002: FE bug). When it is fixed, remove
  104. // this new version of the macros in favor of the original version,
  105. // below.
  106. //
  107. __inline
  108. USHORT UNALIGNED *
  109. TempUShortCast(
  110. IN USHORT UNALIGNED *p
  111. )
  112. {
  113. return p;
  114. }
  115. #define TRANSMIT_CORR(_Hdr) (*TempUShortCast( &(_Hdr)->TransmitCorrelator ))
  116. #define RESPONSE_CORR(_Hdr) (*TempUShortCast( &(_Hdr)->ResponseCorrelator ))
  117. #define HEADER_LENGTH(_Hdr) (*TempUShortCast( &(_Hdr)->Length ))
  118. #define HEADER_SIGNATURE(_Hdr) (*TempUShortCast( &(_Hdr)->Signature ))
  119. #else
  120. #define TRANSMIT_CORR(_Hdr) (*(USHORT UNALIGNED *)(&(_Hdr)->TransmitCorrelator))
  121. #define RESPONSE_CORR(_Hdr) (*(USHORT UNALIGNED *)(&(_Hdr)->ResponseCorrelator))
  122. #define HEADER_LENGTH(_Hdr) (*(USHORT UNALIGNED *)(&(_Hdr)->Length))
  123. #define HEADER_SIGNATURE(_Hdr) (*(USHORT UNALIGNED *)(&(_Hdr)->Signature))
  124. #endif
  125. #define HEADER_LENGTH_A(_Hdr) ((_Hdr)->Length)
  126. #define HEADER_SIGNATURE_A(_Hdr) ((_Hdr)->Signature)
  127. typedef union _NBF_HDR {
  128. NBF_HDR_GENERIC Generic;
  129. NBF_HDR_CONNECTION ConnectionOrientedFrame;
  130. NBF_HDR_CONNECTIONLESS ConnectionlessFrame;
  131. } NBF_HDR;
  132. typedef NBF_HDR UNALIGNED *PNBF_HDR;
  133. //
  134. // The following structures define I-frame, U-frame, and S-frame DLC headers.
  135. //
  136. #define DLC_SSAP_RESPONSE 0x0001 // if (ssap & DLC_SSAP_RESP), it's a response.
  137. #define DLC_SSAP_GLOBAL 0x00ff // the global SAP.
  138. #define DLC_SSAP_NULL 0x0000 // the null SAP.
  139. #define DLC_SSAP_MASK 0x00fe // mask to wipe out the response bit.
  140. #define DLC_DSAP_MASK 0x00fe // mask to wipe out the group SAP bit.
  141. #define DLC_CMD_RR 0x01 // command code for RR.
  142. #define DLC_CMD_RNR 0x05 // command code for RNR.
  143. #define DLC_CMD_REJ 0x09 // command code for REJ.
  144. #define DLC_CMD_SABME 0x6f // command code for SABME.
  145. #define DLC_CMD_DISC 0x43 // command code for DISC.
  146. #define DLC_CMD_UA 0x63 // command code for UA.
  147. #define DLC_CMD_DM 0x0f // command code for DM.
  148. #define DLC_CMD_FRMR 0x87 // command code for FRMR.
  149. #define DLC_CMD_UI 0x03 // command code for UI.
  150. #define DLC_CMD_XID 0xaf // command code for XID.
  151. #define DLC_CMD_TEST 0xe3 // command code for TEST.
  152. typedef struct _DLC_XID_INFORMATION {
  153. UCHAR FormatId; // format of this XID frame.
  154. UCHAR Info1; // first information byte.
  155. UCHAR Info2; // second information byte.
  156. } DLC_XID_INFORMATION;
  157. typedef DLC_XID_INFORMATION UNALIGNED *PDLC_XID_INFORMATION;
  158. typedef struct _DLC_TEST_INFORMATION {
  159. UCHAR Buffer [10]; // this buffer is actually arbitrarily large.
  160. } DLC_TEST_INFORMATION;
  161. typedef DLC_TEST_INFORMATION UNALIGNED *PDLC_TEST_INFORMATION;
  162. typedef struct _DLC_FRMR_INFORMATION {
  163. UCHAR Command; // format: mmmpmm11, m=modifiers, p=poll/final.
  164. UCHAR Ctrl; // control field of rejected frame.
  165. UCHAR Vs; // our next send when error was detected.
  166. UCHAR Vr; // our next receive when error was detected.
  167. UCHAR Reason; // reason for sending FRMR: 000VZYXW.
  168. } DLC_FRMR_INFORMATION;
  169. typedef DLC_FRMR_INFORMATION UNALIGNED *PDLC_FRMR_INFORMATION;
  170. typedef struct _DLC_U_FRAME {
  171. UCHAR Dsap; // Destination Service Access Point.
  172. UCHAR Ssap; // Source Service Access Point.
  173. UCHAR Command; // command code.
  174. union { // information field for FRMR, TEST, XID.
  175. DLC_XID_INFORMATION XidInfo; // XID information.
  176. DLC_TEST_INFORMATION TestInfo; // TEST information.
  177. DLC_FRMR_INFORMATION FrmrInfo; // FRMR information.
  178. NBF_HDR_CONNECTIONLESS NbfHeader; // UI frame contains NetBIOS header.
  179. } Information;
  180. } DLC_U_FRAME;
  181. typedef DLC_U_FRAME UNALIGNED *PDLC_U_FRAME;
  182. #define DLC_U_INDICATOR 0x03 // (cmd & DLC_U_IND) == DLC_U_IND --> U-frame.
  183. #define DLC_U_PF 0x10 // (cmd & DLC_U_PF) -> poll/final set.
  184. typedef struct _DLC_S_FRAME {
  185. UCHAR Dsap; // Destination Service Access Point.
  186. UCHAR Ssap; // Source Service Access Point.
  187. UCHAR Command; // RR, RNR, REJ command code.
  188. UCHAR RcvSeq; // receive seq #, bottom bit is poll/final.
  189. } DLC_S_FRAME;
  190. typedef DLC_S_FRAME UNALIGNED *PDLC_S_FRAME;
  191. #define DLC_S_PF 0x01 // (rcvseq & DLC_S_PF) means poll/final set.
  192. typedef struct _DLC_I_FRAME {
  193. UCHAR Dsap; // Destination Service Access Point.
  194. UCHAR Ssap; // Source Service Access Point.
  195. UCHAR SendSeq; // send sequence number, bottom bit 0.
  196. UCHAR RcvSeq; // rcv sequence number, bottom bit p/f.
  197. } DLC_I_FRAME;
  198. typedef DLC_I_FRAME UNALIGNED *PDLC_I_FRAME;
  199. #define DLC_I_PF 0x01 // (rcvseq & DLC_I_PF) means poll/final set.
  200. #define DLC_I_INDICATOR 0x01 // !(sndseq & DLC_I_INDICATOR) indicates I-frame.
  201. typedef struct _DLC_FRAME {
  202. UCHAR Dsap; // Destination Service Access Point.
  203. UCHAR Ssap; // Source Service Access Point.
  204. UCHAR Byte1; // command byte.
  205. } DLC_FRAME;
  206. typedef DLC_FRAME UNALIGNED *PDLC_FRAME;
  207. //
  208. // This macro builds a DLC UI-frame header.
  209. //
  210. #define NbfBuildUIFrameHeader(_Header) \
  211. { \
  212. PDLC_FRAME DlcHeader = (PDLC_FRAME)(_Header); \
  213. DlcHeader->Dsap = DSAP_NETBIOS_OVER_LLC; \
  214. DlcHeader->Ssap = DSAP_NETBIOS_OVER_LLC; \
  215. DlcHeader->Byte1 = DLC_CMD_UI; \
  216. }
  217. //
  218. // Resume previous structure packing method.
  219. //
  220. #ifdef PACKING
  221. #ifdef __STDC__
  222. #pragma Pop(Align_members)
  223. #else
  224. #pragma pack()
  225. #endif // def __STDC__
  226. #endif // def PACKING
  227. #endif // def _NBFHDRS_