Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/wh_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ int wh_Client_Init(whClientContext* c, const whClientConfig* config)

memset(c, 0, sizeof(*c));

#ifdef WOLFHSM_CFG_CLIENT_MSG_POLL_CB
c->msgPollCb = config->msgPollCb;
c->msgPollCbData = config->msgPollCbData;
#endif /* WOLFHSM_CFG_CLIENT_MSG_POLL_CB */

rc = wh_CommClient_Init(c->comm, config->comm);

#ifndef WOLFHSM_CFG_NO_CRYPTO
Expand Down Expand Up @@ -152,6 +157,16 @@ int wh_Client_SendRequest(whClientContext* c,
c->last_req_kind = kind;
c->last_req_id = req_id;
}

#ifdef WOLFHSM_CFG_CLIENT_MSG_POLL_CB
if (rc == WH_ERROR_NOTREADY && c->msgPollCb != NULL) {
int cbrc = c->msgPollCb(c->msgPollCbData);
if (cbrc != 0) {
return cbrc;
}
}
#endif /* WOLFHSM_CFG_CLIENT_MSG_POLL_CB */

return rc;
}

Expand Down Expand Up @@ -188,6 +203,16 @@ int wh_Client_RecvResponse(whClientContext *c,
}
}
}

#ifdef WOLFHSM_CFG_CLIENT_MSG_POLL_CB
if (rc == WH_ERROR_NOTREADY && c->msgPollCb != NULL) {
int cbrc = c->msgPollCb(c->msgPollCbData);
if (cbrc != 0) {
return cbrc;
}
}
#endif /* WOLFHSM_CFG_CLIENT_MSG_POLL_CB */

return rc;
}

Expand Down
16 changes: 16 additions & 0 deletions wolfhsm/wh_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ typedef struct {
} whClientDmaContext;
#endif /* WOLFHSM_CFG_DMA */

#ifdef WOLFHSM_CFG_CLIENT_MSG_POLL_CB
/* Invoked once each time wh_Client_SendRequest or wh_Client_RecvResponse would
* return WH_ERROR_NOTREADY. When the callback returns 0, the caller's retry
* loop continues. If the callback returns non-zero, the caller's retry loop is
* aborted and the non-zero propagates internally. */
typedef int (*whClientMsgPollCb)(void* cbData);
#endif /* WOLFHSM_CFG_CLIENT_MSG_POLL_CB */

/* Client context */
struct whClientContext_t {
uint16_t last_req_id;
Expand All @@ -143,6 +151,10 @@ struct whClientContext_t {
#ifdef WOLFHSM_CFG_DMA
whClientDmaContext dma;
#endif /* WOLFHSM_CFG_DMA */
#ifdef WOLFHSM_CFG_CLIENT_MSG_POLL_CB
whClientMsgPollCb msgPollCb;
void* msgPollCbData;
#endif /* WOLFHSM_CFG_CLIENT_MSG_POLL_CB */
whCommClient comm[1];
};

Expand All @@ -151,6 +163,10 @@ struct whClientConfig_t {
#ifdef WOLFHSM_CFG_DMA
whClientDmaConfig* dmaConfig;
#endif /* WOLFHSM_CFG_DMA */
#ifdef WOLFHSM_CFG_CLIENT_MSG_POLL_CB
whClientMsgPollCb msgPollCb;
void* msgPollCbData;
#endif /* WOLFHSM_CFG_CLIENT_MSG_POLL_CB */
};
typedef struct whClientConfig_t whClientConfig;

Expand Down
Loading