@netkitty/codec 1.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 (463) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +21 -0
  3. package/README.md +352 -0
  4. package/README.zh-CN.md +342 -0
  5. package/dist/Codec.d.ts +133 -0
  6. package/dist/Codec.js +632 -0
  7. package/dist/PacketHeaders.d.ts +189 -0
  8. package/dist/PacketHeaders.js +384 -0
  9. package/dist/abstracts/BaseHeader.d.ts +325 -0
  10. package/dist/abstracts/BaseHeader.js +734 -0
  11. package/dist/errors/CodecSchemaValidateError.d.ts +4 -0
  12. package/dist/errors/CodecSchemaValidateError.js +11 -0
  13. package/dist/headers/ADSAMS.d.ts +33 -0
  14. package/dist/headers/ADSAMS.js +208 -0
  15. package/dist/headers/AH.d.ts +28 -0
  16. package/dist/headers/AH.js +137 -0
  17. package/dist/headers/AMQP.d.ts +31 -0
  18. package/dist/headers/AMQP.js +316 -0
  19. package/dist/headers/ARP.d.ts +26 -0
  20. package/dist/headers/ARP.js +243 -0
  21. package/dist/headers/BACnetIP.d.ts +27 -0
  22. package/dist/headers/BACnetIP.js +97 -0
  23. package/dist/headers/BFD.d.ts +28 -0
  24. package/dist/headers/BFD.js +155 -0
  25. package/dist/headers/BGP.d.ts +27 -0
  26. package/dist/headers/BGP.js +111 -0
  27. package/dist/headers/BSAPIP.d.ts +33 -0
  28. package/dist/headers/BSAPIP.js +78 -0
  29. package/dist/headers/Babel.d.ts +32 -0
  30. package/dist/headers/Babel.js +224 -0
  31. package/dist/headers/BitTorrent.d.ts +28 -0
  32. package/dist/headers/BitTorrent.js +72 -0
  33. package/dist/headers/C37118.d.ts +26 -0
  34. package/dist/headers/C37118.js +147 -0
  35. package/dist/headers/CAPWAP.d.ts +38 -0
  36. package/dist/headers/CAPWAP.js +275 -0
  37. package/dist/headers/CDP.d.ts +25 -0
  38. package/dist/headers/CDP.js +117 -0
  39. package/dist/headers/CMS.d.ts +33 -0
  40. package/dist/headers/CMS.js +238 -0
  41. package/dist/headers/COTP.d.ts +30 -0
  42. package/dist/headers/COTP.js +193 -0
  43. package/dist/headers/CassandraCQL.d.ts +28 -0
  44. package/dist/headers/CassandraCQL.js +117 -0
  45. package/dist/headers/CoAP.d.ts +29 -0
  46. package/dist/headers/CoAP.js +140 -0
  47. package/dist/headers/Codesys.d.ts +32 -0
  48. package/dist/headers/Codesys.js +119 -0
  49. package/dist/headers/Collectd.d.ts +29 -0
  50. package/dist/headers/Collectd.js +154 -0
  51. package/dist/headers/DCCP.d.ts +30 -0
  52. package/dist/headers/DCCP.js +204 -0
  53. package/dist/headers/DHCP.d.ts +26 -0
  54. package/dist/headers/DHCP.js +148 -0
  55. package/dist/headers/DHCPFailover.d.ts +30 -0
  56. package/dist/headers/DHCPFailover.js +104 -0
  57. package/dist/headers/DHCPv6.d.ts +25 -0
  58. package/dist/headers/DHCPv6.js +145 -0
  59. package/dist/headers/DNP3.d.ts +27 -0
  60. package/dist/headers/DNP3.js +150 -0
  61. package/dist/headers/DNS.d.ts +55 -0
  62. package/dist/headers/DNS.js +309 -0
  63. package/dist/headers/DTLS.d.ts +33 -0
  64. package/dist/headers/DTLS.js +142 -0
  65. package/dist/headers/Diameter.d.ts +34 -0
  66. package/dist/headers/Diameter.js +229 -0
  67. package/dist/headers/EAPOL.d.ts +32 -0
  68. package/dist/headers/EAPOL.js +135 -0
  69. package/dist/headers/EIGRP.d.ts +28 -0
  70. package/dist/headers/EIGRP.js +165 -0
  71. package/dist/headers/ENIP.d.ts +31 -0
  72. package/dist/headers/ENIP.js +164 -0
  73. package/dist/headers/ESP.d.ts +27 -0
  74. package/dist/headers/ESP.js +140 -0
  75. package/dist/headers/Elasticsearch.d.ts +30 -0
  76. package/dist/headers/Elasticsearch.js +125 -0
  77. package/dist/headers/EtherCAT.d.ts +35 -0
  78. package/dist/headers/EtherCAT.js +150 -0
  79. package/dist/headers/EthernetII.d.ts +28 -0
  80. package/dist/headers/EthernetII.js +117 -0
  81. package/dist/headers/FCoE.d.ts +38 -0
  82. package/dist/headers/FCoE.js +210 -0
  83. package/dist/headers/FTP.d.ts +34 -0
  84. package/dist/headers/FTP.js +158 -0
  85. package/dist/headers/Finger.d.ts +41 -0
  86. package/dist/headers/Finger.js +135 -0
  87. package/dist/headers/FoundationFieldbusHSE.d.ts +43 -0
  88. package/dist/headers/FoundationFieldbusHSE.js +163 -0
  89. package/dist/headers/GELF.d.ts +35 -0
  90. package/dist/headers/GELF.js +261 -0
  91. package/dist/headers/GENEVE.d.ts +26 -0
  92. package/dist/headers/GENEVE.js +209 -0
  93. package/dist/headers/GESRTP.d.ts +32 -0
  94. package/dist/headers/GESRTP.js +141 -0
  95. package/dist/headers/GLBP.d.ts +29 -0
  96. package/dist/headers/GLBP.js +159 -0
  97. package/dist/headers/GRE.d.ts +27 -0
  98. package/dist/headers/GRE.js +181 -0
  99. package/dist/headers/GTPU.d.ts +25 -0
  100. package/dist/headers/GTPU.js +203 -0
  101. package/dist/headers/GTPv2C.d.ts +30 -0
  102. package/dist/headers/GTPv2C.js +281 -0
  103. package/dist/headers/GitProtocol.d.ts +34 -0
  104. package/dist/headers/GitProtocol.js +141 -0
  105. package/dist/headers/Goose.d.ts +115 -0
  106. package/dist/headers/Goose.js +1067 -0
  107. package/dist/headers/Gopher.d.ts +43 -0
  108. package/dist/headers/Gopher.js +182 -0
  109. package/dist/headers/HARTIP.d.ts +30 -0
  110. package/dist/headers/HARTIP.js +145 -0
  111. package/dist/headers/HSR.d.ts +27 -0
  112. package/dist/headers/HSR.js +105 -0
  113. package/dist/headers/HSRP.d.ts +26 -0
  114. package/dist/headers/HSRP.js +173 -0
  115. package/dist/headers/HTTP.d.ts +32 -0
  116. package/dist/headers/HTTP.js +153 -0
  117. package/dist/headers/HTTP2.d.ts +34 -0
  118. package/dist/headers/HTTP2.js +190 -0
  119. package/dist/headers/IAX2.d.ts +33 -0
  120. package/dist/headers/IAX2.js +274 -0
  121. package/dist/headers/ICMP.d.ts +15 -0
  122. package/dist/headers/ICMP.js +148 -0
  123. package/dist/headers/ICMPv6.d.ts +15 -0
  124. package/dist/headers/ICMPv6.js +129 -0
  125. package/dist/headers/IEC104_I_Frame.d.ts +23 -0
  126. package/dist/headers/IEC104_I_Frame.js +6489 -0
  127. package/dist/headers/IEC104_S_Frame.d.ts +26 -0
  128. package/dist/headers/IEC104_S_Frame.js +135 -0
  129. package/dist/headers/IEC104_U_Frame.d.ts +27 -0
  130. package/dist/headers/IEC104_U_Frame.js +176 -0
  131. package/dist/headers/IEC61850SampledValues.d.ts +20 -0
  132. package/dist/headers/IEC61850SampledValues.js +420 -0
  133. package/dist/headers/IGMP.d.ts +31 -0
  134. package/dist/headers/IGMP.js +274 -0
  135. package/dist/headers/IMAP.d.ts +32 -0
  136. package/dist/headers/IMAP.js +185 -0
  137. package/dist/headers/IPFIX.d.ts +29 -0
  138. package/dist/headers/IPFIX.js +156 -0
  139. package/dist/headers/IPv4.d.ts +20 -0
  140. package/dist/headers/IPv4.js +370 -0
  141. package/dist/headers/IPv6.d.ts +29 -0
  142. package/dist/headers/IPv6.js +209 -0
  143. package/dist/headers/IPv6HopByHopOptions.d.ts +81 -0
  144. package/dist/headers/IPv6HopByHopOptions.js +495 -0
  145. package/dist/headers/IRC.d.ts +34 -0
  146. package/dist/headers/IRC.js +175 -0
  147. package/dist/headers/ISAKMP.d.ts +29 -0
  148. package/dist/headers/ISAKMP.js +197 -0
  149. package/dist/headers/ISCSI.d.ts +39 -0
  150. package/dist/headers/ISCSI.js +289 -0
  151. package/dist/headers/ISIS.d.ts +25 -0
  152. package/dist/headers/ISIS.js +79 -0
  153. package/dist/headers/ISOSession.d.ts +27 -0
  154. package/dist/headers/ISOSession.js +343 -0
  155. package/dist/headers/Ident.d.ts +42 -0
  156. package/dist/headers/Ident.js +184 -0
  157. package/dist/headers/KNXnetIP.d.ts +30 -0
  158. package/dist/headers/KNXnetIP.js +135 -0
  159. package/dist/headers/Kafka.d.ts +35 -0
  160. package/dist/headers/Kafka.js +128 -0
  161. package/dist/headers/Kerberos.d.ts +30 -0
  162. package/dist/headers/Kerberos.js +217 -0
  163. package/dist/headers/L2TP.d.ts +26 -0
  164. package/dist/headers/L2TP.js +297 -0
  165. package/dist/headers/LACP.d.ts +31 -0
  166. package/dist/headers/LACP.js +151 -0
  167. package/dist/headers/LDAP.d.ts +31 -0
  168. package/dist/headers/LDAP.js +226 -0
  169. package/dist/headers/LDP.d.ts +31 -0
  170. package/dist/headers/LDP.js +138 -0
  171. package/dist/headers/LISP.d.ts +30 -0
  172. package/dist/headers/LISP.js +103 -0
  173. package/dist/headers/LLC.d.ts +27 -0
  174. package/dist/headers/LLC.js +81 -0
  175. package/dist/headers/LLDP.d.ts +26 -0
  176. package/dist/headers/LLDP.js +126 -0
  177. package/dist/headers/LLMNR.d.ts +23 -0
  178. package/dist/headers/LLMNR.js +40 -0
  179. package/dist/headers/LPD.d.ts +31 -0
  180. package/dist/headers/LPD.js +159 -0
  181. package/dist/headers/MACsec.d.ts +34 -0
  182. package/dist/headers/MACsec.js +178 -0
  183. package/dist/headers/MDNS.d.ts +26 -0
  184. package/dist/headers/MDNS.js +45 -0
  185. package/dist/headers/MGCP.d.ts +30 -0
  186. package/dist/headers/MGCP.js +155 -0
  187. package/dist/headers/MMS.d.ts +29 -0
  188. package/dist/headers/MMS.js +243 -0
  189. package/dist/headers/MPLS.d.ts +31 -0
  190. package/dist/headers/MPLS.js +145 -0
  191. package/dist/headers/MQTT.d.ts +30 -0
  192. package/dist/headers/MQTT.js +173 -0
  193. package/dist/headers/MQTTSN.d.ts +34 -0
  194. package/dist/headers/MQTTSN.js +177 -0
  195. package/dist/headers/MarkerProtocol.d.ts +32 -0
  196. package/dist/headers/MarkerProtocol.js +153 -0
  197. package/dist/headers/Megaco.d.ts +32 -0
  198. package/dist/headers/Megaco.js +144 -0
  199. package/dist/headers/Memcached.d.ts +44 -0
  200. package/dist/headers/Memcached.js +285 -0
  201. package/dist/headers/ModbusTCP.d.ts +25 -0
  202. package/dist/headers/ModbusTCP.js +99 -0
  203. package/dist/headers/ModbusUDP.d.ts +26 -0
  204. package/dist/headers/ModbusUDP.js +100 -0
  205. package/dist/headers/MongoDB.d.ts +33 -0
  206. package/dist/headers/MongoDB.js +143 -0
  207. package/dist/headers/MySQL.d.ts +30 -0
  208. package/dist/headers/MySQL.js +114 -0
  209. package/dist/headers/NATS.d.ts +29 -0
  210. package/dist/headers/NATS.js +135 -0
  211. package/dist/headers/NBDS.d.ts +34 -0
  212. package/dist/headers/NBDS.js +176 -0
  213. package/dist/headers/NBNS.d.ts +34 -0
  214. package/dist/headers/NBNS.js +78 -0
  215. package/dist/headers/NBSS.d.ts +36 -0
  216. package/dist/headers/NBSS.js +137 -0
  217. package/dist/headers/NFS.d.ts +36 -0
  218. package/dist/headers/NFS.js +273 -0
  219. package/dist/headers/NHRP.d.ts +32 -0
  220. package/dist/headers/NHRP.js +154 -0
  221. package/dist/headers/NNTP.d.ts +35 -0
  222. package/dist/headers/NNTP.js +162 -0
  223. package/dist/headers/NTP.d.ts +18 -0
  224. package/dist/headers/NTP.js +73 -0
  225. package/dist/headers/NetFlowV5.d.ts +28 -0
  226. package/dist/headers/NetFlowV5.js +205 -0
  227. package/dist/headers/OLSR.d.ts +31 -0
  228. package/dist/headers/OLSR.js +213 -0
  229. package/dist/headers/OPCUA.d.ts +33 -0
  230. package/dist/headers/OPCUA.js +165 -0
  231. package/dist/headers/OPCUAPubSub.d.ts +33 -0
  232. package/dist/headers/OPCUAPubSub.js +144 -0
  233. package/dist/headers/OSPF.d.ts +31 -0
  234. package/dist/headers/OSPF.js +365 -0
  235. package/dist/headers/OmronFINS.d.ts +31 -0
  236. package/dist/headers/OmronFINS.js +90 -0
  237. package/dist/headers/OpenFlow.d.ts +30 -0
  238. package/dist/headers/OpenFlow.js +113 -0
  239. package/dist/headers/OpenVPN.d.ts +35 -0
  240. package/dist/headers/OpenVPN.js +214 -0
  241. package/dist/headers/PCWorx.d.ts +35 -0
  242. package/dist/headers/PCWorx.js +115 -0
  243. package/dist/headers/PIM.d.ts +27 -0
  244. package/dist/headers/PIM.js +129 -0
  245. package/dist/headers/POP3.d.ts +31 -0
  246. package/dist/headers/POP3.js +152 -0
  247. package/dist/headers/POWERLINK.d.ts +28 -0
  248. package/dist/headers/POWERLINK.js +116 -0
  249. package/dist/headers/PPPoEDiscovery.d.ts +29 -0
  250. package/dist/headers/PPPoEDiscovery.js +198 -0
  251. package/dist/headers/PPPoESession.d.ts +28 -0
  252. package/dist/headers/PPPoESession.js +125 -0
  253. package/dist/headers/PPTP.d.ts +30 -0
  254. package/dist/headers/PPTP.js +122 -0
  255. package/dist/headers/PROFINETRT.d.ts +28 -0
  256. package/dist/headers/PROFINETRT.js +74 -0
  257. package/dist/headers/PTP.d.ts +34 -0
  258. package/dist/headers/PTP.js +213 -0
  259. package/dist/headers/PostgreSQL.d.ts +40 -0
  260. package/dist/headers/PostgreSQL.js +236 -0
  261. package/dist/headers/QUIC.d.ts +34 -0
  262. package/dist/headers/QUIC.js +308 -0
  263. package/dist/headers/RADIUS.d.ts +24 -0
  264. package/dist/headers/RADIUS.js +138 -0
  265. package/dist/headers/RDP.d.ts +27 -0
  266. package/dist/headers/RDP.js +93 -0
  267. package/dist/headers/RFB.d.ts +39 -0
  268. package/dist/headers/RFB.js +151 -0
  269. package/dist/headers/RGoose.d.ts +72 -0
  270. package/dist/headers/RGoose.js +340 -0
  271. package/dist/headers/RIP.d.ts +29 -0
  272. package/dist/headers/RIP.js +133 -0
  273. package/dist/headers/RIPng.d.ts +26 -0
  274. package/dist/headers/RIPng.js +140 -0
  275. package/dist/headers/RMCP.d.ts +26 -0
  276. package/dist/headers/RMCP.js +155 -0
  277. package/dist/headers/RSVP.d.ts +31 -0
  278. package/dist/headers/RSVP.js +263 -0
  279. package/dist/headers/RTCP.d.ts +34 -0
  280. package/dist/headers/RTCP.js +217 -0
  281. package/dist/headers/RTP.d.ts +33 -0
  282. package/dist/headers/RTP.js +291 -0
  283. package/dist/headers/RTPS.d.ts +33 -0
  284. package/dist/headers/RTPS.js +182 -0
  285. package/dist/headers/RTSP.d.ts +36 -0
  286. package/dist/headers/RTSP.js +184 -0
  287. package/dist/headers/RawData.d.ts +17 -0
  288. package/dist/headers/RawData.js +43 -0
  289. package/dist/headers/Redis.d.ts +32 -0
  290. package/dist/headers/Redis.js +202 -0
  291. package/dist/headers/Rlogin.d.ts +42 -0
  292. package/dist/headers/Rlogin.js +139 -0
  293. package/dist/headers/Rsync.d.ts +28 -0
  294. package/dist/headers/Rsync.js +117 -0
  295. package/dist/headers/S7comm.d.ts +36 -0
  296. package/dist/headers/S7comm.js +244 -0
  297. package/dist/headers/SCTP.d.ts +35 -0
  298. package/dist/headers/SCTP.js +174 -0
  299. package/dist/headers/SFlow.d.ts +29 -0
  300. package/dist/headers/SFlow.js +242 -0
  301. package/dist/headers/SIP.d.ts +27 -0
  302. package/dist/headers/SIP.js +146 -0
  303. package/dist/headers/SLMP.d.ts +36 -0
  304. package/dist/headers/SLMP.js +154 -0
  305. package/dist/headers/SLP.d.ts +30 -0
  306. package/dist/headers/SLP.js +207 -0
  307. package/dist/headers/SLPv1.d.ts +32 -0
  308. package/dist/headers/SLPv1.js +138 -0
  309. package/dist/headers/SMB1.d.ts +37 -0
  310. package/dist/headers/SMB1.js +200 -0
  311. package/dist/headers/SMB2.d.ts +36 -0
  312. package/dist/headers/SMB2.js +203 -0
  313. package/dist/headers/SMPP.d.ts +33 -0
  314. package/dist/headers/SMPP.js +119 -0
  315. package/dist/headers/SMTP.d.ts +33 -0
  316. package/dist/headers/SMTP.js +157 -0
  317. package/dist/headers/SNAP.d.ts +22 -0
  318. package/dist/headers/SNAP.js +68 -0
  319. package/dist/headers/SNMP.d.ts +28 -0
  320. package/dist/headers/SNMP.js +302 -0
  321. package/dist/headers/SOCKS4.d.ts +42 -0
  322. package/dist/headers/SOCKS4.js +302 -0
  323. package/dist/headers/SOCKS5.d.ts +45 -0
  324. package/dist/headers/SOCKS5.js +223 -0
  325. package/dist/headers/SSDP.d.ts +27 -0
  326. package/dist/headers/SSDP.js +161 -0
  327. package/dist/headers/SSH.d.ts +44 -0
  328. package/dist/headers/SSH.js +274 -0
  329. package/dist/headers/STOMP.d.ts +48 -0
  330. package/dist/headers/STOMP.js +177 -0
  331. package/dist/headers/STP.d.ts +26 -0
  332. package/dist/headers/STP.js +150 -0
  333. package/dist/headers/STUN.d.ts +25 -0
  334. package/dist/headers/STUN.js +183 -0
  335. package/dist/headers/SercosIII.d.ts +43 -0
  336. package/dist/headers/SercosIII.js +199 -0
  337. package/dist/headers/Skinny.d.ts +32 -0
  338. package/dist/headers/Skinny.js +139 -0
  339. package/dist/headers/StatsD.d.ts +27 -0
  340. package/dist/headers/StatsD.js +134 -0
  341. package/dist/headers/SunRPC.d.ts +34 -0
  342. package/dist/headers/SunRPC.js +268 -0
  343. package/dist/headers/Syslog.d.ts +21 -0
  344. package/dist/headers/Syslog.js +91 -0
  345. package/dist/headers/TCP.d.ts +19 -0
  346. package/dist/headers/TCP.js +905 -0
  347. package/dist/headers/TFTP.d.ts +28 -0
  348. package/dist/headers/TFTP.js +224 -0
  349. package/dist/headers/TLS_Alert.d.ts +24 -0
  350. package/dist/headers/TLS_Alert.js +639 -0
  351. package/dist/headers/TLS_ApplicationData.d.ts +24 -0
  352. package/dist/headers/TLS_ApplicationData.js +170 -0
  353. package/dist/headers/TLS_ChangeCipherSpec.d.ts +23 -0
  354. package/dist/headers/TLS_ChangeCipherSpec.js +168 -0
  355. package/dist/headers/TLS_Handshake.d.ts +65 -0
  356. package/dist/headers/TLS_Handshake.js +860 -0
  357. package/dist/headers/TLS_Heartbeat.d.ts +27 -0
  358. package/dist/headers/TLS_Heartbeat.js +247 -0
  359. package/dist/headers/TPKT.d.ts +26 -0
  360. package/dist/headers/TPKT.js +99 -0
  361. package/dist/headers/TacacsPlus.d.ts +27 -0
  362. package/dist/headers/TacacsPlus.js +133 -0
  363. package/dist/headers/Telnet.d.ts +40 -0
  364. package/dist/headers/Telnet.js +193 -0
  365. package/dist/headers/Teredo.d.ts +40 -0
  366. package/dist/headers/Teredo.js +251 -0
  367. package/dist/headers/TimeProtocol.d.ts +25 -0
  368. package/dist/headers/TimeProtocol.js +53 -0
  369. package/dist/headers/UDP.d.ts +19 -0
  370. package/dist/headers/UDP.js +171 -0
  371. package/dist/headers/VLAN_802dot1Q.d.ts +24 -0
  372. package/dist/headers/VLAN_802dot1Q.js +96 -0
  373. package/dist/headers/VRRP.d.ts +26 -0
  374. package/dist/headers/VRRP.js +309 -0
  375. package/dist/headers/VXLAN.d.ts +24 -0
  376. package/dist/headers/VXLAN.js +75 -0
  377. package/dist/headers/WCCP.d.ts +29 -0
  378. package/dist/headers/WCCP.js +117 -0
  379. package/dist/headers/WHOIS.d.ts +37 -0
  380. package/dist/headers/WHOIS.js +126 -0
  381. package/dist/headers/WSDiscovery.d.ts +29 -0
  382. package/dist/headers/WSDiscovery.js +118 -0
  383. package/dist/headers/WakeOnLAN.d.ts +30 -0
  384. package/dist/headers/WakeOnLAN.js +126 -0
  385. package/dist/headers/WebSocket.d.ts +26 -0
  386. package/dist/headers/WebSocket.js +173 -0
  387. package/dist/headers/WireGuard.d.ts +38 -0
  388. package/dist/headers/WireGuard.js +216 -0
  389. package/dist/headers/XMPP.d.ts +37 -0
  390. package/dist/headers/XMPP.js +149 -0
  391. package/dist/headers/Zabbix.d.ts +35 -0
  392. package/dist/headers/Zabbix.js +153 -0
  393. package/dist/headers/cms/AcsiPdu.d.ts +45 -0
  394. package/dist/headers/cms/AcsiPdu.js +112 -0
  395. package/dist/headers/cms/PerDecoder.d.ts +68 -0
  396. package/dist/headers/cms/PerDecoder.js +211 -0
  397. package/dist/headers/cms/PerReader.d.ts +64 -0
  398. package/dist/headers/cms/PerReader.js +155 -0
  399. package/dist/helper/BufferToHex.d.ts +5 -0
  400. package/dist/helper/BufferToHex.js +10 -0
  401. package/dist/helper/BufferToIP.d.ts +12 -0
  402. package/dist/helper/BufferToIP.js +23 -0
  403. package/dist/helper/BufferToNumber.d.ts +18 -0
  404. package/dist/helper/BufferToNumber.js +47 -0
  405. package/dist/helper/HexToBuffer.d.ts +7 -0
  406. package/dist/helper/HexToBuffer.js +27 -0
  407. package/dist/helper/HexToNumber.d.ts +18 -0
  408. package/dist/helper/HexToNumber.js +48 -0
  409. package/dist/helper/IPToBuffer.d.ts +12 -0
  410. package/dist/helper/IPToBuffer.js +34 -0
  411. package/dist/helper/NumberToBERBuffer.d.ts +18 -0
  412. package/dist/helper/NumberToBERBuffer.js +31 -0
  413. package/dist/helper/NumberToBERHex.d.ts +18 -0
  414. package/dist/helper/NumberToBERHex.js +52 -0
  415. package/dist/helper/NumberToBuffer.d.ts +18 -0
  416. package/dist/helper/NumberToBuffer.js +38 -0
  417. package/dist/helper/NumberToHex.d.ts +18 -0
  418. package/dist/helper/NumberToHex.js +35 -0
  419. package/dist/index.d.ts +52 -0
  420. package/dist/index.js +113 -0
  421. package/dist/lib/FlexibleObject.d.ts +27 -0
  422. package/dist/lib/FlexibleObject.js +113 -0
  423. package/dist/lib/GetBERIntegerLengthFromBuffer.d.ts +6 -0
  424. package/dist/lib/GetBERIntegerLengthFromBuffer.js +16 -0
  425. package/dist/lib/ProcessPacketPostHandlers.d.ts +13 -0
  426. package/dist/lib/ProcessPacketPostHandlers.js +53 -0
  427. package/dist/lib/SortPostHandlers.d.ts +7 -0
  428. package/dist/lib/SortPostHandlers.js +11 -0
  429. package/dist/lib/StringContentEncodingEnum.d.ts +10 -0
  430. package/dist/lib/StringContentEncodingEnum.js +14 -0
  431. package/dist/schema/ProtocolFieldJSONSchema.d.ts +35 -0
  432. package/dist/schema/ProtocolFieldJSONSchema.js +2 -0
  433. package/dist/schema/ProtocolFieldJSONSchemaDefinition.d.ts +2 -0
  434. package/dist/schema/ProtocolFieldJSONSchemaDefinition.js +2 -0
  435. package/dist/schema/ProtocolJSONSchema.d.ts +32 -0
  436. package/dist/schema/ProtocolJSONSchema.js +2 -0
  437. package/dist/types/CodecData.d.ts +7 -0
  438. package/dist/types/CodecData.js +2 -0
  439. package/dist/types/CodecDecodeResult.d.ts +10 -0
  440. package/dist/types/CodecDecodeResult.js +2 -0
  441. package/dist/types/CodecEncodeInput.d.ts +2 -0
  442. package/dist/types/CodecEncodeInput.js +2 -0
  443. package/dist/types/CodecEncodeResult.d.ts +5 -0
  444. package/dist/types/CodecEncodeResult.js +2 -0
  445. package/dist/types/CodecErrorInfo.d.ts +5 -0
  446. package/dist/types/CodecErrorInfo.js +2 -0
  447. package/dist/types/CodecModule.d.ts +2 -0
  448. package/dist/types/CodecModule.js +2 -0
  449. package/dist/types/CodecModuleConstructor.d.ts +2 -0
  450. package/dist/types/CodecModuleConstructor.js +2 -0
  451. package/dist/types/CodecSchema.d.ts +6 -0
  452. package/dist/types/CodecSchema.js +2 -0
  453. package/dist/types/DemuxProducer.d.ts +23 -0
  454. package/dist/types/DemuxProducer.js +2 -0
  455. package/dist/types/Dissection.d.ts +23 -0
  456. package/dist/types/Dissection.js +2 -0
  457. package/dist/types/HeaderTreeNode.d.ts +4 -0
  458. package/dist/types/HeaderTreeNode.js +2 -0
  459. package/dist/types/LayerGraph.d.ts +32 -0
  460. package/dist/types/LayerGraph.js +2 -0
  461. package/dist/types/PostHandlerItem.d.ts +4 -0
  462. package/dist/types/PostHandlerItem.js +2 -0
  463. package/package.json +141 -0
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Babel = void 0;
4
+ const BaseHeader_1 = require("../abstracts/BaseHeader");
5
+ const BufferToHex_1 = require("../helper/BufferToHex");
6
+ const HexToBuffer_1 = require("../helper/HexToBuffer");
7
+ const BufferToNumber_1 = require("../helper/BufferToNumber");
8
+ const NumberToBuffer_1 = require("../helper/NumberToBuffer");
9
+ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
10
+ /**
11
+ * Babel routing protocol (RFC 8966), carried in UDP over port 6696 (to the well-known multicast group
12
+ * or unicast). A Babel packet starts with a fixed 4-byte header — Magic (== 42), Version (== 2) and a
13
+ * 2-byte Body Length (the octet count of the packet body that follows the header, not counting the
14
+ * optional packet trailer) — followed by the packet body: a flat sequence of TLVs, then an optional
15
+ * trailer (which may only carry Pad1/PadN sub-TLVs).
16
+ *
17
+ * Each TLV is Type (1 byte) + Length (1 byte, the value byte count, NOT counting the Type/Length pair)
18
+ * + Value, except Pad1 (Type 0) which is a single byte with no Length/Value. Common types: 0 Pad1,
19
+ * 1 PadN, 2 Acknowledgment Request, 4 Hello, 5 IHU, 8 Update.
20
+ *
21
+ * Byte-perfect strategy (minimal slice): structure Magic / Version / Body Length, then carry the TLVs
22
+ * generically (Type + verbatim hex Value, Pad1 special-cased as a bare byte) so every TLV — including
23
+ * types this codec does not sub-decode — round-trips byte-for-byte. The TLV walk is bounded by Body
24
+ * Length AND the UDP payload (udp.length − 8), so a lying Body Length cannot read past the datagram.
25
+ * Body Length is honored when supplied (a crafted packet may lie) else derived from the TLVs; any bytes
26
+ * after the body (the packet trailer, or leftover bytes from a truncated TLV) are kept verbatim in
27
+ * `trailer` so the datagram is reproduced exactly. A well-formed packet round-trips byte-for-byte.
28
+ */
29
+ class Babel extends BaseHeader_1.BaseHeader {
30
+ constructor() {
31
+ super(...arguments);
32
+ this.id = 'babel';
33
+ this.name = 'Babel Routing Protocol';
34
+ this.nickname = 'Babel';
35
+ this.matchKeys = ['udpport:6696'];
36
+ //A leaf header — the per-type TLV bodies are kept verbatim for now.
37
+ this.demuxProducers = [];
38
+ }
39
+ static #schemaCache;
40
+ get SCHEMA() {
41
+ return (Babel.#schemaCache ??= Babel.#buildSchema());
42
+ }
43
+ /**
44
+ * Header-relative end offset of the bytes this Babel layer may consume, so a lying Body Length never
45
+ * reads past the real UDP payload. Over UDP the bound is (udp.length − 8); clamped to the captured
46
+ * bytes. Anything beyond is another datagram / Ethernet padding and is left alone.
47
+ */
48
+ #payloadEnd() {
49
+ let end = this.packet.length - this.startPos;
50
+ const prev = this.prevCodecModule;
51
+ if (prev && prev.id === 'udp') {
52
+ const udpLength = prev.instance.length.getValue(0);
53
+ if (udpLength >= 8 && udpLength - 8 < end)
54
+ end = udpLength - 8;
55
+ }
56
+ return end < 0 ? 0 : end;
57
+ }
58
+ static #buildSchema() {
59
+ return {
60
+ type: 'object',
61
+ summary: 'Babel v${version} ${tlvs.length} TLVs',
62
+ properties: {
63
+ //The Magic byte, always 42 (0x2a) for Babel — also the match signature on UDP 6696.
64
+ magic: this.fieldUInt('magic', 0, 1, 'Magic'),
65
+ //The protocol version, always 2 (RFC 8966).
66
+ version: this.fieldUInt('version', 1, 1, 'Version'),
67
+ //The octet count of the packet body (the TLV sequence) following this 4-byte header, NOT
68
+ //counting the optional packet trailer. Honored when supplied (a crafted packet may lie)
69
+ //else derived from the TLVs. Derived from the TLV VALUES (not written bytes), so it is
70
+ //correct even though it encodes before the `tlvs` field writes them.
71
+ bodyLength: {
72
+ type: 'integer',
73
+ label: 'Body Length',
74
+ minimum: 0,
75
+ maximum: 65535,
76
+ decode: function () {
77
+ this.instance.bodyLength.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)));
78
+ },
79
+ encode: function () {
80
+ const provided = this.instance.bodyLength.getValue();
81
+ let value;
82
+ if (provided !== undefined && provided !== null) {
83
+ value = provided;
84
+ }
85
+ else {
86
+ const tlvs = this.instance.tlvs.getValue([]);
87
+ let total = 0;
88
+ if (tlvs) {
89
+ for (const tlv of tlvs) {
90
+ //Pad1 (Type 0) is a single byte; every other TLV is Type + Length + Value.
91
+ if (tlv && tlv.type === 0)
92
+ total += 1;
93
+ else
94
+ total += 2 + (0, HexToBuffer_1.HexToBuffer)(tlv && tlv.value ? tlv.value : '').length;
95
+ }
96
+ }
97
+ value = total;
98
+ }
99
+ if (value > 65535) {
100
+ this.recordError(this.instance.bodyLength.getPath(), 'Maximum value is 65535');
101
+ value = 65535;
102
+ }
103
+ if (value < 0) {
104
+ this.recordError(this.instance.bodyLength.getPath(), 'Minimum value is 0');
105
+ value = 0;
106
+ }
107
+ this.instance.bodyLength.setValue(value);
108
+ this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(value));
109
+ }
110
+ },
111
+ //The packet body: a flat sequence of TLVs. This single field owns the whole body walk
112
+ //(it also sets/writes `trailer`, which is metadata-only). Bounded by Body Length AND the
113
+ //UDP payload so a truncated / lying packet is contained.
114
+ tlvs: {
115
+ type: 'array',
116
+ label: 'TLVs',
117
+ items: {
118
+ type: 'object',
119
+ label: 'TLV',
120
+ properties: {
121
+ type: { type: 'integer', label: 'Type', minimum: 0, maximum: 255 },
122
+ length: { type: 'integer', label: 'Length', minimum: 0, maximum: 255 },
123
+ value: { type: 'string', label: 'Value', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX }
124
+ }
125
+ },
126
+ decode: function () {
127
+ const payloadEnd = this.#payloadEnd();
128
+ let bodyEnd = 4 + this.instance.bodyLength.getValue(0);
129
+ if (bodyEnd > payloadEnd)
130
+ bodyEnd = payloadEnd;
131
+ const tlvs = [];
132
+ let offset = 4;
133
+ while (offset < bodyEnd) {
134
+ const type = (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(offset, 1));
135
+ //Pad1 (Type 0): a single byte, no Length / Value.
136
+ if (type === 0) {
137
+ tlvs.push({ type: 0 });
138
+ offset += 1;
139
+ continue;
140
+ }
141
+ //Need the Type + Length pair; a truncated header stops the walk.
142
+ if (offset + 2 > bodyEnd)
143
+ break;
144
+ const length = (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(offset + 1, 1));
145
+ //A Value that overruns the body (truncation) is not consumed — stop and leave
146
+ //the remaining bytes to `trailer`, keeping the round-trip exact.
147
+ if (offset + 2 + length > bodyEnd)
148
+ break;
149
+ const value = length > 0 ? (0, BufferToHex_1.BufferToHex)(this.readBytes(offset + 2, length)) : '';
150
+ tlvs.push({ type: type, length: length, value: value });
151
+ offset += 2 + length;
152
+ }
153
+ this.instance.tlvs.setValue(tlvs);
154
+ //Everything after the consumed body up to the UDP payload end is the packet trailer
155
+ //(Pad1/PadN sub-TLVs) or leftover bytes from a truncated TLV — kept verbatim.
156
+ this.instance.trailer.setValue(offset < payloadEnd ? (0, BufferToHex_1.BufferToHex)(this.readBytes(offset, payloadEnd - offset)) : '');
157
+ },
158
+ encode: function () {
159
+ const tlvs = this.instance.tlvs.getValue([]);
160
+ let offset = 4;
161
+ if (tlvs) {
162
+ for (let i = 0; i < tlvs.length; i++) {
163
+ const tlv = tlvs[i];
164
+ const type = tlv && tlv.type ? tlv.type : 0;
165
+ //Pad1 (Type 0): emit the bare Type byte, no Length / Value.
166
+ if (type === 0) {
167
+ this.writeBytes(offset, (0, NumberToBuffer_1.UInt8ToBuffer)(0));
168
+ offset += 1;
169
+ continue;
170
+ }
171
+ let value = (0, HexToBuffer_1.HexToBuffer)(tlv && tlv.value ? tlv.value : '');
172
+ //The Length is a single byte (max 255). A longer value cannot be represented,
173
+ //so clamp it and record the error rather than silently wrapping modulo 256
174
+ //(which would corrupt the following TLVs).
175
+ if (value.length > 255) {
176
+ this.recordError(`tlvs[${i}].value`, 'Maximum TLV value length is 255 bytes');
177
+ value = value.subarray(0, 255);
178
+ }
179
+ //Length honored when supplied (a crafted TLV may lie) else derived from the
180
+ //value byte count.
181
+ const providedLength = tlv ? tlv.length : undefined;
182
+ let length = (providedLength !== undefined && providedLength !== null) ? providedLength : value.length;
183
+ if (length > 255)
184
+ length = 255;
185
+ if (length < 0)
186
+ length = 0;
187
+ this.writeBytes(offset, (0, NumberToBuffer_1.UInt8ToBuffer)(type));
188
+ this.writeBytes(offset + 1, (0, NumberToBuffer_1.UInt8ToBuffer)(length));
189
+ offset += 2;
190
+ if (value.length) {
191
+ this.writeBytes(offset, value);
192
+ offset += value.length;
193
+ }
194
+ }
195
+ }
196
+ const trailer = this.instance.trailer.getValue('');
197
+ if (trailer)
198
+ this.writeBytes(offset, (0, HexToBuffer_1.HexToBuffer)(trailer));
199
+ }
200
+ },
201
+ //The optional packet trailer after the body (Pad1/PadN sub-TLVs), or leftover bytes from a
202
+ //truncated TLV, kept verbatim. No codec of its own — it is set/written by the `tlvs` field
203
+ //(which owns the single offset walk); this entry is metadata so the editor sees the bytes.
204
+ trailer: {
205
+ type: 'string',
206
+ label: 'Trailer',
207
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX
208
+ }
209
+ }
210
+ };
211
+ }
212
+ match() {
213
+ //Babel rides on UDP port 6696 (selected via the udpport:6696 bucket). Require the 4-byte header
214
+ //within the UDP payload and the Magic signature (== 42), so non-Babel traffic on 6696 falls
215
+ //through to raw. Stays a port-bucket protocol: matchKeys only, NO heuristicFallback — a lone
216
+ //0x2a byte is too weak a signature to claim Babel off its well-known port.
217
+ if (!this.prevCodecModule || this.prevCodecModule.id !== 'udp')
218
+ return false;
219
+ if (this.#payloadEnd() < 4)
220
+ return false;
221
+ return (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(0, 1, true)) === 42;
222
+ }
223
+ }
224
+ exports.Babel = Babel;
@@ -0,0 +1,28 @@
1
+ import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
+ import { DemuxProducer } from '../types/DemuxProducer';
4
+ /**
5
+ * BitTorrent — peer wire protocol (BEP 3) handshake, carried over TCP on dynamic/ephemeral ports.
6
+ * A peer connection opens with a fixed 68-byte handshake: a 1-byte pstrlen (0x13 = 19), the 19-byte
7
+ * protocol string "BitTorrent protocol" (pstr), 8 reserved bytes (extension bit-flags — DHT, Fast,
8
+ * Extension Protocol, etc.), the 20-byte SHA-1 info_hash of the torrent, and the 20-byte peer_id.
9
+ *
10
+ * This codec handles ONLY the handshake — its 0x13 + "BitTorrent protocol" prefix is an extremely
11
+ * distinctive 20-byte content signature, so the header is selected by heuristicFallback (no fixed
12
+ * port). The subsequent length-prefixed peer messages (<length(4)><type(1)><payload>) carry no such
13
+ * signature and are intentionally NOT claimed here: after the 68-byte handshake is consumed, any
14
+ * trailing bytes (a pipelined first peer message, etc.) are left to the codec's recursion / RawData.
15
+ * Every field is kept verbatim (reserved / info_hash / peer_id are opaque hex), nothing is recomputed
16
+ * on encode, so a well-formed handshake round-trips byte-for-byte.
17
+ */
18
+ export declare class BitTorrent extends BaseHeader {
19
+ #private;
20
+ get SCHEMA(): ProtocolJSONSchema;
21
+ readonly id: string;
22
+ readonly name: string;
23
+ readonly nickname: string;
24
+ readonly matchKeys: string[];
25
+ readonly heuristicFallback: boolean;
26
+ match(): boolean;
27
+ readonly demuxProducers: DemuxProducer[];
28
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BitTorrent = void 0;
4
+ const BaseHeader_1 = require("../abstracts/BaseHeader");
5
+ const BufferToHex_1 = require("../helper/BufferToHex");
6
+ /**
7
+ * BitTorrent — peer wire protocol (BEP 3) handshake, carried over TCP on dynamic/ephemeral ports.
8
+ * A peer connection opens with a fixed 68-byte handshake: a 1-byte pstrlen (0x13 = 19), the 19-byte
9
+ * protocol string "BitTorrent protocol" (pstr), 8 reserved bytes (extension bit-flags — DHT, Fast,
10
+ * Extension Protocol, etc.), the 20-byte SHA-1 info_hash of the torrent, and the 20-byte peer_id.
11
+ *
12
+ * This codec handles ONLY the handshake — its 0x13 + "BitTorrent protocol" prefix is an extremely
13
+ * distinctive 20-byte content signature, so the header is selected by heuristicFallback (no fixed
14
+ * port). The subsequent length-prefixed peer messages (<length(4)><type(1)><payload>) carry no such
15
+ * signature and are intentionally NOT claimed here: after the 68-byte handshake is consumed, any
16
+ * trailing bytes (a pipelined first peer message, etc.) are left to the codec's recursion / RawData.
17
+ * Every field is kept verbatim (reserved / info_hash / peer_id are opaque hex), nothing is recomputed
18
+ * on encode, so a well-formed handshake round-trips byte-for-byte.
19
+ */
20
+ class BitTorrent extends BaseHeader_1.BaseHeader {
21
+ constructor() {
22
+ super(...arguments);
23
+ this.id = 'bittorrent';
24
+ this.name = 'BitTorrent Peer Wire Protocol';
25
+ this.nickname = 'BitTorrent';
26
+ //No fixed port — BitTorrent peers connect on dynamic/ephemeral ports. Selection is by the
27
+ //content signature (0x13 + "BitTorrent protocol") via heuristicFallback + match().
28
+ this.matchKeys = [];
29
+ this.heuristicFallback = true;
30
+ //A leaf header — only the handshake is decoded; subsequent peer messages are left to raw.
31
+ this.demuxProducers = [];
32
+ }
33
+ static #schemaCache;
34
+ get SCHEMA() {
35
+ return (BitTorrent.#schemaCache ??= BitTorrent.#buildSchema());
36
+ }
37
+ static #buildSchema() {
38
+ return {
39
+ type: 'object',
40
+ summary: 'BitTorrent handshake infoHash=${infoHash}',
41
+ properties: {
42
+ //Protocol string length — always 0x13 (19) for the BEP 3 handshake. Kept as a plain uint8
43
+ //(a crafted handshake may lie); the signature match already guards real traffic.
44
+ pstrlen: this.fieldUInt('pstrlen', 0, 1, 'Protocol String Length'),
45
+ //The 19-byte protocol identifier "BitTorrent protocol". Kept verbatim as hex so any
46
+ //byte edit round-trips; the human-readable form is UI enrichment for later.
47
+ pstr: this.fieldHex('pstr', 1, 19, 'Protocol String'),
48
+ //8 reserved bytes carrying extension bit-flags (BEP 4/5/6/10: DHT, Fast, Extension
49
+ //Protocol). Opaque here and re-emitted verbatim.
50
+ reserved: this.fieldHex('reserved', 20, 8, 'Reserved'),
51
+ //20-byte SHA-1 hash of the torrent's info dictionary — identifies the swarm. Verbatim hex.
52
+ infoHash: this.fieldHex('infoHash', 28, 20, 'Info Hash'),
53
+ //20-byte peer identifier chosen by the connecting client (often an ASCII client tag +
54
+ //random suffix). Verbatim hex.
55
+ peerId: this.fieldHex('peerId', 48, 20, 'Peer ID')
56
+ }
57
+ };
58
+ }
59
+ match() {
60
+ //Rides on TCP. Require the full 68-byte handshake present so a truncated prefix is not claimed
61
+ //(it falls through to raw and merely survives). The 0x13 pstrlen + the exact 19-byte
62
+ //"BitTorrent protocol" string is a distinctive content signature safe to match on any port.
63
+ if (!this.prevCodecModule || this.prevCodecModule.id !== 'tcp')
64
+ return false;
65
+ if (this.packet.length - this.startPos < 68)
66
+ return false;
67
+ if (this.readBytes(0, 1, true)[0] !== 0x13)
68
+ return false;
69
+ return (0, BufferToHex_1.BufferToHex)(this.readBytes(1, 19, true)) === '426974546f7272656e742070726f746f636f6c';
70
+ }
71
+ }
72
+ exports.BitTorrent = BitTorrent;
@@ -0,0 +1,26 @@
1
+ import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
+ import { DemuxProducer } from '../types/DemuxProducer';
4
+ /**
5
+ * C37.118 — IEEE Std C37.118.2 synchrophasor data transfer (PMU/PDC), typically TCP port 4712 and UDP
6
+ * port 4713. Every frame shares a 14-byte common header: SYNC (a 0xAA lead-in byte, then a byte holding
7
+ * a reserved bit, a 3-bit Frame Type — data / header / config-1 / config-2 / command / config-3 — and a
8
+ * 4-bit Version), a FRAMESIZE (total frame length including the check word), an IDCODE (data stream id),
9
+ * a SOC (second-of-century UNIX time), and a FRACSEC (an 8-bit time-quality byte plus a 24-bit fraction
10
+ * of second). It ends with a 2-byte CHK (CRC-CCITT over the whole frame). Everything is big-endian.
11
+ *
12
+ * The frame body between the header and the CHK is frame-type-specific (a configuration frame defines
13
+ * the data layout for the data frames that follow — cross-frame state, not a single-packet concern), so
14
+ * this codec keeps the body verbatim as `body` hex, bounded by FRAMESIZE, and keeps the CHK verbatim
15
+ * (never recomputed). A well-formed frame round-trips byte-for-byte.
16
+ */
17
+ export declare class C37118 extends BaseHeader {
18
+ #private;
19
+ get SCHEMA(): ProtocolJSONSchema;
20
+ readonly id: string;
21
+ readonly name: string;
22
+ readonly nickname: string;
23
+ readonly matchKeys: string[];
24
+ match(): boolean;
25
+ readonly demuxProducers: DemuxProducer[];
26
+ }
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.C37118 = void 0;
4
+ const BaseHeader_1 = require("../abstracts/BaseHeader");
5
+ const BufferToHex_1 = require("../helper/BufferToHex");
6
+ const HexToBuffer_1 = require("../helper/HexToBuffer");
7
+ const BufferToNumber_1 = require("../helper/BufferToNumber");
8
+ const NumberToBuffer_1 = require("../helper/NumberToBuffer");
9
+ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
10
+ /**
11
+ * C37.118 — IEEE Std C37.118.2 synchrophasor data transfer (PMU/PDC), typically TCP port 4712 and UDP
12
+ * port 4713. Every frame shares a 14-byte common header: SYNC (a 0xAA lead-in byte, then a byte holding
13
+ * a reserved bit, a 3-bit Frame Type — data / header / config-1 / config-2 / command / config-3 — and a
14
+ * 4-bit Version), a FRAMESIZE (total frame length including the check word), an IDCODE (data stream id),
15
+ * a SOC (second-of-century UNIX time), and a FRACSEC (an 8-bit time-quality byte plus a 24-bit fraction
16
+ * of second). It ends with a 2-byte CHK (CRC-CCITT over the whole frame). Everything is big-endian.
17
+ *
18
+ * The frame body between the header and the CHK is frame-type-specific (a configuration frame defines
19
+ * the data layout for the data frames that follow — cross-frame state, not a single-packet concern), so
20
+ * this codec keeps the body verbatim as `body` hex, bounded by FRAMESIZE, and keeps the CHK verbatim
21
+ * (never recomputed). A well-formed frame round-trips byte-for-byte.
22
+ */
23
+ class C37118 extends BaseHeader_1.BaseHeader {
24
+ constructor() {
25
+ super(...arguments);
26
+ this.id = 'c37118';
27
+ this.name = 'IEEE C37.118 Synchrophasor';
28
+ this.nickname = 'C37.118';
29
+ this.matchKeys = ['tcpport:4712', 'udpport:4713'];
30
+ //A leaf header — configuration/data frame bodies are stateful (a config frame defines later data
31
+ //frames), which belongs to a higher layer.
32
+ this.demuxProducers = [];
33
+ }
34
+ static #schemaCache;
35
+ get SCHEMA() {
36
+ return (C37118.#schemaCache ??= C37118.#buildSchema());
37
+ }
38
+ static #buildSchema() {
39
+ return {
40
+ type: 'object',
41
+ summary: 'C37.118 type=${sync.frameType} id=${idcode}',
42
+ properties: {
43
+ leadIn: this.fieldHex('leadIn', 0, 1, 'Lead-in (0xAA)'),
44
+ //SYNC byte 1 (MSB first): reserved bit, 3-bit Frame Type, 4-bit Version.
45
+ sync: {
46
+ type: 'object',
47
+ label: 'SYNC',
48
+ properties: {
49
+ reserved: {
50
+ type: 'integer', label: 'Reserved', minimum: 0, maximum: 1, hidden: true,
51
+ decode: function () { this.instance.sync.reserved.setValue(this.readBits(1, 1, 0, 1)); },
52
+ encode: function () { this.writeBits(1, 1, 0, 1, this.instance.sync.reserved.getValue(0)); }
53
+ },
54
+ frameType: {
55
+ type: 'integer', label: 'Frame Type', minimum: 0, maximum: 7,
56
+ decode: function () { this.instance.sync.frameType.setValue(this.readBits(1, 1, 1, 3)); },
57
+ encode: function () { this.writeBits(1, 1, 1, 3, this.instance.sync.frameType.getValue(0)); }
58
+ },
59
+ version: {
60
+ type: 'integer', label: 'Version', minimum: 0, maximum: 15,
61
+ decode: function () { this.instance.sync.version.setValue(this.readBits(1, 1, 4, 4)); },
62
+ encode: function () { this.writeBits(1, 1, 4, 4, this.instance.sync.version.getValue(1)); }
63
+ }
64
+ }
65
+ },
66
+ framesize: {
67
+ type: 'integer',
68
+ label: 'Frame Size',
69
+ minimum: 0,
70
+ maximum: 65535,
71
+ decode: function () {
72
+ this.instance.framesize.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)));
73
+ },
74
+ encode: function () {
75
+ //Honored when supplied (a crafted frame may lie); else derived from the actual
76
+ //body + CHK (FRAMESIZE is the total frame length: 14-byte header + body + CHK).
77
+ const provided = this.instance.framesize.getValue();
78
+ const value = (provided !== undefined && provided !== null)
79
+ ? provided
80
+ : 14 + (0, HexToBuffer_1.HexToBuffer)(this.instance.body.getValue('')).length + (0, HexToBuffer_1.HexToBuffer)(this.instance.chk.getValue('')).length;
81
+ this.instance.framesize.setValue(value);
82
+ this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(value));
83
+ }
84
+ },
85
+ idcode: this.fieldUInt('idcode', 4, 2, 'ID Code'),
86
+ soc: this.fieldUInt('soc', 6, 4, 'SOC (Second of Century)'),
87
+ timeQuality: this.fieldUInt('timeQuality', 10, 1, 'Time Quality'),
88
+ fractionOfSecond: {
89
+ type: 'integer',
90
+ label: 'Fraction of Second',
91
+ minimum: 0,
92
+ maximum: 16777215,
93
+ decode: function () { this.instance.fractionOfSecond.setValue(this.readBits(11, 3, 0, 24)); },
94
+ encode: function () { this.writeBits(11, 3, 0, 24, this.instance.fractionOfSecond.getValue(0)); }
95
+ },
96
+ //Frame-type-specific body, kept verbatim, and the trailing CHK. The body master reads
97
+ //FRAMESIZE (which includes the 2-byte CHK) to place the CHK at the end of the frame.
98
+ body: {
99
+ type: 'string',
100
+ label: 'Body',
101
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
102
+ decode: function () {
103
+ const remaining = this.packet.length - this.startPos;
104
+ const framesize = this.instance.framesize.getValue(0);
105
+ let frameEnd = framesize;
106
+ if (frameEnd > remaining || frameEnd < 16)
107
+ frameEnd = remaining;
108
+ const chkStart = frameEnd - 2;
109
+ if (chkStart >= 14) {
110
+ this.instance.body.setValue(chkStart > 14 ? (0, BufferToHex_1.BufferToHex)(this.readBytes(14, chkStart - 14)) : '');
111
+ this.instance.chk.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(chkStart, 2)));
112
+ }
113
+ else {
114
+ //Too short for a CHK: keep whatever remains as body, no check word.
115
+ this.instance.body.setValue(remaining > 14 ? (0, BufferToHex_1.BufferToHex)(this.readBytes(14, remaining - 14)) : '');
116
+ this.instance.chk.setValue('');
117
+ }
118
+ },
119
+ encode: function () {
120
+ const body = this.instance.body.getValue('');
121
+ const bodyBuffer = (0, HexToBuffer_1.HexToBuffer)(body);
122
+ if (bodyBuffer.length)
123
+ this.writeBytes(14, bodyBuffer);
124
+ const chk = this.instance.chk.getValue('');
125
+ if (chk)
126
+ this.writeBytes(14 + bodyBuffer.length, (0, HexToBuffer_1.HexToBuffer)(chk));
127
+ }
128
+ },
129
+ //The check word (CRC-CCITT), honored verbatim (never recomputed) — populated by the body
130
+ //master since its offset (FRAMESIZE - 2) is frame-length dependent.
131
+ chk: { type: 'string', label: 'Check', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX }
132
+ }
133
+ };
134
+ }
135
+ match() {
136
+ //C37.118 rides on TCP 4712 / UDP 4713. Require the common header + CHK (16 bytes) and the 0xAA
137
+ //SYNC lead-in signature so non-C37.118 traffic on those ports falls through to raw.
138
+ if (!this.prevCodecModule)
139
+ return false;
140
+ if (this.prevCodecModule.id !== 'tcp' && this.prevCodecModule.id !== 'udp')
141
+ return false;
142
+ if (this.packet.length - this.startPos < 16)
143
+ return false;
144
+ return this.readBytes(0, 1, true)[0] === 0xaa;
145
+ }
146
+ }
147
+ exports.C37118 = C37118;
@@ -0,0 +1,38 @@
1
+ import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
+ import { DemuxProducer } from '../types/DemuxProducer';
4
+ /**
5
+ * CAPWAP — Control And Provisioning of Wireless Access Points (RFC 5415), UDP port 5246 (control) and
6
+ * 5247 (data). Every CAPWAP message begins with a fixed 8-byte header whose layout is a preamble octet
7
+ * followed by tightly bit-packed fields:
8
+ *
9
+ * - Preamble (octet 0): Version (high nibble) + Type (low nibble). Type 0 = a CAPWAP header follows,
10
+ * Type 1 = the payload is a DTLS record (the header below is then not present).
11
+ * - Octets 1-3 (24 bits): HLEN (5 bits, the whole CAPWAP header length in units of 4 octets),
12
+ * RID (5 bits, Radio ID), WBID (5 bits, Wireless Binding ID), then the flag bits T, F, L, W, M, K
13
+ * (1 bit each) and a 3-bit reserved Flags remainder.
14
+ * - Octets 4-5: Fragment ID (16 bits).
15
+ * - Octets 6-7: Fragment Offset (13 bits) + a 3-bit reserved field.
16
+ *
17
+ * When the M/W flags are set the header carries optional Radio MAC Address / Wireless Specific
18
+ * Information fields; HLEN delimits the whole header (HLEN × 4 octets), after which the payload begins
19
+ * (the control-plane Control Header + message elements, or the tunneled 802.3/802.11 data frame).
20
+ *
21
+ * This is the minimal, byte-faithful slice: the preamble and every bit-packed field are modelled so an
22
+ * editor can see/round-trip them, the optional per-flag header fields are kept verbatim as
23
+ * `headerRemainder` hex (bounded by HLEN × 4), and everything after the header is kept verbatim as
24
+ * `payload` hex (bounded by the UDP datagram so a retained trailer is not absorbed). Sub-decoding the
25
+ * Control Header / message elements or the tunneled frame is deferred, so CAPWAP is effectively a leaf.
26
+ * HLEN is honored verbatim when supplied (a crafted header may lie) else derived from the header bytes;
27
+ * a well-formed message round-trips byte-for-byte.
28
+ */
29
+ export declare class CAPWAP extends BaseHeader {
30
+ #private;
31
+ get SCHEMA(): ProtocolJSONSchema;
32
+ readonly id: string;
33
+ readonly name: string;
34
+ readonly nickname: string;
35
+ readonly matchKeys: string[];
36
+ match(): boolean;
37
+ readonly demuxProducers: DemuxProducer[];
38
+ }