PLC comms packet length checks

This commit is contained in:
Mikayla Fischler 2022-04-29 09:07:29 -04:00
parent d688f9a1c6
commit 4d5cbcf475
2 changed files with 80 additions and 64 deletions

View File

@ -431,6 +431,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
if self.linked then if self.linked then
if packet.type == RPLC_TYPES.KEEP_ALIVE then if packet.type == RPLC_TYPES.KEEP_ALIVE then
-- keep alive request received, echo back -- keep alive request received, echo back
if packet.length == 1 then
local timestamp = packet.data[1] local timestamp = packet.data[1]
local trip_time = util.time() - timestamp local trip_time = util.time() - timestamp
@ -441,8 +442,12 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
-- log._debug("RPLC RTT = ".. trip_time .. "ms") -- log._debug("RPLC RTT = ".. trip_time .. "ms")
_send_keep_alive_ack(timestamp) _send_keep_alive_ack(timestamp)
else
log._debug(log_header .. "RPLC keep alive packet length mismatch")
end
elseif packet.type == RPLC_TYPES.LINK_REQ then elseif packet.type == RPLC_TYPES.LINK_REQ then
-- link request confirmation -- link request confirmation
if packet.length == 1 then
log._debug("received unsolicited link request response") log._debug("received unsolicited link request response")
local link_ack = packet.data[1] local link_ack = packet.data[1]
@ -465,6 +470,9 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
end end
self.linked = link_ack == RPLC_LINKING.ALLOW self.linked = link_ack == RPLC_LINKING.ALLOW
else
log._debug(log_header .. "RPLC link req packet length mismatch")
end
elseif packet.type == RPLC_TYPES.MEK_STRUCT then elseif packet.type == RPLC_TYPES.MEK_STRUCT then
-- request for physical structure -- request for physical structure
_send_struct() _send_struct()
@ -482,6 +490,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
_send_ack(packet.type, self.reactor.__p_is_ok()) _send_ack(packet.type, self.reactor.__p_is_ok())
elseif packet.type == RPLC_TYPES.MEK_BURN_RATE then elseif packet.type == RPLC_TYPES.MEK_BURN_RATE then
-- set the burn rate -- set the burn rate
if packet.length == 1 then
local success = false local success = false
local burn_rate = packet.data[1] local burn_rate = packet.data[1]
local max_burn_rate = self.max_burn_rate local max_burn_rate = self.max_burn_rate
@ -501,6 +510,9 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
end end
_send_ack(packet.type, success) _send_ack(packet.type, success)
else
log._debug(log_header .. "RPLC set burn rate packet length mismatch")
end
elseif packet.type == RPLC_TYPES.ISS_CLEAR then elseif packet.type == RPLC_TYPES.ISS_CLEAR then
-- clear the ISS status -- clear the ISS status
iss.reset() iss.reset()
@ -510,6 +522,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
end end
elseif packet.type == RPLC_TYPES.LINK_REQ then elseif packet.type == RPLC_TYPES.LINK_REQ then
-- link request confirmation -- link request confirmation
if packet.length == 1 then
local link_ack = packet.data[1] local link_ack = packet.data[1]
if link_ack == RPLC_LINKING.ALLOW then if link_ack == RPLC_LINKING.ALLOW then
@ -535,6 +548,9 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
end end
self.linked = link_ack == RPLC_LINKING.ALLOW self.linked = link_ack == RPLC_LINKING.ALLOW
else
log._debug(log_header .. "RPLC link req packet length mismatch")
end
else else
log._debug("discarding non-link packet before linked") log._debug("discarding non-link packet before linked")
end end

View File

@ -12,7 +12,7 @@ os.loadAPI("config.lua")
os.loadAPI("plc.lua") os.loadAPI("plc.lua")
os.loadAPI("threads.lua") os.loadAPI("threads.lua")
local R_PLC_VERSION = "alpha-v0.4.7" local R_PLC_VERSION = "alpha-v0.4.8"
local print = util.print local print = util.print
local println = util.println local println = util.println