From 9c8948a0f8da71ca6ccc4301cbde612f33205c25 Mon Sep 17 00:00:00 2001 From: Samuel Gouraud Date: Wed, 14 Jun 2023 17:50:28 +0200 Subject: [PATCH] save PD Local Status --- src/osdp_common.h | 2 ++ src/osdp_pd.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/osdp_common.h b/src/osdp_common.h index 773164f5..e6888f48 100644 --- a/src/osdp_common.h +++ b/src/osdp_common.h @@ -172,6 +172,8 @@ union osdp_ephemeral_data { /* PD State Flags */ #define PD_FLAG_SC_CAPABLE BIT(0) /* PD secure channel capable */ +#define PD_FLAG_TAMPER BIT(1) /* local tamper status */ +#define PD_FLAG_POWER BIT(2) /* local power status */ #define PD_FLAG_R_TAMPER BIT(3) /* remote tamper status */ #define PD_FLAG_AWAIT_RESP BIT(4) /* set after command is sent */ #define PD_FLAG_SKIP_SEQ_CHECK BIT(5) /* disable seq checks (debug) */ diff --git a/src/osdp_pd.c b/src/osdp_pd.c index 484b543d..02b4751c 100644 --- a/src/osdp_pd.c +++ b/src/osdp_pd.c @@ -163,6 +163,16 @@ static int pd_translate_event(struct osdp_pd *pd, struct osdp_event *event) reply_code = REPLY_MFGREP; break; case OSDP_EVENT_STATUS: + if (event->status.tamper == 1) { + SET_FLAG(pd, PD_FLAG_TAMPER); + } else { + CLEAR_FLAG(pd, PD_FLAG_TAMPER); + } + if (event->status.power == 1) { + SET_FLAG(pd, PD_FLAG_POWER); + } else { + CLEAR_FLAG(pd, PD_FLAG_POWER); + } reply_code = REPLY_LSTATR; break; default: @@ -738,10 +748,9 @@ static int pd_build_reply(struct osdp_pd *pd, uint8_t *buf, int max_len) } case REPLY_LSTATR: assert_buf_len(REPLY_LSTATR_LEN, max_len); - event = (struct osdp_event *)pd->ephemeral_data; buf[len++] = pd->reply_id; - buf[len++] = event->status.tamper; - buf[len++] = event->status.power; + buf[len++] = ISSET_FLAG(pd, PD_FLAG_TAMPER); + buf[len++] = ISSET_FLAG(pd, PD_FLAG_POWER); ret = OSDP_PD_ERR_NONE; break; case REPLY_RSTATR: