Skip to content

Commit

Permalink
libosdp: cp: Move keyset completion handler to get_next_ok_state()
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Feb 11, 2024
1 parent 13b3984 commit f9b2cb9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/osdp_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const char *osdp_reply_name(int reply_id)

void osdp_keyset_complete(struct osdp_pd *pd)
{
cp_keyset_complete(pd);
cp_keyset_complete(pd, true);
}

int osdp_rb_push(struct osdp_rb *p, uint8_t data)
Expand Down
4 changes: 2 additions & 2 deletions src/osdp_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ struct osdp {
};

#ifdef CONFIG_OSDP_STATIC_PD
static inline void cp_keyset_complete(struct osdp_pd *pd) { }
static inline void cp_keyset_complete(struct osdp_pd *pd, bool restart_sc) { }
#else
void cp_keyset_complete(struct osdp_pd *pd);
void cp_keyset_complete(struct osdp_pd *pd, bool restart_sc);
#endif

void osdp_keyset_complete(struct osdp_pd *pd);
Expand Down
12 changes: 5 additions & 7 deletions src/osdp_cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@ static enum osdp_cp_state_e get_next_ok_state(struct osdp_pd *pd)
}
return OSDP_CP_STATE_ONLINE;
case OSDP_CP_STATE_SET_SCBK:
cp_keyset_complete(pd, false);
return OSDP_CP_STATE_SC_CHLNG;
case OSDP_CP_STATE_ONLINE:
if (cp_sc_should_retry(pd)) {
Expand Down Expand Up @@ -1131,7 +1132,7 @@ static inline enum osdp_cp_state_e get_next_state(struct osdp_pd *pd, int err)
* response (ACK) in plain text since they discarded the SC in favour of the new
* SCBK we set.
*/
void cp_keyset_complete(struct osdp_pd *pd)
void cp_keyset_complete(struct osdp_pd *pd, bool restart_sc)
{
struct osdp_cmd *cmd;

Expand All @@ -1142,7 +1143,9 @@ void cp_keyset_complete(struct osdp_pd *pd)
} else {
CLEAR_FLAG(pd, PD_FLAG_SC_USE_SCBKD);
}
make_request(pd, CP_REQ_RESTART_SC);
if (restart_sc) {
make_request(pd, CP_REQ_RESTART_SC);
}
LOG_INF("SCBK set; restarting SC to verify new SCBK");
}

Expand All @@ -1158,11 +1161,6 @@ static void cp_state_change(struct osdp_pd *pd, enum osdp_cp_state_e next)
}

switch (next) {
case OSDP_CP_STATE_SC_CHLNG:
if (cur == OSDP_CP_STATE_SET_SCBK) {
cp_keyset_complete(pd);
}
break;
case OSDP_CP_STATE_ONLINE:
if (cur == OSDP_CP_STATE_SC_SCRYPT) {
sc_activate(pd);
Expand Down

0 comments on commit f9b2cb9

Please sign in to comment.