| 1 | /* |
| 2 | * QEMU SPDM socket support |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | * of this software and associated documentation files (the "Software"), to deal |
| 6 | * in the Software without restriction, including without limitation the rights |
| 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | * copies of the Software, and to permit persons to whom the Software is |
| 9 | * furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | * THE SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #ifndef SPDM_REQUESTER_H |
| 24 | #define SPDM_REQUESTER_H |
| 25 | |
| 26 | /** |
| 27 | * spdm_socket_connect: connect to an external SPDM socket |
| 28 | * @port: port to connect to |
| 29 | * @errp: error object handle |
| 30 | * |
| 31 | * This will connect to an external SPDM socket server. On error |
| 32 | * it will return -1 and errp will be set. On success this function |
| 33 | * will return the socket number. |
| 34 | */ |
| 35 | int spdm_socket_connect(uint16_t port, Error **errp); |
| 36 | |
| 37 | /** |
| 38 | * spdm_socket_rsp: send and receive a message to a SPDM server |
| 39 | * @socket: socket returned from spdm_socket_connect() |
| 40 | * @transport_type: SPDM_SOCKET_TRANSPORT_TYPE_* macro |
| 41 | * @req: request buffer |
| 42 | * @req_len: request buffer length |
| 43 | * @rsp: response buffer |
| 44 | * @rsp_len: response buffer length |
| 45 | * |
| 46 | * Send platform data to a SPDM server on socket and then receive |
| 47 | * a response. |
| 48 | */ |
| 49 | uint32_t spdm_socket_rsp(const int socket, uint32_t transport_type, |
| 50 | void *req, uint32_t req_len, |
| 51 | void *rsp, uint32_t rsp_len); |
| 52 | |
| 53 | /** |
| 54 | * spdm_socket_rsp: Receive a message from an SPDM server |
| 55 | * @socket: socket returned from spdm_socket_connect() |
| 56 | * @transport_type: SPDM_SOCKET_TRANSPORT_TYPE_* macro |
| 57 | * @rsp: response buffer |
| 58 | * @rsp_len: response buffer length |
| 59 | * |
| 60 | * Receives a message from the SPDM server and returns the number of bytes |
| 61 | * received or 0 on failure. This can be used to receive a message from the SPDM |
| 62 | * server without sending anything first. |
| 63 | */ |
| 64 | uint32_t spdm_socket_receive(const int socket, uint32_t transport_type, |
| 65 | void *rsp, uint32_t rsp_len); |
| 66 | |
| 67 | /** |
| 68 | * spdm_socket_rsp: Sends a message to an SPDM server |
| 69 | * @socket: socket returned from spdm_socket_connect() |
| 70 | * @socket_cmd: socket command type (normal/if_recv/if_send etc...) |
| 71 | * @transport_type: SPDM_SOCKET_TRANSPORT_TYPE_* macro |
| 72 | * @req: request buffer |
| 73 | * @req_len: request buffer length |
| 74 | * |
| 75 | * Sends platform data to a SPDM server on socket, returns true on success. |
| 76 | * The response from the server must then be fetched by using |
| 77 | * spdm_socket_receive(). |
| 78 | */ |
| 79 | bool spdm_socket_send(const int socket, uint32_t socket_cmd, |
| 80 | uint32_t transport_type, void *req, uint32_t req_len); |
| 81 | |
| 82 | /** |
| 83 | * spdm_socket_close: send a shutdown command to the server |
| 84 | * @socket: socket returned from spdm_socket_connect() |
| 85 | * @transport_type: SPDM_SOCKET_TRANSPORT_TYPE_* macro |
| 86 | * |
| 87 | * This will issue a shutdown command to the server. |
| 88 | */ |
| 89 | void spdm_socket_close(const int socket, uint32_t transport_type); |
| 90 | |
| 91 | /* |
| 92 | * Defines the transport encoding for SPDM, this information shall be passed |
| 93 | * down to the SPDM server, when conforming to the SPDM over Storage standard |
| 94 | * as defined by DSP0286. |
| 95 | */ |
| 96 | typedef struct { |
| 97 | uint8_t security_protocol; /* Must be 0xE8 for SPDM Commands |
| 98 | as per SCSI Primary Commands 5 */ |
| 99 | uint16_t security_protocol_specific; /* Bit[7:2] SPDM Operation |
| 100 | Bit[0:1] Connection ID |
| 101 | per DSP0286 1.0: Section 7.2 */ |
| 102 | uint32_t length; /* Length of the SPDM Message*/ |
| 103 | } QEMU_PACKED StorageSpdmTransportHeader; |
| 104 | |
| 105 | #define SPDM_SOCKET_COMMAND_NORMAL 0x0001 |
| 106 | #define SPDM_SOCKET_STORAGE_CMD_IF_SEND 0x0002 |
| 107 | #define SPDM_SOCKET_STORAGE_CMD_IF_RECV 0x0003 |
| 108 | #define SOCKET_SPDM_STORAGE_ACK_STATUS 0x0004 |
| 109 | #define SPDM_SOCKET_COMMAND_OOB_ENCAP_KEY_UPDATE 0x8001 |
| 110 | #define SPDM_SOCKET_COMMAND_CONTINUE 0xFFFD |
| 111 | #define SPDM_SOCKET_COMMAND_SHUTDOWN 0xFFFE |
| 112 | #define SPDM_SOCKET_COMMAND_UNKOWN 0xFFFF |
| 113 | #define SPDM_SOCKET_COMMAND_TEST 0xDEAD |
| 114 | |
| 115 | #define SPDM_SOCKET_MAX_MESSAGE_BUFFER_SIZE 0x1200 |
| 116 | #define SPDM_SOCKET_MAX_MSG_STATUS_LEN 0x02 |
| 117 | |
| 118 | typedef enum SpdmTransportType { |
| 119 | SPDM_SOCKET_TRANSPORT_TYPE_UNSPEC = 0, |
| 120 | SPDM_SOCKET_TRANSPORT_TYPE_MCTP, |
| 121 | SPDM_SOCKET_TRANSPORT_TYPE_PCI_DOE, |
| 122 | SPDM_SOCKET_TRANSPORT_TYPE_SCSI, |
| 123 | SPDM_SOCKET_TRANSPORT_TYPE_NVME, |
| 124 | SPDM_SOCKET_TRANSPORT_TYPE_MAX |
| 125 | } SpdmTransportType; |
| 126 | |
| 127 | extern const PropertyInfo qdev_prop_spdm_trans; |
| 128 | |
| 129 | #define DEFINE_PROP_SPDM_TRANS(_name, _state, _field, _default) \ |
| 130 | DEFINE_PROP_UNSIGNED(_name, _state, _field, _default, \ |
| 131 | qdev_prop_spdm_trans, SpdmTransportType) |
| 132 | |
| 133 | #endif |