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
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
79 changes: 42 additions & 37 deletions src/wh_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,22 +253,21 @@ int wh_Client_SendRequest(whClientContext* c,
return rc;
}

int wh_Client_RecvResponse(whClientContext *c,
uint16_t *out_group, uint16_t *out_action,
uint16_t *out_size, void* data)
int wh_Client_RecvResponse(whClientContext* c, uint16_t* out_group,
uint16_t* out_action, 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 @@ -281,9 +280,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 @@ -327,9 +323,8 @@ int wh_Client_CommInitResponse(whClientContext* c,
return WH_ERROR_BADARGS;
}

rc = wh_Client_RecvResponse(c,
&resp_group, &resp_action,
&resp_size, &msg);
rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
sizeof(msg), &msg);
if (rc == 0) {
/* Validate response */
if ( (resp_group != WH_MESSAGE_GROUP_COMM) ||
Expand Down Expand Up @@ -407,9 +402,8 @@ int wh_Client_CommInfoResponse(whClientContext* c,
return WH_ERROR_BADARGS;
}

rc = wh_Client_RecvResponse(c,
&resp_group, &resp_action,
&resp_size, &msg);
rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
sizeof(msg), &msg);
if (rc == 0) {
/* Validate response */
if ( (resp_group != WH_MESSAGE_GROUP_COMM) ||
Expand Down Expand Up @@ -585,9 +579,8 @@ int wh_Client_CommCloseResponse(whClientContext* c)
return WH_ERROR_BADARGS;
}

rc = wh_Client_RecvResponse(c,
&resp_group, &resp_action,
&resp_size, NULL);
rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, 0,
NULL);
if (rc == 0) {
/* Validate response */
if ( (resp_group != WH_MESSAGE_GROUP_COMM) ||
Expand Down Expand Up @@ -658,9 +651,8 @@ int wh_Client_EchoResponse(whClientContext* c, uint16_t *out_size, void* data)
return WH_ERROR_BADARGS;
}

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

rc =
wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, &resp);
rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size,
sizeof(resp), &resp);
if (rc != WH_ERROR_OK) {
return rc;
}
Expand Down Expand Up @@ -872,7 +864,8 @@ 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 @@ -959,7 +952,8 @@ int wh_Client_KeyCacheRandomResponse(whClientContext* c, uint16_t* outKeyId)
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 @@ -1027,7 +1021,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 @@ -1090,7 +1085,8 @@ 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 @@ -1175,7 +1171,8 @@ 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 @@ -1252,7 +1249,8 @@ 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 @@ -1308,7 +1306,8 @@ 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 @@ -1364,7 +1363,8 @@ 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 @@ -1422,7 +1422,8 @@ 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 @@ -1500,7 +1501,8 @@ 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 @@ -1560,7 +1562,8 @@ 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 @@ -1620,7 +1623,8 @@ 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 @@ -1715,7 +1719,8 @@ 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);
/* NOTREADY: response not in yet - return without POST so the pending
* request keeps its mapping; POST runs once the response arrives. */
if (ret == WH_ERROR_NOTREADY) {
Expand Down Expand Up @@ -1826,7 +1831,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);
/* NOTREADY: response not in yet - return without POST so the pending
* request keeps its mapping; POST runs once the response arrives. */
if (rc == WH_ERROR_NOTREADY) {
Expand Down Expand Up @@ -1951,7 +1956,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);
/* NOTREADY: response not in yet - return without POST so the pending
* request keeps its mapping; POST runs once the response arrives. */
if (rc == WH_ERROR_NOTREADY) {
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 @@ -134,7 +134,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 @@ -219,7 +219,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 @@ -338,7 +338,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 @@ -413,7 +413,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 @@ -489,7 +489,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 @@ -576,7 +576,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 @@ -702,7 +702,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