Skip to content

Commit b922873

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 <[email protected]>
1 parent 5113765 commit b922873

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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 {
@@ -657,7 +658,7 @@ static int cp_decode_response(struct osdp_pd *pd, uint8_t *buf, int len)
657658
osdp_compute_session_keys(pd);
658659
if (osdp_verify_pd_cryptogram(pd) != 0) {
659660
LOG_ERR("Failed to verify PD cryptogram");
660-
return OSDP_CP_ERR_GENERIC;
661+
return OSDP_CP_ERR_APP;
661662
}
662663
ret = OSDP_CP_ERR_NONE;
663664
break;
@@ -895,19 +896,20 @@ static int cp_phy_state_update(struct osdp_pd *pd)
895896
break;
896897
case OSDP_CP_PHY_STATE_REPLY_WAIT:
897898
rc = cp_process_reply(pd);
898-
if (rc == OSDP_CP_ERR_NONE) {
899+
if (rc == OSDP_CP_ERR_NONE || rc == OSDP_CP_ERR_APP) {
899900
pd->tstamp = osdp_millis_now();
900901
osdp_phy_progress_sequence(pd);
901-
cp_phy_state_done(pd);
902-
return OSDP_CP_ERR_NONE;
903902
}
904-
if (rc == OSDP_CP_ERR_SEQ_NUM ||
903+
if (rc == OSDP_CP_ERR_NONE ||
904+
rc == OSDP_CP_ERR_SEQ_NUM ||
905905
(rc == OSDP_CP_ERR_UNKNOWN && pd->cmd_id == CMD_POLL &&
906906
ISSET_FLAG(pd, OSDP_FLAG_IGN_UNSOLICITED))) {
907907
cp_phy_state_done(pd);
908908
return OSDP_CP_ERR_NONE;
909909
}
910-
if (rc == OSDP_CP_ERR_GENERIC || rc == OSDP_CP_ERR_UNKNOWN) {
910+
if (rc == OSDP_CP_ERR_GENERIC ||
911+
rc == OSDP_CP_ERR_UNKNOWN ||
912+
rc == OSDP_CP_ERR_APP) {
911913
goto error;
912914
}
913915
if (rc == OSDP_CP_ERR_RETRY_CMD) {

0 commit comments

Comments
 (0)