Skip to content

Commit ba97d77

Browse files
committed
CP: Fix bug in sequence number progression
Commit 7f6d3c3 introduced a fix for the long-standing sequence number mismatch issue by an explicit sequence progression logic. By this logic, when there are no errors, the sequence number is progressed. But it failed to handle the case when the PD respond with a valid packet, and the CP finds an application layer error in the packet, the sequence number must be progressed as the PD would have (correctly) incremented it's sequence number. To fix this, let's introduce a new CP error code to use for any future application layer errors and use that to hook into the sequence progression logic. Fixes: #244 Fixes: 7f6d3c3 Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com> (cherry picked from commit b922873)
1 parent a81263e commit ba97d77

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/osdp_cp.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum osdp_cp_error_e {
5353
OSDP_CP_ERR_INPROG = -5,
5454
OSDP_CP_ERR_UNKNOWN = -6,
5555
OSDP_CP_ERR_SEQ_NUM = -7,
56+
OSDP_CP_ERR_APP = -8, /* Application layer error */
5657
};
5758

5859
struct cp_cmd_node {
@@ -640,7 +641,7 @@ static int cp_decode_response(struct osdp_pd *pd, uint8_t *buf, int len)
640641
osdp_compute_session_keys(pd);
641642
if (osdp_verify_pd_cryptogram(pd) != 0) {
642643
LOG_ERR("Failed to verify PD cryptogram");
643-
return OSDP_CP_ERR_GENERIC;
644+
return OSDP_CP_ERR_APP;
644645
}
645646
ret = OSDP_CP_ERR_NONE;
646647
break;
@@ -878,19 +879,20 @@ static int cp_phy_state_update(struct osdp_pd *pd)
878879
break;
879880
case OSDP_CP_PHY_STATE_REPLY_WAIT:
880881
rc = cp_process_reply(pd);
881-
if (rc == OSDP_CP_ERR_NONE) {
882+
if (rc == OSDP_CP_ERR_NONE || rc == OSDP_CP_ERR_APP) {
882883
pd->tstamp = osdp_millis_now();
883884
osdp_phy_progress_sequence(pd);
884-
cp_phy_state_done(pd);
885-
return OSDP_CP_ERR_NONE;
886885
}
887-
if (rc == OSDP_CP_ERR_SEQ_NUM ||
886+
if (rc == OSDP_CP_ERR_NONE ||
887+
rc == OSDP_CP_ERR_SEQ_NUM ||
888888
(rc == OSDP_CP_ERR_UNKNOWN && pd->cmd_id == CMD_POLL &&
889889
ISSET_FLAG(pd, OSDP_FLAG_IGN_UNSOLICITED))) {
890890
cp_phy_state_done(pd);
891891
return OSDP_CP_ERR_NONE;
892892
}
893-
if (rc == OSDP_CP_ERR_GENERIC || rc == OSDP_CP_ERR_UNKNOWN) {
893+
if (rc == OSDP_CP_ERR_GENERIC ||
894+
rc == OSDP_CP_ERR_UNKNOWN ||
895+
rc == OSDP_CP_ERR_APP) {
894896
goto error;
895897
}
896898
if (rc == OSDP_CP_ERR_RETRY_CMD) {

0 commit comments

Comments
 (0)