Skip to content
Merged
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
54 changes: 27 additions & 27 deletions port/posix/posix_transport_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ int posixTransportShm_Cleanup(void* c)
return 0;
}


#if defined(WOLFHSM_CFG_ENABLE_CLIENT)
int posixTransportShm_SendRequest(void* c, uint16_t len, const void* data)
{
posixTransportShmContext* ctx = (posixTransportShmContext*)c;
Expand Down Expand Up @@ -520,6 +520,31 @@ int posixTransportShm_SendRequest(void* c, uint16_t len, const void* data)
return ret;
}

int posixTransportShm_RecvResponse(void* c, uint16_t* out_len, void* data)
{
posixTransportShmContext* ctx = (posixTransportShmContext*)c;

/* Only need to check NULL, mem transport checks other state info */
if (ctx == NULL) {
return WH_ERROR_BADARGS;
}

return wh_TransportMem_RecvResponse(ctx->transportMemCtx, out_len, data);
}
#endif /* WOLFHSM_CFG_ENABLE_CLIENT */

#if defined(WOLFHSM_CFG_ENABLE_SERVER)
int posixTransportShm_SendResponse(void* c, uint16_t len, const void* data)
{
posixTransportShmContext* ctx = (posixTransportShmContext*)c;

/* Only need to check NULL, mem transport checks other state info */
if (ctx == NULL) {
return WH_ERROR_BADARGS;
}

return wh_TransportMem_SendResponse(ctx->transportMemCtx, len, data);
}

int posixTransportShm_RecvRequest(void* c, uint16_t* out_len, void* data)
{
Expand Down Expand Up @@ -565,29 +590,4 @@ int posixTransportShm_RecvRequest(void* c, uint16_t* out_len, void* data)
}
return ret;
}


int posixTransportShm_SendResponse(void* c, uint16_t len, const void* data)
{
posixTransportShmContext* ctx = (posixTransportShmContext*)c;

/* Only need to check NULL, mem transport checks other state info */
if (ctx == NULL) {
return WH_ERROR_BADARGS;
}

return wh_TransportMem_SendResponse(ctx->transportMemCtx, len, data);
}


int posixTransportShm_RecvResponse(void* c, uint16_t* out_len, void* data)
{
posixTransportShmContext* ctx = (posixTransportShmContext*)c;

/* Only need to check NULL, mem transport checks other state info */
if (ctx == NULL) {
return WH_ERROR_BADARGS;
}

return wh_TransportMem_RecvResponse(ctx->transportMemCtx, out_len, data);
}
#endif
39 changes: 21 additions & 18 deletions src/wh_transport_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int wh_TransportMem_Cleanup(void* c)

return 0;
}

#if defined(WOLFHSM_CFG_ENABLE_CLIENT)
int wh_TransportMem_SendRequest(void* c, uint16_t len, const void* data)
{
whTransportMemContext* context = c;
Expand Down Expand Up @@ -142,7 +142,7 @@ int wh_TransportMem_SendRequest(void* c, uint16_t len, const void* data)
return 0;
}

int wh_TransportMem_RecvRequest(void* c, uint16_t *out_len, void* data)
int wh_TransportMem_RecvResponse(void* c, uint16_t *out_len, void* data)
{
whTransportMemContext* context = c;
volatile whTransportMemCsr* ctx_req;
Expand All @@ -158,27 +158,30 @@ int wh_TransportMem_RecvRequest(void* c, uint16_t *out_len, void* data)
ctx_req = context->req;
ctx_resp = context->resp;

/* Read current request CSR's. ctx_resp does not need to be invalidated */
/* Read both CSR's. ctx_req does not need to be invalidated */
XMEMFENCE();
XCACHEINVLD(ctx_req);
XCACHEINVLD(ctx_resp);
req.u64 = ctx_req->u64;
resp.u64 = ctx_resp->u64;

/* Check to see if a new request has arrived */
if(req.s.notify == resp.s.notify) {
/* Check to see if the current response is the different than the request */
if(resp.s.notify != req.s.notify) {
return WH_ERROR_NOTREADY;
}

if ((data != NULL) && (req.s.len != 0)) {
wh_Utils_memcpy_invalidate(data, context->req_data, req.s.len);
if ((data != NULL) && (resp.s.len != 0)) {
wh_Utils_memcpy_invalidate(data, context->resp_data, resp.s.len);
}

if (out_len != NULL) {
*out_len = req.s.len;
*out_len = resp.s.len;
}

return 0;
}
#endif /* WOLFHSM_CFG_ENABLE_CLIENT */

#if defined(WOLFHSM_CFG_ENABLE_SERVER)
int wh_TransportMem_SendResponse(void* c, uint16_t len, const void* data)
{
whTransportMemContext* context = c;
Expand Down Expand Up @@ -223,7 +226,7 @@ int wh_TransportMem_SendResponse(void* c, uint16_t len, const void* data)
return 0;
}

int wh_TransportMem_RecvResponse(void* c, uint16_t *out_len, void* data)
int wh_TransportMem_RecvRequest(void* c, uint16_t *out_len, void* data)
{
whTransportMemContext* context = c;
volatile whTransportMemCsr* ctx_req;
Expand All @@ -239,24 +242,24 @@ int wh_TransportMem_RecvResponse(void* c, uint16_t *out_len, void* data)
ctx_req = context->req;
ctx_resp = context->resp;

/* Read both CSR's. ctx_req does not need to be invalidated */
/* Read current request CSR's. ctx_resp does not need to be invalidated */
XMEMFENCE();
XCACHEINVLD(ctx_resp);
XCACHEINVLD(ctx_req);
req.u64 = ctx_req->u64;
resp.u64 = ctx_resp->u64;

/* Check to see if the current response is the different than the request */
if(resp.s.notify != req.s.notify) {
/* Check to see if a new request has arrived */
if(req.s.notify == resp.s.notify) {
return WH_ERROR_NOTREADY;
}

if ((data != NULL) && (resp.s.len != 0)) {
wh_Utils_memcpy_invalidate(data, context->resp_data, resp.s.len);
if ((data != NULL) && (req.s.len != 0)) {
wh_Utils_memcpy_invalidate(data, context->req_data, req.s.len);
}

if (out_len != NULL) {
*out_len = resp.s.len;
*out_len = req.s.len;
}

return 0;
}
#endif /* WOLFHSM_CFG_ENABLE_SERVER */
5 changes: 2 additions & 3 deletions wolfhsm/wh_transport_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ int wh_TransportMem_InitClear(void* c, const void* cf,
whCommSetConnectedCb connectcb, void* connectcb_arg);
int wh_TransportMem_Cleanup(void* c);
int wh_TransportMem_SendRequest(void* c, uint16_t len, const void* data);
int wh_TransportMem_RecvRequest(void* c, uint16_t *out_len, void* data);
int wh_TransportMem_RecvRequest(void* c, uint16_t* out_len, void* data);
int wh_TransportMem_SendResponse(void* c, uint16_t len, const void* data);
int wh_TransportMem_RecvResponse(void* c, uint16_t *out_len, void* data);
int wh_TransportMem_RecvResponse(void* c, uint16_t* out_len, void* data);

#define WH_TRANSPORT_MEM_CLIENT_CB \
{ \
Expand All @@ -162,5 +162,4 @@ int wh_TransportMem_RecvResponse(void* c, uint16_t *out_len, void* data);
.Cleanup = wh_TransportMem_Cleanup, \
}


#endif /* !WOLFHSM_WH_TRANSPORT_MEM_H_ */