You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2021/05/21 23:51:28 UTC

[mynewt-core] branch master updated: net/osdp: add a polling timeout for non-secure session - Raise a timeout flag if the peripheral device does not hear from the control panel for said time interval

This is an automated email from the ASF dual-hosted git repository.

vipulrahane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 453459d  net/osdp: add a polling timeout for non-secure session - Raise a timeout flag if the peripheral device does not hear from the control panel for said time interval
     new 2bde4bd  Merge pull request #2600 from vikrant-proxy/osdp/nonsec
453459d is described below

commit 453459db981857914a09e5eda5617d2c43944dd3
Author: Vikrant More <vi...@proxy.com>
AuthorDate: Fri May 21 13:41:44 2021 -0700

    net/osdp: add a polling timeout for non-secure session
    - Raise a timeout flag if the peripheral device does not hear from the control panel for said time interval
---
 net/osdp/include/osdp/osdp.h        |  5 +++++
 net/osdp/include/osdp/osdp_common.h |  1 +
 net/osdp/src/osdp_common.c          |  7 +++++--
 net/osdp/src/osdp_pd.c              | 31 +++++++++++++++++++++++--------
 net/osdp/syscfg.yml                 |  4 ++++
 5 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/net/osdp/include/osdp/osdp.h b/net/osdp/include/osdp/osdp.h
index 491e1ce..d61e9fa 100644
--- a/net/osdp/include/osdp/osdp.h
+++ b/net/osdp/include/osdp/osdp.h
@@ -43,6 +43,11 @@ extern "C" {
 #define OSDP_FLAG_INSTALL_MODE         0x00020000
 
 /**
+ * @brief When set, the PD will not set up secure mode capability.
+ */
+#define OSDP_FLAG_NON_SECURE_MODE      0x00040000
+
+/**
  * @brief Various PD capability function codes.
  */
 enum osdp_pd_cap_function_code_e {
diff --git a/net/osdp/include/osdp/osdp_common.h b/net/osdp/include/osdp/osdp_common.h
index ab50375..f4a014a 100644
--- a/net/osdp/include/osdp/osdp_common.h
+++ b/net/osdp/include/osdp/osdp_common.h
@@ -144,6 +144,7 @@ union osdp_ephemeral_data {
 #define PD_FLAG_CHN_SHARED      0x00000400 /* PD's channel is shared */
 #define PD_FLAG_PKT_SKIP_MARK   0x00000800 /* CONFIG_OSDP_SKIP_MARK_BYTE */
 #define PD_FLAG_PKT_HAS_MARK    0x00001000 /* Packet has mark byte */
+#define PD_FLAG_CP_POLL_ACTIVE  0x00002000 /* PD is getting polled by CP, for non-secure mode */
 
 #define osdp_dump(b, l, f, ...) hexdump(b, l, f, __VA_ARGS__)
 
diff --git a/net/osdp/src/osdp_common.c b/net/osdp/src/osdp_common.c
index 4c3b936..3d749a4 100644
--- a/net/osdp/src/osdp_common.c
+++ b/net/osdp/src/osdp_common.c
@@ -199,8 +199,11 @@ osdp_get_status_mask(osdp_t *ctx)
             }
         }
     } else {
-        /* PD is stateless */
-        mask = 1;
+        /* PD state is either online or offline based on whether it got polled from CP */
+        pd = TO_PD(ctx, 0);
+        if (ISSET_FLAG(pd, PD_FLAG_CP_POLL_ACTIVE)) {
+            mask = 1;
+        }
     }
 
     return mask;
diff --git a/net/osdp/src/osdp_pd.c b/net/osdp/src/osdp_pd.c
index 6efe78d..3c9baf0 100644
--- a/net/osdp/src/osdp_pd.c
+++ b/net/osdp/src/osdp_pd.c
@@ -61,11 +61,6 @@ static struct osdp_pd_cap osdp_pd_cap[] = {
         1, /* The PD supports the 16-bit CRC-16 mode */
         0, /* N/A */
     },
-    {
-        OSDP_PD_CAP_COMMUNICATION_SECURITY,
-        1, /* (Bit-0) AES128 support */
-        0, /* N/A */
-    },
     { -1, 0, 0 } /* Sentinel */
 };
 
@@ -356,6 +351,7 @@ pd_decode_command(struct osdp_pd *pd, uint8_t *buf, int len)
             pd->reply_id = REPLY_ACK;
         }
         ret = OSDP_PD_ERR_NONE;
+        SET_FLAG(pd, PD_FLAG_CP_POLL_ACTIVE);
         break;
     case CMD_LSTAT:
         ASSERT_LENGTH(len, CMD_LSTAT_DATA_LEN);
@@ -999,6 +995,12 @@ osdp_update(struct osdp_pd *pd)
             OSDP_LOG_INFO("PD SC session timeout!\n");
             CLEAR_FLAG(pd, PD_FLAG_SC_ACTIVE);
         }
+        /* When secure mode is inactive check if CP is polling */
+        if (ISSET_FLAG(pd, PD_FLAG_CP_POLL_ACTIVE) &&
+            osdp_millis_since(pd->tstamp) > MYNEWT_VAL(OSDP_PD_IDLE_TIMEOUT_MS)) {
+            OSDP_LOG_INFO("PD CP-poll timeout!\n");
+            CLEAR_FLAG(pd, PD_FLAG_CP_POLL_ACTIVE);
+        }
         ret = pd->channel.recv(pd->channel.data, pd->rx_buf,
               sizeof(pd->rx_buf));
         if (ret <= 0) {
@@ -1110,16 +1112,29 @@ osdp_pd_setup(struct osdp_ctx *osdp_ctx, osdp_pd_info_t *info, uint8_t *scbk)
             OSDP_LOG_ERROR("SCBK must be provided in ENFORCE_SECURE\n");
             goto error;
         }
-        OSDP_LOG_WARN("SCBK not provided. PD is in INSTALL_MODE\n");
-        SET_FLAG(pd, OSDP_FLAG_INSTALL_MODE);
+        if (!ISSET_FLAG(pd, OSDP_FLAG_NON_SECURE_MODE)) {
+            OSDP_LOG_WARN("SCBK not provided. PD is in INSTALL_MODE\n");
+            SET_FLAG(pd, OSDP_FLAG_INSTALL_MODE);
+        } else {
+            OSDP_LOG_WARN("Setting up in non-secure mode\n");
+            /* Non secure mode */
+        }
     } else {
         memcpy(pd->sc.scbk, scbk, 16);
     }
-    SET_FLAG(pd, PD_FLAG_SC_CAPABLE);
+
+    /* Set secure capability based on non-secure flag */
+    if (!ISSET_FLAG(pd, OSDP_FLAG_NON_SECURE_MODE)) {
+        OSDP_LOG_INFO("PD is SC capable!\n");
+        SET_FLAG(pd, PD_FLAG_SC_CAPABLE);
+    }
+
     if (IS_ENABLED(CONFIG_OSDP_SKIP_MARK_BYTE)) {
         SET_FLAG(pd, PD_FLAG_PKT_SKIP_MARK);
     }
+    /* Set capabilities based on application */
     osdp_pd_set_attributes(pd, info->cap, &info->id);
+    /* Set implicit capabilities */
     osdp_pd_set_attributes(pd, osdp_pd_cap, NULL);
 
     SET_FLAG(pd, PD_FLAG_PD_MODE); /* used in checks in phy */
diff --git a/net/osdp/syscfg.yml b/net/osdp/syscfg.yml
index 004ae3f..33674a7 100644
--- a/net/osdp/syscfg.yml
+++ b/net/osdp/syscfg.yml
@@ -56,6 +56,10 @@ syscfg.defs:
         value: 400
         description: 'Timeout in milliseconds for secure mode session.'
 
+    OSDP_PD_IDLE_TIMEOUT_MS:
+        value: 800
+        description: 'Idle line timeout. PD has not heard a POLL from CP for this duration.'
+
     OSDP_DEVICE_LOCK_TIMEOUT_MS:
         value: 20
         description: 'Event/Command mutex timeout in milliseconds'