@netkitty/codec 1.2.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/CHANGELOG.md +159 -0
  2. package/README.md +58 -10
  3. package/README.zh-CN.md +52 -9
  4. package/dist/Codec.d.ts +3 -2
  5. package/dist/Codec.js +106 -10
  6. package/dist/abstracts/BaseHeader.d.ts +28 -2
  7. package/dist/abstracts/BaseHeader.js +132 -43
  8. package/dist/errors/CodecSchemaValidateError.d.ts +34 -1
  9. package/dist/errors/CodecSchemaValidateError.js +26 -3
  10. package/dist/headers/ADSAMS.js +2 -0
  11. package/dist/headers/AH.js +1 -0
  12. package/dist/headers/AMQP.js +2 -1
  13. package/dist/headers/ARP.js +16 -10
  14. package/dist/headers/BACnetIP.js +1 -0
  15. package/dist/headers/BGP.js +1 -0
  16. package/dist/headers/Babel.js +2 -1
  17. package/dist/headers/BitTorrent.d.ts +2 -0
  18. package/dist/headers/BitTorrent.js +4 -2
  19. package/dist/headers/C37118.js +1 -0
  20. package/dist/headers/CAPWAP.js +1 -0
  21. package/dist/headers/CDP.js +1 -1
  22. package/dist/headers/CMS.js +2 -2
  23. package/dist/headers/COTP.d.ts +2 -0
  24. package/dist/headers/COTP.js +6 -1
  25. package/dist/headers/CassandraCQL.js +1 -0
  26. package/dist/headers/Codesys.js +1 -0
  27. package/dist/headers/Collectd.js +1 -1
  28. package/dist/headers/DCCP.js +1 -0
  29. package/dist/headers/DHCPFailover.js +1 -0
  30. package/dist/headers/DNS.js +3 -3
  31. package/dist/headers/DTLS.js +1 -0
  32. package/dist/headers/Diameter.js +3 -2
  33. package/dist/headers/EAPOL.js +1 -1
  34. package/dist/headers/EIGRP.js +1 -1
  35. package/dist/headers/ENIP.js +1 -0
  36. package/dist/headers/Elasticsearch.js +1 -0
  37. package/dist/headers/EtherCAT.js +1 -0
  38. package/dist/headers/EthernetII.js +6 -0
  39. package/dist/headers/FTP.js +6 -6
  40. package/dist/headers/Finger.js +3 -3
  41. package/dist/headers/FoundationFieldbusHSE.js +1 -0
  42. package/dist/headers/GELF.js +7 -1
  43. package/dist/headers/GENEVE.js +1 -1
  44. package/dist/headers/GLBP.js +1 -1
  45. package/dist/headers/GTPU.js +1 -0
  46. package/dist/headers/GTPv2C.js +1 -0
  47. package/dist/headers/GitProtocol.js +2 -2
  48. package/dist/headers/Goose.js +20 -8
  49. package/dist/headers/Gopher.js +6 -6
  50. package/dist/headers/HARTIP.js +1 -0
  51. package/dist/headers/HSR.js +2 -0
  52. package/dist/headers/HTTP.js +6 -6
  53. package/dist/headers/HTTP2.js +1 -0
  54. package/dist/headers/ICMP.js +1 -0
  55. package/dist/headers/ICMPv6.js +1 -0
  56. package/dist/headers/IEC104_I_Frame.js +26 -3
  57. package/dist/headers/IEC104_S_Frame.js +7 -2
  58. package/dist/headers/IEC104_U_Frame.js +14 -3
  59. package/dist/headers/IEC61850SampledValues.js +2 -1
  60. package/dist/headers/IGMP.js +1 -0
  61. package/dist/headers/IMAP.js +5 -5
  62. package/dist/headers/IPFIX.js +2 -1
  63. package/dist/headers/IPv4.js +18 -1
  64. package/dist/headers/IPv6.js +1 -0
  65. package/dist/headers/IPv6HopByHopOptions.js +12 -11
  66. package/dist/headers/IRC.js +4 -4
  67. package/dist/headers/ISAKMP.js +2 -1
  68. package/dist/headers/ISCSI.js +2 -0
  69. package/dist/headers/ISIS.js +2 -1
  70. package/dist/headers/ISOSession.d.ts +2 -0
  71. package/dist/headers/ISOSession.js +14 -10
  72. package/dist/headers/Ident.js +8 -8
  73. package/dist/headers/KNXnetIP.js +1 -0
  74. package/dist/headers/Kafka.js +1 -0
  75. package/dist/headers/Kerberos.js +1 -0
  76. package/dist/headers/L2TP.js +2 -2
  77. package/dist/headers/LACP.js +1 -1
  78. package/dist/headers/LDAP.js +2 -3
  79. package/dist/headers/LDP.js +1 -0
  80. package/dist/headers/LLC.d.ts +2 -0
  81. package/dist/headers/LLC.js +2 -0
  82. package/dist/headers/LPD.js +3 -3
  83. package/dist/headers/MGCP.js +7 -7
  84. package/dist/headers/MMS.d.ts +2 -0
  85. package/dist/headers/MMS.js +10 -6
  86. package/dist/headers/MQTT.js +1 -0
  87. package/dist/headers/MQTTSN.js +1 -0
  88. package/dist/headers/MarkerProtocol.js +1 -1
  89. package/dist/headers/Megaco.js +3 -3
  90. package/dist/headers/Memcached.js +3 -2
  91. package/dist/headers/ModbusTCP.js +1 -0
  92. package/dist/headers/ModbusUDP.js +1 -0
  93. package/dist/headers/MongoDB.js +1 -0
  94. package/dist/headers/MySQL.js +1 -0
  95. package/dist/headers/NATS.js +2 -2
  96. package/dist/headers/NBDS.js +1 -0
  97. package/dist/headers/NBSS.js +1 -0
  98. package/dist/headers/NFS.js +1 -0
  99. package/dist/headers/NHRP.js +1 -0
  100. package/dist/headers/NNTP.js +6 -6
  101. package/dist/headers/NetFlowV5.js +1 -0
  102. package/dist/headers/OLSR.js +2 -1
  103. package/dist/headers/OPCUA.js +1 -0
  104. package/dist/headers/OpenFlow.js +1 -0
  105. package/dist/headers/OpenVPN.js +1 -0
  106. package/dist/headers/PCWorx.js +1 -0
  107. package/dist/headers/POP3.js +5 -5
  108. package/dist/headers/PPPoEDiscovery.js +2 -1
  109. package/dist/headers/PPPoESession.js +1 -0
  110. package/dist/headers/PPTP.js +1 -0
  111. package/dist/headers/PTP.js +1 -0
  112. package/dist/headers/PostgreSQL.js +2 -0
  113. package/dist/headers/QUIC.js +2 -0
  114. package/dist/headers/RADIUS.js +1 -0
  115. package/dist/headers/RDP.d.ts +2 -0
  116. package/dist/headers/RDP.js +4 -1
  117. package/dist/headers/RFB.js +4 -4
  118. package/dist/headers/RGoose.js +6 -1
  119. package/dist/headers/RSVP.js +3 -2
  120. package/dist/headers/RTCP.js +1 -0
  121. package/dist/headers/RTP.js +2 -1
  122. package/dist/headers/RTPS.d.ts +2 -0
  123. package/dist/headers/RTPS.js +4 -1
  124. package/dist/headers/RTSP.js +7 -7
  125. package/dist/headers/RawData.js +1 -1
  126. package/dist/headers/Redis.js +4 -4
  127. package/dist/headers/Rlogin.js +5 -5
  128. package/dist/headers/Rsync.js +2 -2
  129. package/dist/headers/S7comm.d.ts +2 -0
  130. package/dist/headers/S7comm.js +5 -1
  131. package/dist/headers/SCTP.js +2 -2
  132. package/dist/headers/SFlow.js +2 -1
  133. package/dist/headers/SIP.js +6 -6
  134. package/dist/headers/SLMP.js +1 -0
  135. package/dist/headers/SLP.js +2 -0
  136. package/dist/headers/SLPv1.js +1 -0
  137. package/dist/headers/SMB1.js +1 -0
  138. package/dist/headers/SMB2.js +1 -0
  139. package/dist/headers/SMPP.js +1 -0
  140. package/dist/headers/SMTP.js +6 -6
  141. package/dist/headers/SNAP.js +18 -5
  142. package/dist/headers/SNMP.js +4 -4
  143. package/dist/headers/SOCKS4.js +11 -5
  144. package/dist/headers/SSDP.js +7 -7
  145. package/dist/headers/SSH.js +5 -4
  146. package/dist/headers/STOMP.js +5 -5
  147. package/dist/headers/STUN.js +2 -0
  148. package/dist/headers/Skinny.js +1 -0
  149. package/dist/headers/StatsD.js +4 -4
  150. package/dist/headers/SunRPC.js +1 -0
  151. package/dist/headers/Syslog.js +2 -2
  152. package/dist/headers/TCP.js +18 -6
  153. package/dist/headers/TLS_Alert.js +23 -11
  154. package/dist/headers/TLS_ApplicationData.js +9 -4
  155. package/dist/headers/TLS_ChangeCipherSpec.js +10 -5
  156. package/dist/headers/TLS_Handshake.js +41 -26
  157. package/dist/headers/TLS_Heartbeat.js +10 -1
  158. package/dist/headers/TPKT.js +3 -1
  159. package/dist/headers/TacacsPlus.js +1 -0
  160. package/dist/headers/Telnet.js +2 -1
  161. package/dist/headers/Teredo.js +2 -2
  162. package/dist/headers/UDP.js +8 -0
  163. package/dist/headers/VLAN_802dot1Q.js +7 -0
  164. package/dist/headers/WCCP.js +1 -0
  165. package/dist/headers/WHOIS.js +3 -3
  166. package/dist/headers/WSDiscovery.js +2 -2
  167. package/dist/headers/XMPP.js +3 -3
  168. package/dist/headers/Zabbix.js +1 -0
  169. package/dist/index.d.ts +3 -3
  170. package/dist/lib/SchemaValidator.d.ts +31 -0
  171. package/dist/lib/SchemaValidator.js +137 -0
  172. package/dist/schema/ProtocolFieldJSONSchema.d.ts +4 -1
  173. package/dist/schema/ProtocolJSONSchema.d.ts +1 -1
  174. package/dist/types/CodecErrorInfo.d.ts +11 -0
  175. package/dist/types/LayerGraph.d.ts +14 -1
  176. package/package.json +2 -2
@@ -52,6 +52,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
52
52
  //Exposed read-only for analysis; the authoritative bytes are in controlField above.
53
53
  txSequence: {
54
54
  type: 'integer',
55
+ readOnly: true,
55
56
  label: 'Tx Sequence Number N(S)',
56
57
  decode: () => {
57
58
  this.instance.txSequence.setValue(this.readBytes(2, 2).readUInt16LE() >> 1);
@@ -59,6 +60,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
59
60
  },
60
61
  rxSequence: {
61
62
  type: 'integer',
63
+ readOnly: true,
62
64
  label: 'Rx Sequence Number N(R)',
63
65
  decode: () => {
64
66
  this.instance.rxSequence.setValue(this.readBytes(4, 2).readUInt16LE() >> 1);
@@ -84,7 +86,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
84
86
  }
85
87
  },
86
88
  encode: () => {
87
- const controlType = this.instance.apciType.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
89
+ const controlType = this.instance.apciType.getValue('I-Format', (nodePath) => this.recordError(nodePath, 'Not Found'));
88
90
  switch (controlType) {
89
91
  case 'I-Format':
90
92
  {
@@ -92,7 +94,12 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
92
94
  }
93
95
  break;
94
96
  default: {
95
- this.writeBits(5, 1, 7, 1, this.instance.apciType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found')));
97
+ //Not the label: the raw format bit decode stores for an illegal frame (0/1).
98
+ //It lives in the first control octet (offset 2), like the I-Format case.
99
+ const formatBit = /^[01]$/.test(`${controlType}`) ? Number(controlType) : NaN;
100
+ if (formatBit !== 0 && formatBit !== 1)
101
+ this.recordError(this.instance.apciType.getPath(), `Unknown APCI type '${controlType}', encoded as I-Format`, 'error');
102
+ this.writeBits(2, 1, 7, 1, formatBit === 1 ? 1 : 0);
96
103
  }
97
104
  }
98
105
  }
@@ -2018,7 +2025,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
2018
2025
  maximum: 1
2019
2026
  }
2020
2027
  },
2021
- required: ['address', 'SCS', 'QU', 'S_OR_E']
2028
+ required: ['address', 'DCS', 'QU', 'S_OR_E']
2022
2029
  },
2023
2030
  //步调节命令 C_RC_NA_1 = RCO
2024
2031
  {
@@ -4515,14 +4522,17 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
4515
4522
  case 46:
4516
4523
  {
4517
4524
  const DCS = this.readBits(objectOffset + 3, 1, 6, 2);
4525
+ const QU = this.readBits(objectOffset + 3, 1, 1, 5);
4518
4526
  const S_OR_E = this.readBits(objectOffset + 3, 1, 0, 1);
4519
4527
  const C_DC_NA_1 = {
4520
4528
  address: 0,
4521
4529
  DCS: 0,
4530
+ QU: 0,
4522
4531
  S_OR_E: 0
4523
4532
  };
4524
4533
  C_DC_NA_1.address = buffer.readUintBE(0, 3);
4525
4534
  C_DC_NA_1.DCS = DCS;
4535
+ C_DC_NA_1.QU = QU;
4526
4536
  C_DC_NA_1.S_OR_E = S_OR_E;
4527
4537
  IOA_arr.push(C_DC_NA_1);
4528
4538
  }
@@ -4531,14 +4541,17 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
4531
4541
  case 47:
4532
4542
  {
4533
4543
  const RCS = this.readBits(objectOffset + 3, 1, 6, 2);
4544
+ const QU = this.readBits(objectOffset + 3, 1, 1, 5);
4534
4545
  const S_OR_E = this.readBits(objectOffset + 3, 1, 0, 1);
4535
4546
  const C_RC_NA_1 = {
4536
4547
  address: 0,
4537
4548
  RCS: 0,
4549
+ QU: 0,
4538
4550
  S_OR_E: 0
4539
4551
  };
4540
4552
  C_RC_NA_1.address = buffer.readUintBE(0, 3);
4541
4553
  C_RC_NA_1.RCS = RCS;
4554
+ C_RC_NA_1.QU = QU;
4542
4555
  C_RC_NA_1.S_OR_E = S_OR_E;
4543
4556
  IOA_arr.push(C_RC_NA_1);
4544
4557
  }
@@ -4666,6 +4679,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
4666
4679
  case 59:
4667
4680
  {
4668
4681
  const DCS = this.readBits(objectOffset + 3, 1, 6, 2);
4682
+ const QU = this.readBits(objectOffset + 3, 1, 1, 5);
4669
4683
  const S_OR_E = this.readBits(objectOffset + 3, 1, 0, 1);
4670
4684
  const Milliseconds = this.readBytes(objectOffset + 4, 2).readUInt16LE();
4671
4685
  const Minutes = this.readBits(objectOffset + 6, 1, 2, 6);
@@ -4680,6 +4694,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
4680
4694
  const C_DC_TA_1 = {
4681
4695
  address: 0,
4682
4696
  DCS: 0,
4697
+ QU: 0,
4683
4698
  S_OR_E: 0,
4684
4699
  Milliseconds: 0,
4685
4700
  Minutes: 0,
@@ -4694,6 +4709,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
4694
4709
  };
4695
4710
  C_DC_TA_1.address = buffer.readUintBE(0, 3);
4696
4711
  C_DC_TA_1.DCS = DCS;
4712
+ C_DC_TA_1.QU = QU;
4697
4713
  C_DC_TA_1.S_OR_E = S_OR_E;
4698
4714
  C_DC_TA_1.Milliseconds = Milliseconds;
4699
4715
  C_DC_TA_1.Minutes = Minutes;
@@ -4712,6 +4728,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
4712
4728
  case 60:
4713
4729
  {
4714
4730
  const RCS = this.readBits(objectOffset + 3, 1, 6, 2);
4731
+ const QU = this.readBits(objectOffset + 3, 1, 1, 5);
4715
4732
  const S_OR_E = this.readBits(objectOffset + 3, 1, 0, 1);
4716
4733
  const Milliseconds = this.readBytes(objectOffset + 4, 2).readUInt16LE();
4717
4734
  const Minutes = this.readBits(objectOffset + 6, 1, 2, 6);
@@ -4726,6 +4743,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
4726
4743
  const C_RC_TA_1 = {
4727
4744
  address: 0,
4728
4745
  RCS: 0,
4746
+ QU: 0,
4729
4747
  S_OR_E: 0,
4730
4748
  Milliseconds: 0,
4731
4749
  Minutes: 0,
@@ -4740,6 +4758,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
4740
4758
  };
4741
4759
  C_RC_TA_1.address = buffer.readUintBE(0, 3);
4742
4760
  C_RC_TA_1.RCS = RCS;
4761
+ C_RC_TA_1.QU = QU;
4743
4762
  C_RC_TA_1.S_OR_E = S_OR_E;
4744
4763
  C_RC_TA_1.Milliseconds = Milliseconds;
4745
4764
  C_RC_TA_1.Minutes = Minutes;
@@ -5897,6 +5916,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
5897
5916
  buf.writeUIntLE(address_LE, 0, 3);
5898
5917
  this.writeIOAAddress(objectOffset, buf, i);
5899
5918
  this.writeBits(objectOffset + 3, 1, 6, 2, IOA_message[i - 1].DCS);
5919
+ this.writeBits(objectOffset + 3, 1, 1, 5, IOA_message[i - 1].QU ?? 0);
5900
5920
  this.writeBits(objectOffset + 3, 1, 0, 1, IOA_message[i - 1].S_OR_E);
5901
5921
  }
5902
5922
  break;
@@ -5909,6 +5929,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
5909
5929
  buf.writeUIntLE(address_LE, 0, 3);
5910
5930
  this.writeIOAAddress(objectOffset, buf, i);
5911
5931
  this.writeBits(objectOffset + 3, 1, 6, 2, IOA_message[i - 1].RCS);
5932
+ this.writeBits(objectOffset + 3, 1, 1, 5, IOA_message[i - 1].QU ?? 0);
5912
5933
  this.writeBits(objectOffset + 3, 1, 0, 1, IOA_message[i - 1].S_OR_E);
5913
5934
  }
5914
5935
  break;
@@ -5997,6 +6018,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
5997
6018
  buf.writeUIntLE(address_LE, 0, 3);
5998
6019
  this.writeIOAAddress(objectOffset, buf, i);
5999
6020
  this.writeBits(objectOffset + 3, 1, 6, 2, IOA_message[i - 1].DCS);
6021
+ this.writeBits(objectOffset + 3, 1, 1, 5, IOA_message[i - 1].QU ?? 0);
6000
6022
  this.writeBits(objectOffset + 3, 1, 0, 1, IOA_message[i - 1].S_OR_E);
6001
6023
  const Milliseconds_buffer = (0, NumberToBuffer_1.UInt16ToBuffer)(IOA_message[i - 1].Milliseconds);
6002
6024
  this.writeBytes(objectOffset + 4, (0, NumberToBuffer_1.UInt16ToBuffer)(Milliseconds_buffer.readUInt16LE()));
@@ -6020,6 +6042,7 @@ class IEC104_I_Frame extends BaseHeader_1.BaseHeader {
6020
6042
  buf.writeUIntLE(address_LE, 0, 3);
6021
6043
  this.writeIOAAddress(objectOffset, buf, i);
6022
6044
  this.writeBits(objectOffset + 3, 1, 6, 2, IOA_message[i - 1].RCS);
6045
+ this.writeBits(objectOffset + 3, 1, 1, 5, IOA_message[i - 1].QU ?? 0);
6023
6046
  this.writeBits(objectOffset + 3, 1, 0, 1, IOA_message[i - 1].S_OR_E);
6024
6047
  const Milliseconds_buffer = (0, NumberToBuffer_1.UInt16ToBuffer)(IOA_message[i - 1].Milliseconds);
6025
6048
  this.writeBytes(objectOffset + 4, (0, NumberToBuffer_1.UInt16ToBuffer)(Milliseconds_buffer.readUInt16LE()));
@@ -66,6 +66,7 @@ class IEC104_S_Frame extends BaseHeader_1.BaseHeader {
66
66
  //precisely to acknowledge this sequence number); controlField holds the authoritative bytes.
67
67
  rxSequence: {
68
68
  type: 'integer',
69
+ readOnly: true,
69
70
  label: 'Rx Sequence Number N(R)',
70
71
  decode: () => {
71
72
  this.instance.rxSequence.setValue(this.readBytes(4, 2).readUInt16LE() >> 1);
@@ -91,7 +92,7 @@ class IEC104_S_Frame extends BaseHeader_1.BaseHeader {
91
92
  }
92
93
  },
93
94
  encode: () => {
94
- const controlType = this.instance.apciType.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
95
+ const controlType = this.instance.apciType.getValue('S-Format', (nodePath) => this.recordError(nodePath, 'Not Found'));
95
96
  switch (controlType) {
96
97
  case 'S-Format':
97
98
  {
@@ -99,7 +100,11 @@ class IEC104_S_Frame extends BaseHeader_1.BaseHeader {
99
100
  }
100
101
  break;
101
102
  default: {
102
- this.writeBits(2, 1, 7, 1, this.instance.apciType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found')));
103
+ //Not the label: the raw format bit decode stores for an illegal frame (0/1).
104
+ const formatBit = /^[01]$/.test(`${controlType}`) ? Number(controlType) : NaN;
105
+ if (formatBit !== 0 && formatBit !== 1)
106
+ this.recordError(this.instance.apciType.getPath(), `Unknown APCI type '${controlType}', encoded as S-Format`, 'error');
107
+ this.writeBits(2, 1, 7, 1, formatBit === 0 ? 0 : 1);
103
108
  }
104
109
  }
105
110
  }
@@ -59,7 +59,7 @@ class IEC104_U_Frame extends BaseHeader_1.BaseHeader {
59
59
  this.instance.controlField.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(2, 4)));
60
60
  },
61
61
  encode: () => {
62
- this.writeBytes(2, (0, HexToBuffer_1.HexToBuffer)(this.instance.controlField.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'))));
62
+ this.writeBytes(2, (0, HexToBuffer_1.HexToBuffer)(this.instance.controlField.getValue('00000000', (nodePath) => this.recordError(nodePath, 'Not Found'))));
63
63
  }
64
64
  },
65
65
  apciType: {
@@ -107,7 +107,10 @@ class IEC104_U_Frame extends BaseHeader_1.BaseHeader {
107
107
  }
108
108
  },
109
109
  encode: () => {
110
- const controlType = this.instance.apciType.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
110
+ //Left out: controlField (encoded before this) is the verbatim control word; keep it.
111
+ if (this.instance.apciType.isUndefined())
112
+ return;
113
+ const controlType = this.instance.apciType.getValue('00000000');
111
114
  switch (controlType) {
112
115
  case 'U-Format Type:Test Frame Activation':
113
116
  {
@@ -140,7 +143,15 @@ class IEC104_U_Frame extends BaseHeader_1.BaseHeader {
140
143
  }
141
144
  break;
142
145
  default: {
143
- this.writeBytes(2, (0, HexToBuffer_1.HexToBuffer)(this.instance.apciType.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'))));
146
+ //Not a known label: the verbatim 4-octet control word decode stores for an
147
+ //unrecognized U-frame. Anything else cannot be encoded; keep the 4-octet framing.
148
+ if (/^[0-9a-fA-F]{8}$/.test(`${controlType}`)) {
149
+ this.writeBytes(2, (0, HexToBuffer_1.HexToBuffer)(controlType));
150
+ }
151
+ else {
152
+ this.recordError(this.instance.apciType.getPath(), `Unknown APCI type '${controlType}', control field encoded as 00000000`, 'error');
153
+ this.writeBytes(2, Buffer.alloc(4, 0));
154
+ }
144
155
  }
145
156
  }
146
157
  }
@@ -36,6 +36,7 @@ class IEC61850SampledValues extends BaseHeader_1.BaseHeader {
36
36
  },
37
37
  length: {
38
38
  type: 'integer',
39
+ autoCalculated: true,
39
40
  label: 'Length',
40
41
  decode: () => {
41
42
  this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)));
@@ -152,7 +153,7 @@ class IEC61850SampledValues extends BaseHeader_1.BaseHeader {
152
153
  properties: {
153
154
  noASDU: {
154
155
  type: 'integer',
155
- minimum: 1,
156
+ minimum: 0,
156
157
  maximum: 65535,
157
158
  label: 'Number of ASDU',
158
159
  decode: () => {
@@ -137,6 +137,7 @@ class IGMP extends BaseHeader_1.BaseHeader {
137
137
  },
138
138
  numSources: {
139
139
  type: 'integer',
140
+ autoCalculated: true,
140
141
  label: 'Number of Sources',
141
142
  minimum: 0,
142
143
  maximum: 65535,
@@ -149,11 +149,11 @@ class IMAP extends BaseHeader_1.BaseHeader {
149
149
  //message field above, never read back). kind distinguishes the four line shapes; tag is the
150
150
  //command/response tag (empty for untagged/continuation); command/status/text describe the
151
151
  //recognized tokens.
152
- kind: { type: 'string', label: 'Kind' },
153
- tag: { type: 'string', label: 'Tag' },
154
- command: { type: 'string', label: 'Command' },
155
- status: { type: 'string', label: 'Status' },
156
- text: { type: 'string', label: 'Text' }
152
+ kind: { type: 'string', label: 'Kind', readOnly: true },
153
+ tag: { type: 'string', label: 'Tag', readOnly: true },
154
+ command: { type: 'string', label: 'Command', readOnly: true },
155
+ status: { type: 'string', label: 'Status', readOnly: true },
156
+ text: { type: 'string', label: 'Text', readOnly: true }
157
157
  }
158
158
  };
159
159
  }
@@ -47,6 +47,7 @@ class IPFIX extends BaseHeader_1.BaseHeader {
47
47
  version: this.fieldUInt('version', 0, 2, 'Version'),
48
48
  length: {
49
49
  type: 'integer',
50
+ autoCalculated: true,
50
51
  label: 'Length',
51
52
  minimum: 0,
52
53
  maximum: 65535,
@@ -85,7 +86,7 @@ class IPFIX extends BaseHeader_1.BaseHeader {
85
86
  label: 'Set',
86
87
  properties: {
87
88
  setId: { type: 'integer', label: 'Set ID', minimum: 0, maximum: 65535 },
88
- setLength: { type: 'integer', label: 'Set Length', minimum: 0, maximum: 65535 },
89
+ setLength: { type: 'integer', label: 'Set Length', autoCalculated: true, minimum: 0, maximum: 65535 },
89
90
  body: { type: 'string', label: 'Body', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX }
90
91
  }
91
92
  },
@@ -77,14 +77,19 @@ class IPv4 extends BaseHeader_1.BaseHeader {
77
77
  },
78
78
  hdrLen: {
79
79
  type: 'integer',
80
+ autoCalculated: true,
80
81
  label: 'Header Length',
81
- minimum: 20,
82
+ //The field floor (IHL 0), not the protocol minimum of 20: a decoded malformed header (IHL
83
+ //1–4) must re-encode. 0 means "compute"; a value below 20 is written as given, flagged.
84
+ minimum: 0,
82
85
  maximum: 60,
83
86
  decode: function () {
84
87
  this.instance.hdrLen.setValue(this.readBits(0, 1, 4, 4) * 4);
85
88
  },
86
89
  encode: function () {
87
90
  let headerLength = this.instance.hdrLen.getValue(0);
91
+ if (headerLength && headerLength < 20)
92
+ this.recordError(this.instance.hdrLen.getPath(), 'Header length should be at least 20');
88
93
  if (headerLength)
89
94
  headerLength = headerLength ? Math.floor(headerLength / 4) : 0;
90
95
  this.writeBits(0, 1, 4, 4, headerLength);
@@ -129,6 +134,7 @@ class IPv4 extends BaseHeader_1.BaseHeader {
129
134
  },
130
135
  length: {
131
136
  type: 'integer',
137
+ autoCalculated: true,
132
138
  label: 'Total Length',
133
139
  minimum: 0,
134
140
  maximum: 65535,
@@ -261,6 +267,7 @@ class IPv4 extends BaseHeader_1.BaseHeader {
261
267
  },
262
268
  checksum: {
263
269
  type: 'integer',
270
+ autoCalculated: true,
264
271
  label: 'Header Checksum',
265
272
  minimum: 0,
266
273
  maximum: 65535,
@@ -320,6 +327,7 @@ class IPv4 extends BaseHeader_1.BaseHeader {
320
327
  },
321
328
  options: {
322
329
  type: 'string',
330
+ byteAlignment: 4,
323
331
  label: 'Options',
324
332
  minLength: 0,
325
333
  maxLength: 40 * 2,
@@ -352,6 +360,15 @@ class IPv4 extends BaseHeader_1.BaseHeader {
352
360
  match() {
353
361
  if (!this.prevCodecModule)
354
362
  return false;
363
+ //A header these fields cannot reproduce is left to raw (byte-exact) instead: IHL 0 — the encode
364
+ //"compute" sentinel, so it would come back as 5 — or fewer bytes than the header (20, or IHL×4),
365
+ //since encode always writes a whole header. IHL 1–4 is kept (it re-encodes as given).
366
+ const available = this.packet.length - this.startPos;
367
+ if (available < 20)
368
+ return false;
369
+ const ihl = this.readBytes(0, 1, true)[0] & 0x0f;
370
+ if (ihl === 0 || available < ihl * 4)
371
+ return false;
355
372
  //Normal path (unchanged): a parent that demuxed to IPv4 via its etherType field.
356
373
  if (this.prevCodecModule.instance.etherType.getValue() === (0, NumberToHex_1.UInt16ToHex)(0x0800))
357
374
  return true;
@@ -94,6 +94,7 @@ class IPv6 extends BaseHeader_1.BaseHeader {
94
94
  },
95
95
  plen: {
96
96
  type: 'integer',
97
+ autoCalculated: true,
97
98
  label: 'Payload Length',
98
99
  minimum: 0,
99
100
  maximum: 65535,
@@ -60,6 +60,7 @@ class IPv6HopByHopOptions extends BaseHeader_1.BaseHeader {
60
60
  },
61
61
  len: {
62
62
  type: 'integer',
63
+ autoCalculated: true,
63
64
  label: 'Length',
64
65
  minimum: 0,
65
66
  maximum: 255,
@@ -376,68 +377,68 @@ class IPv6HopByHopOptions extends BaseHeader_1.BaseHeader {
376
377
  case Type.PadN:
377
378
  {
378
379
  const typedItem = { ...item };
379
- parts.push(tlvBytes(new node_tlv_1.default(0x01, Buffer.alloc(typedItem.n, 0))));
380
+ parts.push(tlvBytes(new node_tlv_1.default(0x01, Buffer.alloc(typedItem.n ?? 0, 0))));
380
381
  }
381
382
  break;
382
383
  case Type.Tunnel_Encapsulation_Limit:
383
384
  {
384
385
  const typedItem = { ...item };
385
- parts.push(tlvBytes(new node_tlv_1.default(0x04, (0, NumberToBuffer_1.UInt8ToBuffer)(typedItem.limit))));
386
+ parts.push(tlvBytes(new node_tlv_1.default(0x04, (0, NumberToBuffer_1.UInt8ToBuffer)(typedItem.limit ?? 0))));
386
387
  }
387
388
  break;
388
389
  case Type.Router_Alert:
389
390
  {
390
391
  const typedItem = { ...item };
391
- parts.push(tlvBytes(new node_tlv_1.default(0x05, (0, NumberToBuffer_1.UInt16ToBuffer)((0, HexToNumber_1.HexToUInt16)(typedItem.alert)))));
392
+ parts.push(tlvBytes(new node_tlv_1.default(0x05, (0, NumberToBuffer_1.UInt16ToBuffer)((0, HexToNumber_1.HexToUInt16)(typedItem.alert ?? '0000')))));
392
393
  }
393
394
  break;
394
395
  case Type.CALIPSO:
395
396
  {
396
397
  const typedItem = { ...item };
397
- parts.push(tlvBytes(new node_tlv_1.default(0x07, (0, NumberToBuffer_1.UInt64ToBuffer)((0, HexToNumber_1.HexToUInt64)(typedItem.tag)))));
398
+ parts.push(tlvBytes(new node_tlv_1.default(0x07, (0, NumberToBuffer_1.UInt64ToBuffer)((0, HexToNumber_1.HexToUInt64)(typedItem.tag ?? '0000000000000000')))));
398
399
  }
399
400
  break;
400
401
  case Type.SMF_DPD:
401
402
  {
402
403
  const typedItem = { ...item };
403
- parts.push(tlvBytes(new node_tlv_1.default(0x08, Buffer.from(typedItem.hash, 'hex'))));
404
+ parts.push(tlvBytes(new node_tlv_1.default(0x08, Buffer.from(typedItem.hash ?? '', 'hex'))));
404
405
  }
405
406
  break;
406
407
  case Type.MPL_Option:
407
408
  {
408
409
  const typedItem = { ...item };
409
- parts.push(tlvBytes(new node_tlv_1.default(0x0B, Buffer.from(typedItem.value, 'hex'))));
410
+ parts.push(tlvBytes(new node_tlv_1.default(0x0B, Buffer.from(typedItem.value ?? '', 'hex'))));
410
411
  }
411
412
  break;
412
413
  case Type.ILNP_Nonce:
413
414
  {
414
415
  const typedItem = { ...item };
415
- parts.push(tlvBytes(new node_tlv_1.default(0x0C, Buffer.from(typedItem.nonce.padStart(12, '0'), 'hex'))));
416
+ parts.push(tlvBytes(new node_tlv_1.default(0x0C, Buffer.from((typedItem.nonce ?? '').padStart(12, '0'), 'hex'))));
416
417
  }
417
418
  break;
418
419
  case Type.Line_Identification_Option:
419
420
  {
420
421
  const typedItem = { ...item };
421
- parts.push(tlvBytes(new node_tlv_1.default(0x0D, (0, NumberToBuffer_1.UInt32ToBuffer)((0, HexToNumber_1.HexToUInt32)(typedItem.id)))));
422
+ parts.push(tlvBytes(new node_tlv_1.default(0x0D, (0, NumberToBuffer_1.UInt32ToBuffer)((0, HexToNumber_1.HexToUInt32)(typedItem.id ?? '00000000')))));
422
423
  }
423
424
  break;
424
425
  case Type.IPv6_DFF_Header:
425
426
  {
426
427
  const typedItem = { ...item };
427
- parts.push(tlvBytes(new node_tlv_1.default(0x1E, Buffer.from(typedItem.message, 'hex'))));
428
+ parts.push(tlvBytes(new node_tlv_1.default(0x1E, Buffer.from(typedItem.message ?? '', 'hex'))));
428
429
  }
429
430
  break;
430
431
  case Type.Endpoint_Identification:
431
432
  {
432
433
  const typedItem = { ...item };
433
- parts.push(tlvBytes(new node_tlv_1.default(0x8A, Buffer.from(typedItem.id.padStart(32, '0'), 'hex'))));
434
+ parts.push(tlvBytes(new node_tlv_1.default(0x8A, Buffer.from((typedItem.id ?? '').padStart(32, '0'), 'hex'))));
434
435
  }
435
436
  break;
436
437
  default: {
437
438
  if (typeof item.type !== 'number')
438
439
  return;
439
440
  const customItem = { ...item };
440
- parts.push(tlvBytes(new node_tlv_1.default(customItem.type, Buffer.from(customItem.data, 'hex'))));
441
+ parts.push(tlvBytes(new node_tlv_1.default(customItem.type, Buffer.from(customItem.data ?? '', 'hex'))));
441
442
  }
442
443
  }
443
444
  });
@@ -134,10 +134,10 @@ class IRC extends BaseHeader_1.BaseHeader {
134
134
  //message field above, never read back). prefix is the optional message source; command is
135
135
  //the verb word or numeric reply code; params is the remainder (including any :trailing);
136
136
  //isNumeric marks a 3-digit numeric reply.
137
- prefix: { type: 'string', label: 'Prefix' },
138
- command: { type: 'string', label: 'Command' },
139
- params: { type: 'string', label: 'Params' },
140
- isNumeric: { type: 'boolean', label: 'Is Numeric' }
137
+ prefix: { type: 'string', label: 'Prefix', readOnly: true },
138
+ command: { type: 'string', label: 'Command', readOnly: true },
139
+ params: { type: 'string', label: 'Params', readOnly: true },
140
+ isNumeric: { type: 'boolean', label: 'Is Numeric', readOnly: true }
141
141
  }
142
142
  };
143
143
  }
@@ -85,6 +85,7 @@ class ISAKMP extends BaseHeader_1.BaseHeader {
85
85
  messageId: this.fieldUInt('messageId', 20, 4, 'Message ID'),
86
86
  length: {
87
87
  type: 'integer',
88
+ autoCalculated: true,
88
89
  label: 'Length',
89
90
  minimum: 0,
90
91
  maximum: 4294967295,
@@ -119,7 +120,7 @@ class ISAKMP extends BaseHeader_1.BaseHeader {
119
120
  nextPayload: { type: 'integer', label: 'Next Payload', minimum: 0, maximum: 255 },
120
121
  critical: { type: 'boolean', label: 'Critical' },
121
122
  reserved: { type: 'integer', label: 'Reserved', minimum: 0, maximum: 127, hidden: true },
122
- payloadLength: { type: 'integer', label: 'Payload Length', minimum: 0, maximum: 65535 },
123
+ payloadLength: { type: 'integer', label: 'Payload Length', autoCalculated: true, minimum: 0, maximum: 65535 },
123
124
  body: { type: 'string', label: 'Body', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX }
124
125
  }
125
126
  },
@@ -181,6 +181,7 @@ class ISCSI extends BaseHeader_1.BaseHeader {
181
181
  //derived from the actual data segment length.
182
182
  dataSegmentLength: {
183
183
  type: 'integer',
184
+ autoCalculated: true,
184
185
  label: 'Data Segment Length',
185
186
  minimum: 0,
186
187
  maximum: 16777215,
@@ -244,6 +245,7 @@ class ISCSI extends BaseHeader_1.BaseHeader {
244
245
  //TCP payload so a lying DataSegmentLength can't read past the datagram.
245
246
  dataSegment: {
246
247
  type: 'string',
248
+ byteAlignment: 4,
247
249
  label: 'Data Segment',
248
250
  minLength: 0,
249
251
  contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
@@ -36,7 +36,8 @@ class ISIS extends BaseHeader_1.BaseHeader {
36
36
  type: 'object',
37
37
  summary: 'IS-IS type=${pduType}',
38
38
  properties: {
39
- irpDiscriminator: this.fieldHex('irpDiscriminator', 0, 1, 'IRP Discriminator'),
39
+ //Default 0x83: the IS-IS Intradomain Routeing Protocol Discriminator match() requires.
40
+ irpDiscriminator: { ...this.fieldHex('irpDiscriminator', 0, 1, 'IRP Discriminator'), default: '83' },
40
41
  lengthIndicator: this.fieldUInt('lengthIndicator', 1, 1, 'Length Indicator'),
41
42
  versionProtocolIdExtension: this.fieldUInt('versionProtocolIdExtension', 2, 1, 'Version/Protocol Id Extension'),
42
43
  idLength: this.fieldUInt('idLength', 3, 1, 'ID Length'),
@@ -1,4 +1,5 @@
1
1
  import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { HeuristicParent } from '../types/LayerGraph';
2
3
  import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
4
  import { DemuxProducer } from '../types/DemuxProducer';
4
5
  /**
@@ -21,6 +22,7 @@ export declare class ISOSession extends BaseHeader {
21
22
  readonly name: string;
22
23
  readonly nickname: string;
23
24
  readonly matchKeys: string[];
25
+ readonly heuristicParents: HeuristicParent[];
24
26
  readonly heuristicFallback: boolean;
25
27
  match(): boolean;
26
28
  readonly demuxProducers: DemuxProducer[];
@@ -25,6 +25,8 @@ class ISOSession extends BaseHeader_1.BaseHeader {
25
25
  this.nickname = 'ISO-SES';
26
26
  //A content-heuristic child of COTP (unkeyed), selected by a session SI at the start of the COTP payload.
27
27
  this.matchKeys = [];
28
+ //Editor graph: matched by content, so list it under these parents in allowedNextLayers().
29
+ this.heuristicParents = [{ parent: 'cotp', discriminator: { field: 'pduType', value: 0xf0 } }];
28
30
  this.heuristicFallback = true;
29
31
  //The Presentation/MMS PDU follows as a child — nothing demuxes off Session by a field value.
30
32
  this.demuxProducers = [];
@@ -223,11 +225,13 @@ class ISOSession extends BaseHeader_1.BaseHeader {
223
225
  spdus: {
224
226
  type: 'array',
225
227
  label: 'SPDUs',
228
+ //Default: Give Tokens + Data Transfer, the SPDU pair that carries MMS/ACSE data.
229
+ default: [{ si: 1, li: 0, params: '' }, { si: 1, li: 0, params: '' }],
226
230
  items: {
227
231
  type: 'object',
228
232
  properties: {
229
233
  si: { type: 'integer', label: 'SPDU Identifier', minimum: 0, maximum: 255 },
230
- li: { type: 'integer', label: 'Length Indicator', minimum: 0, maximum: 255 },
234
+ li: { type: 'integer', label: 'Length Indicator', autoCalculated: true, minimum: 0, maximum: 255 },
231
235
  params: { type: 'string', label: 'Parameters', contentEncoding: 'hex' }
232
236
  }
233
237
  },
@@ -319,15 +323,15 @@ class ISOSession extends BaseHeader_1.BaseHeader {
319
323
  //Display-only: the ACSE APDU type (AARQ/AARE/…) and application-context-name OID parsed from
320
324
  //a CONNECT/ACCEPT SPDU's user data on decode. No encode closure — the SPDU params above stay
321
325
  //the encode authority.
322
- acseType: { type: 'string', label: 'ACSE APDU' },
323
- acseAppContext: { type: 'string', label: 'ACSE Application Context' },
324
- acseCalledApTitle: { type: 'string', label: 'ACSE Called AP-Title' },
325
- acseCallingApTitle: { type: 'string', label: 'ACSE Calling AP-Title' },
326
- acseRespondingApTitle: { type: 'string', label: 'ACSE Responding AP-Title' },
327
- mmsInitMaxServOutstandingCalling: { type: 'integer', label: 'MMS Init Max Serv Outstanding Calling' },
328
- mmsInitMaxServOutstandingCalled: { type: 'integer', label: 'MMS Init Max Serv Outstanding Called' },
329
- mmsInitNestingLevel: { type: 'integer', label: 'MMS Init Data Structure Nesting Level' },
330
- mmsInitVersion: { type: 'integer', label: 'MMS Init Version' }
326
+ acseType: { type: 'string', label: 'ACSE APDU', readOnly: true },
327
+ acseAppContext: { type: 'string', label: 'ACSE Application Context', readOnly: true },
328
+ acseCalledApTitle: { type: 'string', label: 'ACSE Called AP-Title', readOnly: true },
329
+ acseCallingApTitle: { type: 'string', label: 'ACSE Calling AP-Title', readOnly: true },
330
+ acseRespondingApTitle: { type: 'string', label: 'ACSE Responding AP-Title', readOnly: true },
331
+ mmsInitMaxServOutstandingCalling: { type: 'integer', label: 'MMS Init Max Serv Outstanding Calling', readOnly: true },
332
+ mmsInitMaxServOutstandingCalled: { type: 'integer', label: 'MMS Init Max Serv Outstanding Called', readOnly: true },
333
+ mmsInitNestingLevel: { type: 'integer', label: 'MMS Init Data Structure Nesting Level', readOnly: true },
334
+ mmsInitVersion: { type: 'integer', label: 'MMS Init Version', readOnly: true }
331
335
  }
332
336
  };
333
337
  }
@@ -133,15 +133,15 @@ class Ident extends BaseHeader_1.BaseHeader {
133
133
  //`message` field below, never read back). isQuery distinguishes the client query from the
134
134
  //server reply; responseType/opsys/userId apply to a USERID reply, errorType to an ERROR
135
135
  //reply. The two ports are present in both directions.
136
- serverPort: { type: 'integer', label: 'Server Port', minimum: 0, maximum: 65535, default: 0 },
137
- clientPort: { type: 'integer', label: 'Client Port', minimum: 0, maximum: 65535, default: 0 },
138
- isQuery: { type: 'boolean', label: 'Is Query', default: false },
139
- responseType: { type: 'string', label: 'Response Type', default: '' },
140
- opsys: { type: 'string', label: 'Operating System', default: '' },
141
- userId: { type: 'string', label: 'User ID', default: '' },
142
- errorType: { type: 'string', label: 'Error Type', default: '' },
136
+ serverPort: { type: 'integer', label: 'Server Port', readOnly: true, minimum: 0, maximum: 65535, default: 0 },
137
+ clientPort: { type: 'integer', label: 'Client Port', readOnly: true, minimum: 0, maximum: 65535, default: 0 },
138
+ isQuery: { type: 'boolean', label: 'Is Query', readOnly: true, default: false },
139
+ responseType: { type: 'string', label: 'Response Type', readOnly: true, default: '' },
140
+ opsys: { type: 'string', label: 'Operating System', readOnly: true, default: '' },
141
+ userId: { type: 'string', label: 'User ID', readOnly: true, default: '' },
142
+ errorType: { type: 'string', label: 'Error Type', readOnly: true, default: '' },
143
143
  //Drives the one-line summary (query ports / USERID username / ERROR error-type).
144
- summaryInfo: { type: 'string', label: 'Summary', hidden: true, default: '' },
144
+ summaryInfo: { type: 'string', label: 'Summary', readOnly: true, hidden: true, default: '' },
145
145
  //The whole raw payload is the single source of truth: decoded verbatim to hex and
146
146
  //re-emitted untouched (byte-perfect for any Ident payload). The first line is parsed into
147
147
  //the display-only metadata above, which carry no codec of their own.
@@ -74,6 +74,7 @@ class KNXnetIP extends BaseHeader_1.BaseHeader {
74
74
  serviceType: this.fieldUInt('serviceType', 2, 2, 'Service Type'),
75
75
  totalLength: {
76
76
  type: 'integer',
77
+ autoCalculated: true,
77
78
  label: 'Total Length',
78
79
  //minimum 0 (not 6): a crafted/corrupt frame may carry a Total Length below the 6-byte
79
80
  //header, and that value must round-trip (honored verbatim) rather than be rejected by
@@ -56,6 +56,7 @@ class Kafka extends BaseHeader_1.BaseHeader {
56
56
  //as 8 (the fixed apiKey + apiVersion + correlationId header) + payload bytes.
57
57
  messageSize: {
58
58
  type: 'integer',
59
+ autoCalculated: true,
59
60
  label: 'Message Size',
60
61
  minimum: 0,
61
62
  maximum: 4294967295,