CotpHeader.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using PlcSiemens.O;
  2. using PlcSiemens.Protocol.Iso;
  3. namespace PlcSiemens.Protocol.Header
  4. {
  5. public class CotpHeader
  6. {
  7. public byte Length { get; set; } // Header length : initialized to 6 (length without params - 1)
  8. // descending classes that add values in params field must update it.
  9. public byte PduType { get; set; } // 0xE0 Connection request
  10. // 0xD0 Connection confirm
  11. // 0x80 Disconnect request
  12. // 0xDC Disconnect confirm
  13. public ushort DstRef { get; set; } // Destination reference : Always 0x0000
  14. public ushort SrcRef { get; set; } // Source reference : Always 0x0000
  15. public byte CoR { get; set; } // If the telegram is used for Connection request/Confirm,
  16. // the meaning of this field is CLASS+OPTION :
  17. // Class (High 4 bits) + Option (Low 4 bits)
  18. // Class : Always 4 (0100) but is ignored in input (RFC States this)
  19. // Option : Always 0, also this in ignored.
  20. // If the telegram is used for Disconnect request,
  21. // the meaning of this field is REASON :
  22. // 1 Congestion at TSAP
  23. // 2 Session entity not attached to TSAP
  24. // 3 Address unknown (at TCP connect time)
  25. // 128+0 Normal disconnect initiated by the session
  26. // entity.
  27. // 128+1 Remote transport entity congestion at connect
  28. // request time
  29. // 128+3 Connection negotiation failed
  30. // 128+5 Protocol Error
  31. // 128+8 Connection request refused on this network
  32. // connection
  33. // Parameter data : depending on the protocol implementation.
  34. // ISO 8073 define several type of parameters, but RFC 1006 recognizes only
  35. // TSAP related parameters and PDU size. See RFC 0983 for more details.
  36. public CoptParams Params { get; set; }
  37. /* Other params not used here, list only for completeness
  38. ACK_TIME = 0x85, 1000 0101 Acknowledge Time
  39. RES_ERROR = 0x86, 1000 0110 Residual Error Rate
  40. PRIORITY = 0x87, 1000 0111 Priority
  41. TRANSIT_DEL = 0x88, 1000 1000 Transit Delay
  42. THROUGHPUT = 0x89, 1000 1001 Throughput
  43. SEQ_NR = 0x8A, 1000 1010 Subsequence Number (in AK)
  44. REASSIGNMENT = 0x8B, 1000 1011 Reassignment Time
  45. FLOW_CNTL = 0x8C, 1000 1100 Flow Control Confirmation (in AK)
  46. TPDU_SIZE = 0xC0, 1100 0000 TPDU Size
  47. SRC_TSAP = 0xC1, 1100 0001 TSAP-ID / calling TSAP ( in CR/CC )
  48. DST_TSAP = 0xC2, 1100 0010 TSAP-ID / called TSAP
  49. CHECKSUM = 0xC3, 1100 0011 Checksum
  50. VERSION_NR = 0xC4, 1100 0100 Version Number
  51. PROTECTION = 0xC5, 1100 0101 Protection Parameters (user defined)
  52. OPT_SEL = 0xC6, 1100 0110 Additional Option Selection
  53. PROTO_CLASS = 0xC7, 1100 0111 Alternative Protocol Classes
  54. PREF_MAX_TPDU_SIZE = 0xF0, 1111 0000
  55. INACTIVITY_TIMER = 0xF2, 1111 0010
  56. ADDICC = 0xe0 1110 0000 Additional Information on Connection Clearing
  57. */
  58. public CotpHeader()
  59. {
  60. Params = new CoptParams();
  61. }
  62. public void GetByteBuffer(ByteBuffer buffer)
  63. {
  64. buffer.Push(Length);
  65. buffer.Push(PduType);
  66. buffer.Push(DstRef);
  67. buffer.Push(SrcRef);
  68. buffer.Push(CoR);
  69. Params.GetByteBuffer(buffer);
  70. }
  71. public void InitByBuffer(ByteBuffer buffer)
  72. {
  73. Length = buffer.PopByte();
  74. PduType = buffer.PopByte();
  75. DstRef = buffer.PopUshort();
  76. SrcRef = buffer.PopUshort();
  77. CoR = buffer.PopByte();
  78. Params.InitByBuffer(buffer);
  79. }
  80. }
  81. }