Skip to content

Commit 0d229b5

Browse files
committed
CP: Don't update sequence number on command retry probes
Fixes: #274 Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
1 parent 14c2111 commit 0d229b5

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/osdp_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ struct osdp_pd {
413413
int state; /* FSM state (CP mode only) */
414414
int phy_state; /* phy layer FSM state (CP mode only) */
415415
int phy_retry_count; /* command retry counter */
416+
int phy_tx_seq; /* seq number embedded in last TX packet */
416417
uint32_t wait_ms; /* wait time in MS to retry communication */
417418
tick_t tstamp; /* Last POLL command issued time in ticks */
418419
tick_t sc_tstamp; /* Last received secure reply time in ticks */

src/osdp_cp.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,12 @@ static int cp_phy_state_update(struct osdp_pd *pd)
814814
pd->phy_state = OSDP_CP_PHY_STATE_SEND_CMD;
815815
__fallthrough;
816816
case OSDP_CP_PHY_STATE_SEND_CMD:
817-
/* Check if we have any commands in the queue */
817+
if (pd->phy_retry_count > 0) {
818+
struct osdp_channel *channel = &pd_to_osdp(pd)->channel;
819+
if (channel->flush)
820+
channel->flush(channel->data);
821+
pd->seq_number = pd->phy_tx_seq - 1;
822+
}
818823
if (cp_build_and_send_packet(pd)) {
819824
LOG_ERR("Failed to build/send packet for CMD: %s(%02x)",
820825
osdp_cmd_name(pd->cmd_id), pd->cmd_id);

src/osdp_phy.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ int osdp_phy_packet_init(struct osdp_pd *pd, uint8_t *buf, int max_len)
233233
id = pd->cmd_id;
234234
}
235235
pkt->control = phy_get_next_seq_number(pd);
236+
pd->phy_tx_seq = pkt->control & PKT_CONTROL_SQN;
236237
if (is_pd_mode(pd) ||
237238
(is_cp_mode(pd) && ISSET_FLAG(pd, PD_FLAG_CP_USE_CRC))) {
238239
pkt->control |= PKT_CONTROL_CRC;
@@ -899,6 +900,7 @@ void osdp_phy_state_reset(struct osdp_pd *pd, bool is_error)
899900
pd->packet_buf = osdp_tx_staging_buf(pd);
900901
if (is_error) {
901902
pd->phy_retry_count = 0;
903+
pd->phy_tx_seq = 0;
902904
phy_reset_seq_number(pd);
903905
if (channel->flush) {
904906
channel->flush(channel->data);

0 commit comments

Comments
 (0)