diff --git a/subsys/mgmt/osdp/src/osdp_common.h b/subsys/mgmt/osdp/src/osdp_common.h index 548dd514c9ab..3b8648a7d81e 100644 --- a/subsys/mgmt/osdp/src/osdp_common.h +++ b/subsys/mgmt/osdp/src/osdp_common.h @@ -35,7 +35,6 @@ (uint32_t)((1 << ((ctx)->num_pd)) - 1) #define AES_PAD_LEN(x) ((x + 16 - 1) & (~(16 - 1))) #define NUM_PD(ctx) ((ctx)->num_pd) -#define OSDP_COMMAND_DATA_MAX_LEN sizeof(struct osdp_cmd) /** * @brief OSDP reserved commands @@ -318,6 +317,7 @@ union osdp_ephemeral_data { struct osdp_cmd cmd; struct osdp_event event; }; +#define OSDP_EPHEMERAL_DATA_MAX_LEN sizeof(union osdp_ephemeral_data) /** * @brief PD capability structure. Each PD capability has a 3 byte @@ -435,7 +435,7 @@ struct osdp_pd { int cmd_id; int reply_id; - uint8_t cmd_data[OSDP_COMMAND_DATA_MAX_LEN]; + uint8_t ephemeral_data[OSDP_EPHEMERAL_DATA_MAX_LEN]; struct osdp_channel channel; diff --git a/subsys/mgmt/osdp/src/osdp_cp.c b/subsys/mgmt/osdp/src/osdp_cp.c index 3fd57035f0f6..1173dfc44e9b 100644 --- a/subsys/mgmt/osdp/src/osdp_cp.c +++ b/subsys/mgmt/osdp/src/osdp_cp.c @@ -181,7 +181,7 @@ static int cp_build_command(struct osdp_pd *pd, uint8_t *buf, int max_len) break; case CMD_OUT: assert_buf_len(CMD_OUT_LEN, max_len); - cmd = (struct osdp_cmd *)pd->cmd_data; + cmd = (struct osdp_cmd *)pd->ephemeral_data; buf[len++] = pd->cmd_id; buf[len++] = cmd->output.output_no; buf[len++] = cmd->output.control_code; @@ -191,7 +191,7 @@ static int cp_build_command(struct osdp_pd *pd, uint8_t *buf, int max_len) break; case CMD_LED: assert_buf_len(CMD_LED_LEN, max_len); - cmd = (struct osdp_cmd *)pd->cmd_data; + cmd = (struct osdp_cmd *)pd->ephemeral_data; buf[len++] = pd->cmd_id; buf[len++] = cmd->led.reader; buf[len++] = cmd->led.led_number; @@ -213,7 +213,7 @@ static int cp_build_command(struct osdp_pd *pd, uint8_t *buf, int max_len) break; case CMD_BUZ: assert_buf_len(CMD_BUZ_LEN, max_len); - cmd = (struct osdp_cmd *)pd->cmd_data; + cmd = (struct osdp_cmd *)pd->ephemeral_data; buf[len++] = pd->cmd_id; buf[len++] = cmd->buzzer.reader; buf[len++] = cmd->buzzer.control_code; @@ -223,7 +223,7 @@ static int cp_build_command(struct osdp_pd *pd, uint8_t *buf, int max_len) ret = 0; break; case CMD_TEXT: - cmd = (struct osdp_cmd *)pd->cmd_data; + cmd = (struct osdp_cmd *)pd->ephemeral_data; assert_buf_len(CMD_TEXT_LEN + cmd->text.length, max_len); buf[len++] = pd->cmd_id; buf[len++] = cmd->text.reader; @@ -239,7 +239,7 @@ static int cp_build_command(struct osdp_pd *pd, uint8_t *buf, int max_len) break; case CMD_COMSET: assert_buf_len(CMD_COMSET_LEN, max_len); - cmd = (struct osdp_cmd *)pd->cmd_data; + cmd = (struct osdp_cmd *)pd->ephemeral_data; buf[len++] = pd->cmd_id; buf[len++] = cmd->comset.address; buf[len++] = BYTE_0(cmd->comset.baud_rate); @@ -684,7 +684,7 @@ static int cp_phy_state_update(struct osdp_pd *pd) break; } pd->cmd_id = cmd->id; - memcpy(pd->cmd_data, cmd, sizeof(struct osdp_cmd)); + memcpy(pd->ephemeral_data, cmd, sizeof(struct osdp_cmd)); cp_cmd_free(pd, cmd); /* fall-thru */ case OSDP_CP_PHY_STATE_SEND_CMD: diff --git a/subsys/mgmt/osdp/src/osdp_pd.c b/subsys/mgmt/osdp/src/osdp_pd.c index cb4ad77ae92e..9114911c2b46 100644 --- a/subsys/mgmt/osdp/src/osdp_pd.c +++ b/subsys/mgmt/osdp/src/osdp_pd.c @@ -172,7 +172,7 @@ static int pd_translate_event(struct osdp_pd *pd, struct osdp_event *event) /* POLL command cannot fail even when there are errors here */ return REPLY_ACK; } - memcpy(pd->cmd_data, event, sizeof(struct osdp_event)); + memcpy(pd->ephemeral_data, event, sizeof(struct osdp_event)); return reply_code; } @@ -183,7 +183,7 @@ static bool do_command_callback(struct osdp_pd *pd, struct osdp_cmd *cmd) ret = pd->command_callback(pd->command_callback_arg, cmd); if (ret != 0) { pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_RECORD; + pd->ephemeral_data[0] = OSDP_PD_NAK_RECORD; return false; } return true; @@ -371,7 +371,7 @@ static int pd_decode_command(struct osdp_pd *pd, uint8_t *buf, int len) ret = OSDP_PD_ERR_REPLY; break; } - memcpy(pd->cmd_data, &cmd, sizeof(struct osdp_cmd)); + memcpy(pd->ephemeral_data, &cmd, sizeof(struct osdp_cmd)); pd->reply_id = REPLY_COM; ret = OSDP_PD_ERR_NONE; break; @@ -386,7 +386,7 @@ static int pd_decode_command(struct osdp_pd *pd, uint8_t *buf, int len) */ if (!sc_is_active(pd)) { pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_SC_COND; + pd->ephemeral_data[0] = OSDP_PD_NAK_SC_COND; LOG_ERR("Keyset with SC inactive"); break; } @@ -417,7 +417,7 @@ static int pd_decode_command(struct osdp_pd *pd, uint8_t *buf, int len) int tmp = OSDP_PD_CAP_COMMUNICATION_SECURITY; if (pd->cap[tmp].compliance_level == 0) { pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_SC_UNSUP; + pd->ephemeral_data[0] = OSDP_PD_NAK_SC_UNSUP; break; } if (len != CMD_CHLNG_DATA_LEN) { @@ -446,7 +446,7 @@ static int pd_decode_command(struct osdp_pd *pd, uint8_t *buf, int len) default: LOG_ERR("Unknown CMD(%02x)", pd->cmd_id); pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_CMD_UNKNOWN; + pd->ephemeral_data[0] = OSDP_PD_NAK_CMD_UNKNOWN; return OSDP_PD_ERR_REPLY; } @@ -454,7 +454,7 @@ static int pd_decode_command(struct osdp_pd *pd, uint8_t *buf, int len) LOG_ERR("Failed to decode command: CMD(%02x) Len:%d ret:%d", pd->cmd_id, len, ret); pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_CMD_LEN; + pd->ephemeral_data[0] = OSDP_PD_NAK_CMD_LEN; ret = OSDP_PD_ERR_REPLY; } @@ -559,7 +559,7 @@ static int pd_build_reply(struct osdp_pd *pd, uint8_t *buf, int max_len) * TODO: Persist pd->address and pd->baud_rate via * subsys/settings */ - cmd = (struct osdp_cmd *)pd->cmd_data; + cmd = (struct osdp_cmd *)pd->ephemeral_data; buf[len++] = pd->reply_id; buf[len++] = cmd->comset.address; buf[len++] = BYTE_0(cmd->comset.baud_rate); @@ -576,7 +576,7 @@ static int pd_build_reply(struct osdp_pd *pd, uint8_t *buf, int max_len) case REPLY_NAK: assert_buf_len(REPLY_NAK_LEN, max_len); buf[len++] = pd->reply_id; - buf[len++] = pd->cmd_data[0]; + buf[len++] = pd->ephemeral_data[0]; ret = OSDP_PD_ERR_NONE; break; #ifdef CONFIG_OSDP_SC_ENABLED @@ -727,12 +727,12 @@ static int pd_receve_packet(struct osdp_pd *pd) } pd->reply_id = 0; /* reset past reply ID so phy can send NAK */ - pd->cmd_data[0] = 0; /* reset past NAK reason */ + pd->ephemeral_data[0] = 0; /* reset past NAK reason */ ret = osdp_phy_decode_packet(pd, pd->rx_buf, pd->rx_buf_len); if (ret == OSDP_ERR_PKT_FMT) { if (pd->reply_id != 0) { pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_RECORD; + pd->ephemeral_data[0] = OSDP_PD_NAK_RECORD; return OSDP_PD_ERR_REPLY; } return OSDP_PD_ERR_GENERIC; /* fatal errors */ diff --git a/subsys/mgmt/osdp/src/osdp_phy.c b/subsys/mgmt/osdp/src/osdp_phy.c index f3b8bf78ed28..b63d4b4420f3 100644 --- a/subsys/mgmt/osdp/src/osdp_phy.c +++ b/subsys/mgmt/osdp/src/osdp_phy.c @@ -272,14 +272,14 @@ int osdp_phy_decode_packet(struct osdp_pd *pd, uint8_t *buf, int len) */ LOG_ERR("seq-repeat/reply-resend feature not supported!"); pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_SEQ_NUM; + pd->ephemeral_data[0] = OSDP_PD_NAK_SEQ_NUM; return OSDP_ERR_PKT_FMT; } comp = osdp_phy_get_seq_number(pd, is_pd_mode(pd)); if (comp != cur && !ISSET_FLAG(pd, PD_FLAG_SKIP_SEQ_CHECK)) { LOG_ERR("packet seq mismatch %d/%d", comp, cur); pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_SEQ_NUM; + pd->ephemeral_data[0] = OSDP_PD_NAK_SEQ_NUM; return OSDP_ERR_PKT_FMT; } len -= sizeof(struct osdp_packet_header); /* consume header */ @@ -291,7 +291,7 @@ int osdp_phy_decode_packet(struct osdp_pd *pd, uint8_t *buf, int len) if (comp != cur) { LOG_ERR("invalid crc 0x%04x/0x%04x", comp, cur); pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_MSG_CHK; + pd->ephemeral_data[0] = OSDP_PD_NAK_MSG_CHK; return OSDP_ERR_PKT_FMT; } mac_offset = pkt_len - 4 - 2; @@ -301,7 +301,7 @@ int osdp_phy_decode_packet(struct osdp_pd *pd, uint8_t *buf, int len) if (comp != buf[len - 1]) { LOG_ERR("invalid checksum %02x/%02x", comp, cur); pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_MSG_CHK; + pd->ephemeral_data[0] = OSDP_PD_NAK_MSG_CHK; return OSDP_ERR_PKT_FMT; } mac_offset = pkt_len - 4 - 1; @@ -318,13 +318,13 @@ int osdp_phy_decode_packet(struct osdp_pd *pd, uint8_t *buf, int len) if (is_pd_mode(pd) && !sc_is_capable(pd)) { LOG_ERR("PD is not SC capable"); pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_SC_UNSUP; + pd->ephemeral_data[0] = OSDP_PD_NAK_SC_UNSUP; return OSDP_ERR_PKT_FMT; } if (pkt->data[1] < SCS_11 || pkt->data[1] > SCS_18) { LOG_ERR("Invalid SB Type"); pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_SC_COND; + pd->ephemeral_data[0] = OSDP_PD_NAK_SC_COND; return OSDP_ERR_PKT_FMT; } if (pkt->data[1] == SCS_11 || pkt->data[1] == SCS_13) { @@ -346,7 +346,7 @@ int osdp_phy_decode_packet(struct osdp_pd *pd, uint8_t *buf, int len) if (sc_is_active(pd)) { LOG_ERR("Received plain-text message in SC"); pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_SC_COND; + pd->ephemeral_data[0] = OSDP_PD_NAK_SC_COND; return OSDP_ERR_PKT_FMT; } } @@ -360,7 +360,7 @@ int osdp_phy_decode_packet(struct osdp_pd *pd, uint8_t *buf, int len) if (memcmp(buf + 1 + mac_offset, mac, 4) != 0) { LOG_ERR("Invalid MAC; discarding SC"); pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_SC_COND; + pd->ephemeral_data[0] = OSDP_PD_NAK_SC_COND; return OSDP_ERR_PKT_FMT; } len -= 4; /* consume MAC */ @@ -381,7 +381,7 @@ int osdp_phy_decode_packet(struct osdp_pd *pd, uint8_t *buf, int len) if (len <= 0) { LOG_ERR("Failed at decrypt; discarding SC"); pd->reply_id = REPLY_NAK; - pd->cmd_data[0] = OSDP_PD_NAK_SC_COND; + pd->ephemeral_data[0] = OSDP_PD_NAK_SC_COND; return OSDP_ERR_PKT_FMT; } len += 1; /* put back cmd/reply ID */