Skip to content
Open
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
2 changes: 1 addition & 1 deletion docs/src-ja/chapter04.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ rc = wh_CommClient_SendRequest(context, req_magic, req_type, &request_id,
uint16_t resp_magic, resp_type, resp_id, resp_size;
char response_data[20];
while((rc = wh_CommClient_RecvResponse(context,&resp_magic, &resp_type, &resp_id,
&resp_size, resp_data)) == WH_ERROR_NOTREADY) {
&resp_size, sizeof(response_data), response_data)) == WH_ERROR_NOTREADY) {
/* 他のタスクを実行 or yield */
}
```
Expand Down
48 changes: 23 additions & 25 deletions src/wh_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,19 @@ int wh_Client_SendRequest(whClientContext* c,

int wh_Client_RecvResponse(whClientContext *c,
uint16_t *out_group, uint16_t *out_action,
uint16_t *out_size, void* data)
uint16_t *out_size, uint16_t data_size, void* data)
{
int rc = 0;
uint16_t resp_kind = 0;
uint16_t resp_id = 0;
uint16_t resp_size = 0;

if (c == NULL) {
return WH_ERROR_BADARGS;
}

/* Comm layer performs magic and sequence validation */
rc = wh_CommClient_RecvResponse(c->comm, NULL, &resp_kind, &resp_id,
&resp_size, data);
out_size, data_size, data);
if (rc == 0) {
if ((resp_kind != c->last_req_kind) || (resp_id != c->last_req_id)) {
/* Response kind/id doesn't match outstanding request. */
Expand All @@ -183,9 +182,6 @@ int wh_Client_RecvResponse(whClientContext *c,
if (out_action != NULL) {
*out_action = WH_MESSAGE_ACTION(resp_kind);
}
if (out_size != NULL) {
*out_size = resp_size;
}
}
}
return rc;
Expand Down Expand Up @@ -231,7 +227,7 @@ int wh_Client_CommInitResponse(whClientContext* c,

rc = wh_Client_RecvResponse(c,
&resp_group, &resp_action,
&resp_size, &msg);
&resp_size, sizeof(msg), &msg);
if (rc == 0) {
/* Validate response */
if ( (resp_group != WH_MESSAGE_GROUP_COMM) ||
Expand Down Expand Up @@ -311,7 +307,7 @@ int wh_Client_CommInfoResponse(whClientContext* c,

rc = wh_Client_RecvResponse(c,
&resp_group, &resp_action,
&resp_size, &msg);
&resp_size, sizeof(msg), &msg);
if (rc == 0) {
/* Validate response */
if ( (resp_group != WH_MESSAGE_GROUP_COMM) ||
Expand Down Expand Up @@ -461,7 +457,7 @@ int wh_Client_CommCloseResponse(whClientContext* c)

rc = wh_Client_RecvResponse(c,
&resp_group, &resp_action,
&resp_size, NULL);
&resp_size, 0, NULL);
if (rc == 0) {
/* Validate response */
if ( (resp_group != WH_MESSAGE_GROUP_COMM) ||
Expand Down Expand Up @@ -534,7 +530,7 @@ int wh_Client_EchoResponse(whClientContext* c, uint16_t *out_size, void* data)

rc = wh_Client_RecvResponse(c,
&resp_group, &resp_action,
&resp_size, msg);
&resp_size, WOLFHSM_CFG_COMM_DATA_LEN, msg);
if (rc == 0) {
/* Validate response */
if ( (resp_group != WH_MESSAGE_GROUP_COMM) ||
Expand Down Expand Up @@ -596,7 +592,8 @@ int wh_Client_CustomCbResponse(whClientContext* c,
}

rc =
wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, &resp);
wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
sizeof(resp), &resp);
if (rc != WH_ERROR_OK) {
return rc;
}
Expand Down Expand Up @@ -746,7 +743,7 @@ int wh_Client_KeyCacheResponse(whClientContext* c, uint16_t* keyId)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -809,7 +806,8 @@ int wh_Client_KeyEvictResponse(whClientContext* c)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)&resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp),
(uint8_t*)&resp);

if (ret == 0) {
if (resp.rc != 0) {
Expand Down Expand Up @@ -872,7 +870,7 @@ int wh_Client_KeyExportResponse(whClientContext* c, uint8_t* label,
}
packOut = (uint8_t*)(resp + 1);

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -957,7 +955,7 @@ int wh_Client_KeyExportPublicResponse(whClientContext* c, uint8_t* label,
}
packOut = (uint8_t*)(resp + 1);

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1034,7 +1032,7 @@ int wh_Client_KeyCommitResponse(whClientContext* c)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1090,7 +1088,7 @@ int wh_Client_KeyEraseResponse(whClientContext* c)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1146,7 +1144,7 @@ int wh_Client_KeyRevokeResponse(whClientContext* c)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == 0) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1204,7 +1202,7 @@ int wh_Client_CounterInitResponse(whClientContext* c, uint32_t* counter)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1282,7 +1280,7 @@ int wh_Client_CounterIncrementResponse(whClientContext* c, uint32_t* counter)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1342,7 +1340,7 @@ int wh_Client_CounterReadResponse(whClientContext* c, uint32_t* counter)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1402,7 +1400,7 @@ int wh_Client_CounterDestroyResponse(whClientContext* c)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (ret == WH_ERROR_OK) {
if (resp->rc != 0) {
ret = resp->rc;
Expand Down Expand Up @@ -1491,7 +1489,7 @@ int wh_Client_KeyCacheDmaResponse(whClientContext* c, uint16_t* keyId)
return WH_ERROR_BADARGS;
}

ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp);
ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);

if (ret == 0) {
/* Validate response */
Expand Down Expand Up @@ -1570,7 +1568,7 @@ int wh_Client_KeyExportDmaResponse(whClientContext* c, uint8_t* label,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
(uint8_t*)resp);
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (rc == 0) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_KEY) ||
Expand Down Expand Up @@ -1659,7 +1657,7 @@ int wh_Client_KeyExportPublicDmaResponse(whClientContext* c, uint8_t* label,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
(uint8_t*)resp);
WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp);
if (rc == 0) {
if (resp_size != sizeof(*resp)) {
rc = WH_ERROR_ABORTED;
Expand Down
14 changes: 7 additions & 7 deletions src/wh_client_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int wh_Client_AuthLoginResponse(whClientContext* c, int32_t* out_rc,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down Expand Up @@ -212,7 +212,7 @@ int wh_Client_AuthLogoutResponse(whClientContext* c, int32_t* out_rc)
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down Expand Up @@ -329,7 +329,7 @@ int wh_Client_AuthUserAddResponse(whClientContext* c, int32_t* out_rc,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down Expand Up @@ -404,7 +404,7 @@ int wh_Client_AuthUserDeleteResponse(whClientContext* c, int32_t* out_rc)
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down Expand Up @@ -480,7 +480,7 @@ int wh_Client_AuthUserGetResponse(whClientContext* c, int32_t* out_rc,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down Expand Up @@ -567,7 +567,7 @@ int wh_Client_AuthUserSetPermissionsResponse(whClientContext* c,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down Expand Up @@ -685,7 +685,7 @@ int wh_Client_AuthUserSetCredentialsResponse(whClientContext* c,
}

rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
buffer);
sizeof(buffer), buffer);
if (rc == WH_ERROR_OK) {
/* Validate response */
if ((resp_group != WH_MESSAGE_GROUP_AUTH) ||
Expand Down
Loading
Loading