spdm-socket: add seperate send/recv functions
This is to support uni-directional transports such as SPDM over Storage. As specified by the DMTF DSP0286. Also update spdm_socket_rsp() to use the new send()/receive() functions. For the case of spdm_socket_receive(), this allows us to do error checking in one place with the addition of spdm_socket_command_valid(). Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
This commit is contained in:
parent
e090e0312d
commit
169e8d0c4b
2 changed files with 77 additions and 13 deletions
|
|
@ -184,29 +184,61 @@ int spdm_socket_connect(uint16_t port, Error **errp)
|
|||
return client_socket;
|
||||
}
|
||||
|
||||
uint32_t spdm_socket_rsp(const int socket, uint32_t transport_type,
|
||||
void *req, uint32_t req_len,
|
||||
void *rsp, uint32_t rsp_len)
|
||||
static bool spdm_socket_command_valid(uint32_t command)
|
||||
{
|
||||
switch (command) {
|
||||
case SPDM_SOCKET_COMMAND_NORMAL:
|
||||
case SPDM_SOCKET_STORAGE_CMD_IF_SEND:
|
||||
case SPDM_SOCKET_STORAGE_CMD_IF_RECV:
|
||||
case SOCKET_SPDM_STORAGE_ACK_STATUS:
|
||||
case SPDM_SOCKET_COMMAND_OOB_ENCAP_KEY_UPDATE:
|
||||
case SPDM_SOCKET_COMMAND_CONTINUE:
|
||||
case SPDM_SOCKET_COMMAND_SHUTDOWN:
|
||||
case SPDM_SOCKET_COMMAND_UNKOWN:
|
||||
case SPDM_SOCKET_COMMAND_TEST:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t spdm_socket_receive(const int socket, uint32_t transport_type,
|
||||
void *rsp, uint32_t rsp_len)
|
||||
{
|
||||
uint32_t command;
|
||||
bool result;
|
||||
|
||||
result = send_platform_data(socket, transport_type,
|
||||
SPDM_SOCKET_COMMAND_NORMAL,
|
||||
req, req_len);
|
||||
if (!result) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
result = receive_platform_data(socket, transport_type, &command,
|
||||
(uint8_t *)rsp, &rsp_len);
|
||||
|
||||
/* we may have received some data, but check if the command is valid */
|
||||
if (!result || !spdm_socket_command_valid(command)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return rsp_len;
|
||||
}
|
||||
|
||||
bool spdm_socket_send(const int socket, uint32_t socket_cmd,
|
||||
uint32_t transport_type, void *req, uint32_t req_len)
|
||||
{
|
||||
return send_platform_data(socket, transport_type, socket_cmd, req,
|
||||
req_len);
|
||||
}
|
||||
|
||||
uint32_t spdm_socket_rsp(const int socket, uint32_t transport_type,
|
||||
void *req, uint32_t req_len,
|
||||
void *rsp, uint32_t rsp_len)
|
||||
{
|
||||
bool result;
|
||||
|
||||
result = spdm_socket_send(socket, SPDM_SOCKET_COMMAND_NORMAL,
|
||||
transport_type, req, req_len);
|
||||
if (!result) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(command != 0);
|
||||
|
||||
return rsp_len;
|
||||
return spdm_socket_receive(socket, transport_type, rsp, rsp_len);
|
||||
}
|
||||
|
||||
void spdm_socket_close(const int socket, uint32_t transport_type)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue