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.

141 lines
5.2 KiB

  1. //--------------------------------------------------------------------
  2. // Copyright (C)1998 Microsoft Corporation, All Rights Reserved.
  3. //
  4. // byteswap.cpp
  5. //
  6. // Routines to byteswap SCEP and bFTP headers from the wire format
  7. // (which is Big-Endian) to Little-Endian (Intel) format.
  8. //
  9. // Author:
  10. //
  11. // Edward Reus (EdwardR) 02-26-98 Initial coding.
  12. //
  13. //--------------------------------------------------------------------
  14. #include "precomp.h"
  15. //--------------------------------------------------------------------
  16. // ByteSwapCommandHeader()
  17. //
  18. // A command header is a 28 byte sub-header embedded in some of the
  19. // SCEP headers.
  20. //--------------------------------------------------------------------
  21. void ByteSwapCommandHeader( COMMAND_HEADER *pCommandHeader )
  22. {
  23. pCommandHeader->Length4 = ByteSwapLong(pCommandHeader->Length4);
  24. pCommandHeader->DestPid = ByteSwapShort(pCommandHeader->DestPid);
  25. pCommandHeader->SrcPid = ByteSwapShort(pCommandHeader->SrcPid);
  26. pCommandHeader->CommandId = ByteSwapShort(pCommandHeader->CommandId);
  27. }
  28. //--------------------------------------------------------------------
  29. // ByteSwapReqHeaderShortNonFrag()
  30. //
  31. // Short non-fragmented SCEP request header.
  32. //--------------------------------------------------------------------
  33. void ByteSwapReqHeaderShortNonFrag( SCEP_REQ_HEADER_SHORT *pReqHeaderShort )
  34. {
  35. pReqHeaderShort->Length3 = ByteSwapShort(pReqHeaderShort->Length3);
  36. if (pReqHeaderShort->Length3 >= COMMAND_HEADER_SIZE)
  37. {
  38. ByteSwapCommandHeader( (COMMAND_HEADER*)pReqHeaderShort->CommandHeader );
  39. }
  40. }
  41. //--------------------------------------------------------------------
  42. // ByteSwapReqHeaderLongNonFrag()
  43. //
  44. // Long non-fragmented SCEP request header.
  45. //--------------------------------------------------------------------
  46. void ByteSwapReqHeaderLongNonFrag( SCEP_REQ_HEADER_LONG *pReqHeaderLong )
  47. {
  48. pReqHeaderLong->Length2 = ByteSwapShort(pReqHeaderLong->Length2);
  49. pReqHeaderLong->Length3 = ByteSwapShort(pReqHeaderLong->Length3);
  50. if (pReqHeaderLong->Length3 >= COMMAND_HEADER_SIZE)
  51. {
  52. ByteSwapCommandHeader( (COMMAND_HEADER*)pReqHeaderLong->CommandHeader );
  53. }
  54. }
  55. //--------------------------------------------------------------------
  56. // ByteSwapReqHeaderShortFrag()
  57. //
  58. // Short fragmented SCEP request header. SCEP PDUs can be fragmented.
  59. //
  60. // Note: In practice a short fragmented PDU will probably never
  61. // show up, but its part of the spec...
  62. //--------------------------------------------------------------------
  63. void ByteSwapReqHeaderShortFrag(
  64. SCEP_REQ_HEADER_SHORT_FRAG *pReqHeaderShortFrag )
  65. {
  66. pReqHeaderShortFrag->Length3 = ByteSwapShort(pReqHeaderShortFrag->Length3);
  67. pReqHeaderShortFrag->SequenceNo = ByteSwapLong(pReqHeaderShortFrag->SequenceNo);
  68. pReqHeaderShortFrag->RestNo = ByteSwapLong(pReqHeaderShortFrag->RestNo);
  69. if ( (pReqHeaderShortFrag->Length3 >= COMMAND_HEADER_SIZE)
  70. && (pReqHeaderShortFrag->DFlag == DFLAG_FIRST_FRAGMENT) )
  71. {
  72. ByteSwapCommandHeader( (COMMAND_HEADER*)pReqHeaderShortFrag->CommandHeader );
  73. }
  74. }
  75. //--------------------------------------------------------------------
  76. // ByteSwapReqHeaderLongFrag()
  77. //
  78. // Long fragmented SCEP request header.
  79. //--------------------------------------------------------------------
  80. void ByteSwapReqHeaderLongFrag( SCEP_REQ_HEADER_LONG_FRAG *pReqHeaderLongFrag )
  81. {
  82. pReqHeaderLongFrag->Length2 = ByteSwapShort(pReqHeaderLongFrag->Length2);
  83. pReqHeaderLongFrag->Length3 = ByteSwapShort(pReqHeaderLongFrag->Length3);
  84. pReqHeaderLongFrag->SequenceNo = ByteSwapLong(pReqHeaderLongFrag->SequenceNo);
  85. pReqHeaderLongFrag->RestNo = ByteSwapLong(pReqHeaderLongFrag->RestNo);
  86. if ( (pReqHeaderLongFrag->Length3 >= COMMAND_HEADER_SIZE)
  87. && (pReqHeaderLongFrag->DFlag == DFLAG_FIRST_FRAGMENT) )
  88. {
  89. ByteSwapCommandHeader( (COMMAND_HEADER*)pReqHeaderLongFrag->CommandHeader );
  90. }
  91. }
  92. //--------------------------------------------------------------------
  93. // ByteSwapReqHeaderShort()
  94. //
  95. //--------------------------------------------------------------------
  96. void ByteSwapReqHeaderShort( SCEP_REQ_HEADER_SHORT *pReqHeaderShort )
  97. {
  98. if ( (pReqHeaderShort->DFlag == DFLAG_SINGLE_PDU)
  99. || (pReqHeaderShort->DFlag == DFLAG_INTERRUPT)
  100. || (pReqHeaderShort->DFlag == DFLAG_CONNECT_REJECT) )
  101. {
  102. ByteSwapReqHeaderShortNonFrag( pReqHeaderShort );
  103. }
  104. else
  105. {
  106. ByteSwapReqHeaderShortFrag(
  107. (SCEP_REQ_HEADER_SHORT_FRAG*)pReqHeaderShort );
  108. }
  109. }
  110. //--------------------------------------------------------------------
  111. // ByteSwapReqHeaderLong()
  112. //
  113. //--------------------------------------------------------------------
  114. void ByteSwapReqHeaderLong( SCEP_REQ_HEADER_LONG *pReqHeaderLong )
  115. {
  116. if ( (pReqHeaderLong->DFlag == DFLAG_SINGLE_PDU)
  117. || (pReqHeaderLong->DFlag == DFLAG_INTERRUPT)
  118. || (pReqHeaderLong->DFlag == DFLAG_CONNECT_REJECT) )
  119. {
  120. ByteSwapReqHeaderLongNonFrag( pReqHeaderLong );
  121. }
  122. else
  123. {
  124. ByteSwapReqHeaderLongFrag(
  125. (SCEP_REQ_HEADER_LONG_FRAG*)pReqHeaderLong );
  126. }
  127. }