@netkitty/codec 2.0.0 → 2.2.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.
- package/CHANGELOG.md +324 -0
- package/README.md +31 -7
- package/README.zh-CN.md +28 -7
- package/dist/Codec.d.ts +4 -3
- package/dist/Codec.js +48 -6
- package/dist/PacketHeaders.d.ts +2 -0
- package/dist/PacketHeaders.js +8 -4
- package/dist/abstracts/BaseHeader.d.ts +43 -0
- package/dist/abstracts/BaseHeader.js +75 -0
- package/dist/headers/AH.js +3 -2
- package/dist/headers/ARP.d.ts +3 -1
- package/dist/headers/ARP.js +8 -1
- package/dist/headers/BACnetIP.js +2 -1
- package/dist/headers/BFD.d.ts +2 -1
- package/dist/headers/BFD.js +30 -4
- package/dist/headers/BGP.js +8 -3
- package/dist/headers/Babel.js +1 -1
- package/dist/headers/C37118.d.ts +3 -2
- package/dist/headers/C37118.js +34 -15
- package/dist/headers/CDP.d.ts +3 -3
- package/dist/headers/CDP.js +46 -10
- package/dist/headers/CMS.js +25 -10
- package/dist/headers/COTP.js +2 -3
- package/dist/headers/CoAP.js +20 -2
- package/dist/headers/Codesys.js +3 -2
- package/dist/headers/DCCP.d.ts +3 -2
- package/dist/headers/DCCP.js +60 -8
- package/dist/headers/DHCP.js +2 -1
- package/dist/headers/DNP3.d.ts +12 -5
- package/dist/headers/DNP3.js +153 -18
- package/dist/headers/DTLS.js +5 -3
- package/dist/headers/Diameter.js +2 -1
- package/dist/headers/EIGRP.d.ts +3 -2
- package/dist/headers/EIGRP.js +31 -5
- package/dist/headers/Elasticsearch.js +3 -2
- package/dist/headers/EthernetII.d.ts +1 -0
- package/dist/headers/EthernetII.js +4 -0
- package/dist/headers/GELF.js +1 -0
- package/dist/headers/GENEVE.js +1 -0
- package/dist/headers/GRE.js +1 -0
- package/dist/headers/GTPv2C.js +1 -0
- package/dist/headers/Goose.d.ts +31 -7
- package/dist/headers/Goose.js +413 -172
- package/dist/headers/HARTIP.js +2 -2
- package/dist/headers/HSR.js +1 -0
- package/dist/headers/HTTP2.js +1 -0
- package/dist/headers/ICMP.js +2 -1
- package/dist/headers/ICMPv6.js +10 -16
- package/dist/headers/IEC104_I_Frame.d.ts +28 -0
- package/dist/headers/IEC104_I_Frame.js +434 -319
- package/dist/headers/IEC104_S_Frame.js +22 -4
- package/dist/headers/IEC104_U_Frame.js +24 -4
- package/dist/headers/IEC61850SampledValues.d.ts +1 -0
- package/dist/headers/IEC61850SampledValues.js +20 -5
- package/dist/headers/IGMP.d.ts +8 -7
- package/dist/headers/IGMP.js +57 -19
- package/dist/headers/IPFIX.js +3 -2
- package/dist/headers/IPv4.d.ts +1 -0
- package/dist/headers/IPv4.js +32 -23
- package/dist/headers/IPv6.d.ts +1 -0
- package/dist/headers/IPv6.js +10 -1
- package/dist/headers/IPv6HopByHopOptions.js +11 -1
- package/dist/headers/ISAKMP.js +1 -0
- package/dist/headers/KNXnetIP.js +3 -2
- package/dist/headers/Kerberos.js +1 -0
- package/dist/headers/L2TP.js +1 -0
- package/dist/headers/LACP.js +2 -1
- package/dist/headers/LDAP.js +1 -1
- package/dist/headers/LDP.js +2 -2
- package/dist/headers/LLC.js +1 -0
- package/dist/headers/MQTT.js +3 -1
- package/dist/headers/MarkerProtocol.js +2 -1
- package/dist/headers/NHRP.d.ts +1 -1
- package/dist/headers/NHRP.js +29 -4
- package/dist/headers/NetFlowV5.js +2 -1
- package/dist/headers/OPCUA.js +4 -0
- package/dist/headers/OSPF.d.ts +5 -5
- package/dist/headers/OSPF.js +98 -12
- package/dist/headers/OSPFv3.d.ts +37 -0
- package/dist/headers/OSPFv3.js +314 -0
- package/dist/headers/PIM.d.ts +3 -3
- package/dist/headers/PIM.js +55 -6
- package/dist/headers/PPPoEDiscovery.js +2 -0
- package/dist/headers/PPTP.js +2 -2
- package/dist/headers/PTP.js +5 -1
- package/dist/headers/QUIC.js +8 -3
- package/dist/headers/RDP.js +2 -0
- package/dist/headers/RGoose.js +4 -1
- package/dist/headers/RIP.js +3 -2
- package/dist/headers/RIPng.js +3 -2
- package/dist/headers/RSVP.d.ts +3 -3
- package/dist/headers/RSVP.js +56 -42
- package/dist/headers/RTCP.js +4 -2
- package/dist/headers/RTP.js +3 -2
- package/dist/headers/SCTP.d.ts +2 -2
- package/dist/headers/SCTP.js +29 -5
- package/dist/headers/SFlow.js +4 -2
- package/dist/headers/SLMP.js +2 -1
- package/dist/headers/SLP.js +2 -1
- package/dist/headers/SLPv1.js +2 -1
- package/dist/headers/SMB1.js +3 -2
- package/dist/headers/SMB2.js +3 -2
- package/dist/headers/SNAP.js +2 -2
- package/dist/headers/SNMP.js +2 -2
- package/dist/headers/STUN.js +3 -2
- package/dist/headers/SercosIII.d.ts +3 -2
- package/dist/headers/SercosIII.js +41 -5
- package/dist/headers/TCP.js +13 -58
- package/dist/headers/TLS_Alert.js +20 -2
- package/dist/headers/TLS_ApplicationData.d.ts +3 -3
- package/dist/headers/TLS_ApplicationData.js +25 -6
- package/dist/headers/TLS_ChangeCipherSpec.d.ts +2 -2
- package/dist/headers/TLS_ChangeCipherSpec.js +24 -4
- package/dist/headers/TLS_Handshake.d.ts +6 -0
- package/dist/headers/TLS_Handshake.js +67 -9
- package/dist/headers/TLS_Heartbeat.d.ts +4 -3
- package/dist/headers/TLS_Heartbeat.js +40 -7
- package/dist/headers/TPKT.js +1 -1
- package/dist/headers/TacacsPlus.js +3 -1
- package/dist/headers/Trailer.d.ts +30 -0
- package/dist/headers/Trailer.js +63 -0
- package/dist/headers/UDP.js +17 -61
- package/dist/headers/VLAN_802dot1Q.d.ts +1 -0
- package/dist/headers/VLAN_802dot1Q.js +4 -0
- package/dist/headers/VRRP.d.ts +2 -1
- package/dist/headers/VRRP.js +45 -9
- package/dist/headers/WakeOnLAN.js +2 -1
- package/dist/headers/WireGuard.js +3 -2
- package/dist/headers/Zabbix.js +2 -2
- package/dist/helper/Checksum.d.ts +15 -0
- package/dist/helper/Checksum.js +56 -0
- package/dist/helper/Crc.d.ts +18 -0
- package/dist/helper/Crc.js +58 -0
- package/dist/lib/BERElement.d.ts +51 -0
- package/dist/lib/BERElement.js +125 -0
- package/package.json +2 -2
package/dist/headers/HARTIP.js
CHANGED
|
@@ -61,8 +61,8 @@ class HARTIP extends BaseHeader_1.BaseHeader {
|
|
|
61
61
|
summary: 'HART-IP type=${messageType} id=${messageId} seq=${sequenceNumber}',
|
|
62
62
|
properties: {
|
|
63
63
|
//Protocol version — 1 for the current HART-IP specification. Kept verbatim so a crafted
|
|
64
|
-
//message with any version still round-trips.
|
|
65
|
-
version: this.fieldUInt('version', 0, 1, 'Version'),
|
|
64
|
+
//message with any version still round-trips. Default 1: what match() requires.
|
|
65
|
+
version: { ...this.fieldUInt('version', 0, 1, 'Version'), default: 1 },
|
|
66
66
|
//0 Request, 1 Response, 2 Publish/Notify, 3 NAK. Kept as a plain clamped byte (not an Ajv
|
|
67
67
|
//enum) so any non-conformant / crafted value decoded from the wire still re-encodes
|
|
68
68
|
//without throwing — decode never fails and encode is a faithful executor.
|
package/dist/headers/HSR.js
CHANGED
package/dist/headers/HTTP2.js
CHANGED
|
@@ -61,6 +61,7 @@ class HTTP2 extends BaseHeader_1.BaseHeader {
|
|
|
61
61
|
//The 24-byte connection preface, kept verbatim. match() requires it, so it is always
|
|
62
62
|
//present on decode; the default lets a crafted frame re-emit the standard preface.
|
|
63
63
|
preface: {
|
|
64
|
+
default: HTTP2.#PREFACE_HEX,
|
|
64
65
|
type: 'string',
|
|
65
66
|
label: 'Connection Preface',
|
|
66
67
|
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
package/dist/headers/ICMP.js
CHANGED
|
@@ -50,10 +50,11 @@ class ICMP extends BaseHeader_1.BaseHeader {
|
|
|
50
50
|
this.instance.checksum.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)));
|
|
51
51
|
},
|
|
52
52
|
encode: () => {
|
|
53
|
+
const leftOut = this.isLeftOut(this.instance.checksum);
|
|
53
54
|
let checksum = this.instance.checksum.getValue(0);
|
|
54
55
|
this.instance.checksum.setValue(checksum);
|
|
55
56
|
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
56
|
-
if (
|
|
57
|
+
if (leftOut) {
|
|
57
58
|
checksum = this.calculateIcmpChecksum();
|
|
58
59
|
this.instance.checksum.setValue(checksum);
|
|
59
60
|
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
package/dist/headers/ICMPv6.js
CHANGED
|
@@ -6,7 +6,6 @@ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
|
6
6
|
const BufferToNumber_1 = require("../helper/BufferToNumber");
|
|
7
7
|
const NumberToBuffer_1 = require("../helper/NumberToBuffer");
|
|
8
8
|
const BufferToHex_1 = require("../helper/BufferToHex");
|
|
9
|
-
const IPToBuffer_1 = require("../helper/IPToBuffer");
|
|
10
9
|
class ICMPv6 extends BaseHeader_1.BaseHeader {
|
|
11
10
|
constructor() {
|
|
12
11
|
super(...arguments);
|
|
@@ -51,10 +50,11 @@ class ICMPv6 extends BaseHeader_1.BaseHeader {
|
|
|
51
50
|
this.instance.checksum.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)));
|
|
52
51
|
},
|
|
53
52
|
encode: () => {
|
|
53
|
+
const leftOut = this.isLeftOut(this.instance.checksum);
|
|
54
54
|
let checksum = this.instance.checksum.getValue(0);
|
|
55
55
|
this.instance.checksum.setValue(checksum);
|
|
56
56
|
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
57
|
-
if (
|
|
57
|
+
if (leftOut) {
|
|
58
58
|
checksum = this.calculateIcmpv6Checksum();
|
|
59
59
|
this.instance.checksum.setValue(checksum);
|
|
60
60
|
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
@@ -87,21 +87,15 @@ class ICMPv6 extends BaseHeader_1.BaseHeader {
|
|
|
87
87
|
* @protected
|
|
88
88
|
*/
|
|
89
89
|
calculateIcmpv6Checksum() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return 0;
|
|
90
|
+
//The pseudo-header comes from the nearest IPv6 layer beneath (past extension headers or an
|
|
91
|
+
//IPv6-in-IPv6 tunnel's outer header).
|
|
93
92
|
const messageBody = Buffer.from(this.instance.message.getValue(''), 'hex');
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
(0, NumberToBuffer_1.UInt8ToBuffer)(0x00),
|
|
101
|
-
(0, NumberToBuffer_1.UInt8ToBuffer)(0x00),
|
|
102
|
-
(0, NumberToBuffer_1.UInt8ToBuffer)(0x00),
|
|
103
|
-
(0, NumberToBuffer_1.UInt8ToBuffer)(0x3a)
|
|
104
|
-
]);
|
|
93
|
+
const ip = this.nearestIPModule();
|
|
94
|
+
const pseudoHeader = ip && ip.id === 'ipv6' ? this.ipPseudoHeader(0x3a, messageBody.length + 4) : undefined;
|
|
95
|
+
if (!pseudoHeader) {
|
|
96
|
+
this.recordError(this.instance.checksum.getPath(), 'Cannot compute ICMPv6 checksum: no IPv6 layer beneath ICMPv6');
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
105
99
|
const icmpHeader = Buffer.concat([
|
|
106
100
|
(0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.type.getValue(0)),
|
|
107
101
|
(0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.code.getValue(0)),
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
|
|
2
2
|
import { BaseHeader } from '../abstracts/BaseHeader';
|
|
3
|
+
/** The fields of a CP56Time2a time tag, as the time-tagged IOA items carry them. */
|
|
4
|
+
type CP56Time2a = {
|
|
5
|
+
Milliseconds: number;
|
|
6
|
+
Minutes: number;
|
|
7
|
+
GEN: number;
|
|
8
|
+
MIN_IV: number;
|
|
9
|
+
Hours: number;
|
|
10
|
+
SU: number;
|
|
11
|
+
Day: number;
|
|
12
|
+
DOW: number;
|
|
13
|
+
Month: number;
|
|
14
|
+
Year: number;
|
|
15
|
+
};
|
|
3
16
|
export declare class IEC104_I_Frame extends BaseHeader {
|
|
4
17
|
/**
|
|
5
18
|
* True when decode preserved an unparsed ASDU (unknown/unsupported type id) and no
|
|
@@ -7,12 +20,26 @@ export declare class IEC104_I_Frame extends BaseHeader {
|
|
|
7
20
|
* supplying structured IOA turns this false and encode rebuilds from fields.
|
|
8
21
|
*/
|
|
9
22
|
protected asduRawFallbackActive(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The number of IOA items encode writes: one per information object (SQ=0) or element (SQ=1).
|
|
25
|
+
*/
|
|
26
|
+
protected ioaItemCount(): number;
|
|
10
27
|
/**
|
|
11
28
|
* Write an information object's 3-octet address. SQ=0 frames carry a per-object address; SQ=1
|
|
12
29
|
* frames carry a single base address (before the first element) with the rest implied by
|
|
13
30
|
* incrementing, so only object 1 writes it.
|
|
14
31
|
*/
|
|
15
32
|
protected writeIOAAddress(offset: number, buffer: Buffer, i: number): void;
|
|
33
|
+
/**
|
|
34
|
+
* Read a 7-octet CP56Time2a (IEC 60870-5-4, IEC 60870-5-101 7.2.6.18) at `offset`: milliseconds (2
|
|
35
|
+
* octets, little-endian), minutes with GEN and IV in bits 7 and 8, hours with SU in bit 8, day of month
|
|
36
|
+
* with day of week in bits 6-8, month, year.
|
|
37
|
+
*/
|
|
38
|
+
protected readCP56Time2a(offset: number): CP56Time2a;
|
|
39
|
+
/**
|
|
40
|
+
* Write a 7-octet CP56Time2a at `offset`, the inverse of readCP56Time2a.
|
|
41
|
+
*/
|
|
42
|
+
protected writeCP56Time2a(offset: number, time: CP56Time2a): void;
|
|
16
43
|
SCHEMA: ProtocolJSONSchema;
|
|
17
44
|
id: string;
|
|
18
45
|
readonly matchKeys: string[];
|
|
@@ -21,3 +48,4 @@ export declare class IEC104_I_Frame extends BaseHeader {
|
|
|
21
48
|
nickname: string;
|
|
22
49
|
match(): boolean;
|
|
23
50
|
}
|
|
51
|
+
export {};
|