From be73b17d46fd22d3af367dfaf684a7a68d3df029 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Wed, 23 Mar 2022 16:17:58 -0400 Subject: [PATCH] RTU linking and requesting advertisement --- rtu/startup.lua | 8 ++++++-- scada-common/comms.lua | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/rtu/startup.lua b/rtu/startup.lua index 483aaee..ce6adb8 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -179,11 +179,15 @@ while true do end elseif event == "modem_message" then -- got a packet - + local link_ref = { linked = linked } local packet = rtu_comms.parse_packet(p1, p2, p3, p4, p5) - rtu_comms.handle_packet(packet) + rtu_comms.handle_packet(packet, units, link_ref) + + -- if linked, stop sending advertisements + linked = link_ref.linked elseif event == "terminate" then + print_ts("Exiting...\n") return end end diff --git a/scada-common/comms.lua b/scada-common/comms.lua index dfea4bf..bbcedde 100644 --- a/scada-common/comms.lua +++ b/scada-common/comms.lua @@ -34,8 +34,9 @@ RPLC_LINKING = { SCADA_MGMT_TYPES = { PING = 0, -- generic ping SV_HEARTBEAT = 1, -- supervisor heartbeat - RTU_HEARTBEAT = 2, -- RTU heartbeat - RTU_ADVERT = 3 -- RTU capability advertisement + REMOTE_LINKED = 2, -- remote device linked + RTU_ADVERT = 3, -- RTU capability advertisement + RTU_HEARTBEAT = 4, -- RTU heartbeat } RTU_ADVERT_TYPES = { @@ -203,7 +204,7 @@ function rtu_comms(modem, local_port, server_port) return pkt end - local handle_packet = function(packet, units) + local handle_packet = function(packet, units, ref) if packet ~= nil then local protocol = packet.scada_frame.protocol() @@ -222,6 +223,16 @@ function rtu_comms(modem, local_port, server_port) end elseif protocol == PROTOCOLS.SCADA_MGMT then -- SCADA management packet + if packet.type == SCADA_MGMT_TYPES.REMOTE_LINKED then + -- acknowledgement + ref.linked = true + elseif packet.type == SCADA_MGMT_TYPES.RTU_ADVERT then + -- request for capabilities again + send_advertisement(units) + else + -- not supported + log._warning("RTU got unexpected SCADA message type " .. packet.type, true) + end else -- should be unreachable assuming packet is from parse_packet() log._error("Illegal packet type " .. protocol, true)