Skip to content

Commit

Permalink
mgmt/osdp: Rename cmd_data as ephemeral_data
Browse files Browse the repository at this point in the history
Since cmd_data member is used by both commands and events to store the
contents of current transaction, rename it to ephemeral_data which
better reflects the purpose of the variable.

Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha authored and stephanosio committed Jan 27, 2023
1 parent 67ca254 commit a369bf7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions subsys/mgmt/osdp/src/osdp_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions subsys/mgmt/osdp/src/osdp_cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 11 additions & 11 deletions subsys/mgmt/osdp/src/osdp_pd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -446,15 +446,15 @@ 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;
}

if (ret == OSDP_PD_ERR_GENERIC) {
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;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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 */
Expand Down
18 changes: 9 additions & 9 deletions subsys/mgmt/osdp/src/osdp_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
}
}
Expand All @@ -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 */
Expand All @@ -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 */
Expand Down

0 comments on commit a369bf7

Please sign in to comment.