From 48c80f5cae3fc59414e896d89127304ca084a4f1 Mon Sep 17 00:00:00 2001 From: andreas karlsson Date: Sun, 19 Jun 2022 10:51:51 +0200 Subject: [PATCH] Impove SM validation for input- ouput only slaves Re-add always verify SM length Add validation of SM disabled, don't allow master to activate or set a length if disabled. Add validation of SM enabled, don't allow master to set a length and de-activate. --- soes/esc.c | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/soes/esc.c b/soes/esc.c index 07c9a04..706edd6 100644 --- a/soes/esc.c +++ b/soes/esc.c @@ -697,15 +697,32 @@ uint8_t ESC_checkSM23 (uint8_t state) /* fail state change */ return (ESCpreop | ESCerror); } - /* If length > 0 check run-time settings */ - else if ((ESCvar.ESC_SM2_sml > 0) && - ((etohs (SM->Length) != ESCvar.ESC_SM2_sml) || - !(SM->ActESC & ESC_SM2_act))) + /* Check run-time settings */ + /* Check length */ + else if (etohs (SM->Length) != ESCvar.ESC_SM2_sml) { ESCvar.SMtestresult = SMRESULT_ERRSM2; /* fail state change */ return (ESCpreop | ESCerror); } + /* SM disabled and (SM activated or length > 0) set by master */ + else if (((ESC_SM2_act & ESCREG_SYNC_ACT_ACTIVATED) == 0) && + ((SM->ActESC & ESCREG_SYNC_ACT_ACTIVATED) || (etohs (SM->Length) > 0))) + { + ESCvar.SMtestresult = SMRESULT_ERRSM2; + /* fail state change */ + return (ESCpreop | ESCerror); + } + /* SM enabled and (length > 0 but SM disabled) set by master */ + else if (((ESC_SM2_act & ESCREG_SYNC_ACT_ACTIVATED) > 0) && + ((SM->ActESC & ESCREG_SYNC_ACT_ACTIVATED) == 0) && + (etohs (SM->Length) > 0)) + { + ESCvar.SMtestresult = SMRESULT_ERRSM2; + /* fail state change */ + return (ESCpreop | ESCerror); + } + if ((ESC_SM2_sma + (etohs (SM->Length) * 3)) > ESC_SM3_sma) { ESCvar.SMtestresult = SMRESULT_ERRSM2; @@ -723,10 +740,26 @@ uint8_t ESC_checkSM23 (uint8_t state) /* fail state change */ return (ESCpreop | ESCerror); } - /* If length > 0 check run-time settings */ - else if ((ESCvar.ESC_SM3_sml > 0) && - ((etohs (SM->Length) != ESCvar.ESC_SM3_sml) || - !(SM->ActESC & ESC_SM3_act))) + /* Check run-time settings */ + /* Check length */ + else if (etohs (SM->Length) != ESCvar.ESC_SM3_sml) + { + ESCvar.SMtestresult = SMRESULT_ERRSM3; + /* fail state change */ + return (ESCpreop | ESCerror); + } + /* SM disabled and (SM activated or length > 0) set by master */ + else if (((ESC_SM3_act & ESCREG_SYNC_ACT_ACTIVATED) == 0) && + ((SM->ActESC & ESCREG_SYNC_ACT_ACTIVATED) || (etohs (SM->Length) > 0))) + { + ESCvar.SMtestresult = SMRESULT_ERRSM3; + /* fail state change */ + return (ESCpreop | ESCerror); + } + /* SM enabled and (length > 0 but SM disabled) set by master */ + else if (((ESC_SM3_act & ESCREG_SYNC_ACT_ACTIVATED) > 0) && + ((SM->ActESC & ESCREG_SYNC_ACT_ACTIVATED) == 0) && + (etohs (SM->Length) > 0)) { ESCvar.SMtestresult = SMRESULT_ERRSM3; /* fail state change */