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.

500 lines
12 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1991 - 1999
  3. Module Name:
  4. osfpcket.hxx
  5. Abstract:
  6. This file contains the packet formats for the OSF Connection Oriented
  7. RPC protocol.
  8. Author:
  9. Michael Montague (mikemon) 23-Jul-1990
  10. Revision History:
  11. 07-Mar-1992 mikemon
  12. Added comments and cleaned it up.
  13. --*/
  14. #ifndef __OSFPCKET_HXX__
  15. #define __OSFPCKET_HXX__
  16. #define OSF_RPC_V20_VERS 5
  17. #define OSF_RPC_V20_VERS_MINOR 0
  18. typedef enum
  19. {
  20. rpc_request = 0,
  21. rpc_response = 2,
  22. rpc_fault = 3,
  23. rpc_bind = 11,
  24. rpc_bind_ack = 12,
  25. rpc_bind_nak = 13,
  26. rpc_alter_context = 14,
  27. rpc_alter_context_resp = 15,
  28. rpc_auth_3 = 16,
  29. rpc_shutdown = 17,
  30. rpc_cancel = 18,
  31. rpc_orphaned = 19,
  32. rpc_rts = 20
  33. } rpc_ptype_t;
  34. #define PFC_FIRST_FRAG 0x01
  35. #define PFC_LAST_FRAG 0x02
  36. #define PFC_PENDING_CANCEL 0x04
  37. // 0x08 reserved
  38. #define PFC_CONC_MPX 0x10
  39. #define PFC_DID_NOT_EXECUTE 0x20
  40. #define PFC_MAYBE 0x40
  41. #define PFC_OBJECT_UUID 0x80
  42. typedef struct
  43. {
  44. unsigned short length;
  45. unsigned char port_spec[1];
  46. } port_any_t;
  47. typedef unsigned short p_context_id_t;
  48. typedef struct
  49. {
  50. GUID if_uuid;
  51. unsigned long if_version;
  52. } p_syntax_id_t;
  53. typedef struct
  54. {
  55. p_context_id_t p_cont_id;
  56. unsigned char n_transfer_syn;
  57. unsigned char reserved;
  58. p_syntax_id_t abstract_syntax;
  59. p_syntax_id_t transfer_syntaxes[1];
  60. } p_cont_elem_t;
  61. typedef struct
  62. {
  63. unsigned char n_context_elem;
  64. unsigned char reserved;
  65. unsigned short reserved2;
  66. p_cont_elem_t p_cont_elem[1];
  67. } p_cont_list_t;
  68. typedef unsigned short p_cont_def_result_t;
  69. #define acceptance 0
  70. #define user_rejection 1
  71. #define provider_rejection 2
  72. typedef unsigned short p_provider_reason_t;
  73. #define reason_not_specified 0
  74. #define abstract_syntax_not_supported 1
  75. #define proposed_transfer_syntaxes_not_supported 2
  76. #define local_limit_exceeded 3
  77. typedef unsigned short p_reject_reason_t;
  78. #define reason_not_specified_reject 0
  79. #define temporary_congestion 1
  80. #define local_limit_exceeded_reject 2
  81. #define protocol_version_not_supported 4
  82. #define authentication_type_not_recognized 8
  83. #define invalid_checksum 9
  84. typedef struct
  85. {
  86. p_cont_def_result_t result;
  87. p_provider_reason_t reason;
  88. p_syntax_id_t transfer_syntax;
  89. } p_result_t;
  90. typedef struct
  91. {
  92. unsigned char n_results;
  93. unsigned char reserved;
  94. unsigned short reserved2;
  95. p_result_t p_results[1];
  96. } p_result_list_t;
  97. typedef struct
  98. {
  99. unsigned char major;
  100. unsigned char minor;
  101. } version_t;
  102. typedef version_t p_rt_version_t;
  103. typedef struct
  104. {
  105. // currently, the runtime uses only one version.
  106. // if we change that, we have to change the alignment
  107. // of the members after that so that they are still
  108. // naturally aligned
  109. unsigned char n_protocols;
  110. p_rt_version_t p_protocols[1];
  111. } p_rt_versions_supported_t;
  112. typedef struct
  113. {
  114. unsigned char rpc_vers;
  115. unsigned char rpc_vers_minor;
  116. unsigned char PTYPE;
  117. unsigned char pfc_flags;
  118. unsigned char drep[4];
  119. unsigned short frag_length;
  120. unsigned short auth_length;
  121. unsigned long call_id;
  122. } rpcconn_common;
  123. typedef struct
  124. {
  125. rpcconn_common common;
  126. unsigned short max_xmit_frag;
  127. unsigned short max_recv_frag;
  128. unsigned long assoc_group_id;
  129. } rpcconn_bind;
  130. #if defined(WIN32RPC) || defined(MAC)
  131. #pragma pack(2)
  132. #endif // WIN32RPC
  133. typedef struct
  134. {
  135. rpcconn_common common;
  136. unsigned short max_xmit_frag;
  137. unsigned short max_recv_frag;
  138. unsigned long assoc_group_id;
  139. unsigned short sec_addr_length;
  140. } rpcconn_bind_ack;
  141. #if defined(WIN32RPC) || defined(MAC)
  142. #pragma pack()
  143. #endif // WIN32RPC
  144. typedef struct
  145. {
  146. rpcconn_common common;
  147. p_reject_reason_t provider_reject_reason;
  148. p_rt_versions_supported_t versions;
  149. UUID Signature;
  150. #if defined (_WIN64)
  151. // on Win64, we need to align the buffer after
  152. // this to 16 byte boundary. That's why the padding
  153. ULONG Padding[2];
  154. #endif
  155. char buffer[1];
  156. } rpcconn_bind_nak;
  157. const size_t BindNakSizeWithoutEEInfoAndSignature = FIELD_OFFSET(rpcconn_bind_nak, Signature);
  158. const size_t BindNakSizeWithoutEEInfo = FIELD_OFFSET(rpcconn_bind_nak, buffer);
  159. extern const UUID *BindNakEEInfoSignature;
  160. inline size_t GetEEInfoSizeFromBindNakPacket (rpcconn_bind_nak *BindNak)
  161. {
  162. ASSERT (BindNak->common.frag_length > BindNakSizeWithoutEEInfo);
  163. ASSERT (RpcpMemoryCompare(&BindNak->Signature, BindNakEEInfoSignature, sizeof(UUID)) == 0);
  164. return (BindNak->common.frag_length - BindNakSizeWithoutEEInfo);
  165. }
  166. const int MinimumBindNakLength = 21;
  167. typedef struct
  168. {
  169. rpcconn_common common;
  170. unsigned char auth_type;
  171. unsigned char auth_level;
  172. #ifndef WIN32RPC
  173. unsigned short pad;
  174. #endif // WIN32RPC
  175. } rpcconn_auth3;
  176. typedef rpcconn_bind rpcconn_alter_context;
  177. typedef struct
  178. {
  179. rpcconn_common common;
  180. unsigned short max_xmit_frag;
  181. unsigned short max_recv_frag;
  182. unsigned long assoc_group_id;
  183. unsigned short sec_addr_length;
  184. unsigned short pad;
  185. } rpcconn_alter_context_resp;
  186. typedef struct
  187. {
  188. rpcconn_common common;
  189. unsigned long alloc_hint;
  190. p_context_id_t p_cont_id;
  191. unsigned short opnum;
  192. } rpcconn_request;
  193. typedef struct
  194. {
  195. rpcconn_common common;
  196. unsigned long alloc_hint;
  197. p_context_id_t p_cont_id;
  198. unsigned char alert_count;
  199. unsigned char reserved;
  200. } rpcconn_response;
  201. const unsigned char FaultEEInfoPresent = 1;
  202. typedef struct
  203. {
  204. rpcconn_common common;
  205. unsigned long alloc_hint;
  206. p_context_id_t p_cont_id;
  207. unsigned char alert_count;
  208. unsigned char reserved;
  209. unsigned long status;
  210. unsigned long reserved2;
  211. // present only if reserved & FaultEEInfoPresent
  212. // the actual length is alloc_hint - FIELD_OFFSET(rpcconn_fault, buffer)
  213. unsigned char buffer[1];
  214. } rpcconn_fault;
  215. const size_t FaultSizeWithoutEEInfo = FIELD_OFFSET(rpcconn_fault, buffer);
  216. inline size_t GetEEInfoSizeFromFaultPacket (rpcconn_fault *Fault)
  217. {
  218. ASSERT (Fault->reserved & FaultEEInfoPresent);
  219. ASSERT (Fault->alloc_hint > 0);
  220. return (Fault->alloc_hint - FaultSizeWithoutEEInfo);
  221. }
  222. typedef struct
  223. {
  224. unsigned char auth_type;
  225. unsigned char auth_level;
  226. unsigned char auth_pad_length;
  227. unsigned char auth_reserved;
  228. unsigned long auth_context_id;
  229. } sec_trailer;
  230. typedef struct tagChannelSettingCookie
  231. {
  232. char Cookie[16];
  233. } ChannelSettingCookie;
  234. #define COOKIE_SIZE_IN_BYTES 16
  235. #define MAX_IPv4_ADDRESS_SIZE 4
  236. #define MAX_IPv6_ADDRESS_SIZE (16 + 4) // address + scope_id
  237. #define MAX_ADDRESS_SIZE max(MAX_IPv4_ADDRESS_SIZE, MAX_IPv6_ADDRESS_SIZE)
  238. #define RTS_FLAG_PING 0x1
  239. #define RTS_FLAG_OTHER_CMD 0x2
  240. #define RTS_FLAG_RECYCLE_CHANNEL 0x4
  241. #define RTS_FLAG_IN_CHANNEL 0x8
  242. #define RTS_FLAG_OUT_CHANNEL 0x10
  243. #define RTS_FLAG_EOF 0x20
  244. #define RTS_FLAG_ECHO 0x40
  245. typedef enum tagClientAddressType
  246. {
  247. catIPv4 = 0,
  248. catIPv6
  249. } ClientAddressType;
  250. typedef struct tagChannelSettingClientAddress
  251. {
  252. // provide enough storage for IPv6 address. Declared in this
  253. // form to avoid general runtime dependency on transport headers
  254. // In reality this is SOCKADDR_IN for IPv4 and SOCKADDR_IN6 for
  255. // IPv6
  256. ClientAddressType AddressType;
  257. union
  258. {
  259. /*[case(catIPv4)]*/ char IPv4Address[MAX_IPv4_ADDRESS_SIZE];
  260. /*[case(catIPv6)]*/ char IPv6Address[MAX_IPv6_ADDRESS_SIZE];
  261. } u;
  262. } ChannelSettingClientAddress;
  263. typedef enum tagForwardDestinations
  264. {
  265. fdClient = 0,
  266. fdInProxy,
  267. fdServer,
  268. fdOutProxy
  269. } ForwardDestinations;
  270. typedef struct tagFlowControlAck
  271. {
  272. ULONG BytesReceived;
  273. ULONG AvailableWindow;
  274. ChannelSettingCookie ChannelCookie;
  275. } FlowControlAck;
  276. typedef enum tagTunnelSettingsCommandTypes
  277. {
  278. tsctReceiveWindowSize = 0, // 0
  279. tsctFlowControlAck, // 1
  280. tsctConnectionTimeout, // 2
  281. tsctCookie, // 3
  282. tsctChannelLifetime, // 4
  283. tsctClientKeepalive, // 5
  284. tsctVersion, // 6
  285. tsctEmpty, // 7
  286. tsctPadding, // 8
  287. tsctNANCE, // 9
  288. tsctANCE, // 10
  289. tsctClientAddress, // 11
  290. tsctAssociationGroupId, // 12
  291. tsctDestination, // 13
  292. tsctPingTrafficSentNotify // 14
  293. } TunnelSettingsCommandTypes;
  294. #define LAST_RTS_COMMAND (tsctPingTrafficSentNotify)
  295. extern const int TunnelSettingsCommandTypeSizes[];
  296. typedef struct tagTunnelSettingsCommand
  297. {
  298. unsigned long CommandType;
  299. union
  300. {
  301. /*[case(tsctReceiveWindowSize)]*/ ULONG ReceiveWindowSize;
  302. /*[case(tsctFlowControlAck)]*/ FlowControlAck Ack;
  303. /*[case(tsctConnectionTimeout)]*/ ULONG ConnectionTimeout; // in milliseconds
  304. /*[case(tsctCookie)]*/ ChannelSettingCookie Cookie;
  305. /*[case(tsctChannelLifetime)]*/ ULONG ChannelLifetime;
  306. /*[case(tsctClientKeepalive)]*/ ULONG ClientKeepalive; // in milliseconds
  307. /*[case(tsctVersion)]*/ ULONG Version;
  308. /*[case(tsctEmpty)] ; */ // empty - no operands
  309. /*[case(tsctPadding)] ; */ ULONG ConformanceCount; // in bytes
  310. /*[case(tsctNANCE)] ; */ // NANCE - negative acknowledgement for new channel
  311. // establishment - no operands
  312. /*[case(tsctANCE)] ; */ // ANCE - acknowledge new channel establishment
  313. /*[case(tsctClientAddress)]*/ ChannelSettingClientAddress ClientAddress;
  314. /*[case(tsctAssociationGroupId)]*/ ChannelSettingCookie AssociationGroupId;
  315. /*[case(tsctDestination)]*/ ULONG Destination; // actually one of ForwardDestinations
  316. /*[case(tsctPingTrafficSentNotify)]*/ ULONG PingTrafficSent; // in bytes
  317. } u;
  318. } TunnelSettingsCommand;
  319. typedef struct {
  320. rpcconn_common common;
  321. unsigned short Flags;
  322. unsigned short NumberOfSettingCommands;
  323. TunnelSettingsCommand Cmd[1]; // the actual size depends on NumberOfSettings
  324. } rpcconn_tunnel_settings;
  325. #define SIZE_OF_RTS_CMD_AND_PADDING(Command) \
  326. (TunnelSettingsCommandTypeSizes[Command] \
  327. + ConstPadN(TunnelSettingsCommandTypeSizes[Command], 4))
  328. #define MUST_RECV_FRAG_SIZE 2048
  329. #define NDR_DREP_ASCII 0x00
  330. #define NDR_DREP_EBCDIC 0x01
  331. #define NDR_DREP_CHARACTER_MASK 0x0F
  332. #define NDR_DREP_BIG_ENDIAN 0x00
  333. #define NDR_DREP_LITTLE_ENDIAN 0x10
  334. #define NDR_DREP_ENDIAN_MASK 0xF0
  335. #define NDR_DREP_IEEE 0x00
  336. #define NDR_DREP_VAX 0x01
  337. #define NDR_DREP_CRAY 0x02
  338. #define NDR_DREP_IBM 0x03
  339. #ifdef MAC
  340. #define NDR_LOCAL_CHAR_DREP NDR_DREP_ASCII
  341. #define NDR_LOCAL_INT_DREP NDR_DREP_BIG_ENDIAN
  342. #define NDR_LOCAL_FP_DREP NDR_DREP_IEEE
  343. #else
  344. #define NDR_LOCAL_CHAR_DREP NDR_DREP_ASCII
  345. #define NDR_LOCAL_INT_DREP NDR_DREP_LITTLE_ENDIAN
  346. #define NDR_LOCAL_FP_DREP NDR_DREP_IEEE
  347. #endif
  348. /*++
  349. Routine Description:
  350. This macro determines whether or not we need to do endian data
  351. conversion.
  352. Argument:
  353. drep - Supplies the four byte data representation.
  354. Return Value:
  355. A value of non-zero indicates that endian data conversion needs to
  356. be performed.
  357. --*/
  358. #define DataConvertEndian(drep) \
  359. ( (drep[0] & NDR_DREP_ENDIAN_MASK) != NDR_LOCAL_INT_DREP )
  360. /*++
  361. Routine Description:
  362. This macro determines whether or not we need to do character data
  363. conversion.
  364. Argument:
  365. drep - Supplies the four byte data representation.
  366. Return Value:
  367. A value of non-zero indicates that character data conversion needs to
  368. be performed.
  369. --*/
  370. #define DataConvertCharacter(drep) \
  371. ( (drep[0] & NDR_DREP_CHARACTER_MASK) != NDR_LOCAL_CHAR_DREP)
  372. void
  373. ConstructPacket (
  374. IN OUT rpcconn_common PAPI * Packet,
  375. IN unsigned char PacketType,
  376. IN unsigned int PacketLength
  377. );
  378. RPC_STATUS
  379. ValidatePacket (
  380. IN rpcconn_common PAPI * Packet,
  381. IN unsigned int PacketLength
  382. );
  383. void
  384. ByteSwapSyntaxId (
  385. IN p_syntax_id_t PAPI * SyntaxId
  386. );
  387. #if 0
  388. void
  389. ConvertStringEbcdicToAscii (
  390. IN unsigned char * String
  391. );
  392. #endif
  393. extern unsigned long __RPC_FAR
  394. MapToNcaStatusCode (
  395. IN RPC_STATUS RpcStatus
  396. );
  397. extern RPC_STATUS __RPC_FAR
  398. MapFromNcaStatusCode (
  399. IN unsigned long NcaStatus
  400. );
  401. #if 1
  402. #define CoAllocateBuffer(_x_) RpcAllocateBuffer((_x_))
  403. #define CoFreeBuffer(_x_) RpcFreeBuffer((_x_))
  404. #else
  405. #define CoAllocateBuffer(_x_) RpcpFarAllocate((_x_))
  406. #define CoFreeBuffer(_x_) RpcpFarFree((_x_))
  407. #endif
  408. #endif // __OSFPCKET_HXX__