├── .gitignore ├── .github ├── CODEOWNERS ├── dependabot.yml └── workflows │ ├── chunk_device_sample.yml │ └── pqc_check.yml ├── spdm_emu ├── spdm_device_verifier_tool │ ├── requirements.txt │ ├── SampleEvidence │ │ ├── device_measurement.bin │ │ └── SpdmSampleMeasurement.json │ ├── SampleTestKey │ │ ├── ecc-public-key.pem │ │ ├── ecc-private-key.pem │ │ ├── example.cer.pem │ │ ├── SampleCertChain │ │ │ ├── TestSub.pub.pem │ │ │ ├── TestRoot.pub.pem │ │ │ ├── TestCert.pub.pem │ │ │ ├── TestSub.key │ │ │ ├── TestCert.key │ │ │ └── TestRoot.key │ │ └── example.key.pem │ ├── SpdmSamplePolicy.rego │ └── OpaTool.py ├── spdm_responder_emu │ ├── spdm_responder_mctp.c │ ├── spdm_responder_emu.h │ ├── spdm_responder_pci_doe.c │ └── spdm_responder_tcp.c ├── spdm_requester_emu │ ├── spdm_requester_mctp.c │ ├── spdm_requester_emu.h │ ├── spdm_requester_endpoint_info.c │ └── spdm_requester_tcp.c ├── spdm_device_validator_sample │ ├── spdm_device_validator_sample.h │ └── spdm_device_validator_pci_doe.c ├── spdm_device_attester_sample │ ├── spdm_device_attester_pci_doe.c │ └── spdm_device_attester_sample.h └── spdm_emu_common │ ├── command.h │ ├── os_include.h │ └── nv_storage.h ├── .gitmodules ├── library ├── spdm_transport_none_lib │ └── CMakeLists.txt ├── pci_doe_responder_lib │ ├── CMakeLists.txt │ └── pci_doe_dispatch.c ├── mctp_responder_lib │ ├── CMakeLists.txt │ └── pldm_rsp_control_get_tid.c ├── pci_doe_requester_lib │ └── CMakeLists.txt ├── mctp_requester_lib │ ├── CMakeLists.txt │ └── pldm_send_receive.c ├── pci_ide_km_responder_lib │ ├── CMakeLists.txt │ ├── pci_ide_km_dispatch.c │ ├── pci_ide_km_rsp_key_set_go.c │ └── pci_ide_km_rsp_key_set_stop.c ├── pci_ide_km_requester_lib │ ├── CMakeLists.txt │ └── pci_ide_km_send_receive.c ├── cxl_ide_km_responder_lib │ ├── CMakeLists.txt │ ├── cxl_ide_km_dispatch.c │ ├── cxl_ide_km_rsp_key_set_go.c │ └── cxl_ide_km_rsp_key_set_stop.c ├── pci_ide_km_device_lib_sample │ ├── CMakeLists.txt │ ├── pci_ide_km_device_context.c │ ├── pci_ide_km_device_key_set_go.c │ ├── pci_ide_km_device_key_set_stop.c │ ├── pci_ide_km_device_query.c │ └── pci_ide_km_device_key_prog.c ├── cxl_ide_km_requester_lib │ ├── CMakeLists.txt │ └── cxl_ide_km_send_receive.c ├── cxl_ide_km_device_lib_sample │ ├── CMakeLists.txt │ ├── cxl_ide_km_device_key_set_go.c │ ├── cxl_ide_km_device_key_set_stop.c │ ├── cxl_ide_km_device_context.c │ ├── cxl_ide_km_device_get_key.c │ ├── cxl_ide_km_device_query.c │ └── cxl_ide_km_device_key_prog.c ├── cxl_tsp_requester_lib │ ├── CMakeLists.txt │ ├── cxl_tsp_send_receive.c │ └── cxl_tsp_req_lock_configuration.c ├── pci_tdisp_requester_lib │ ├── CMakeLists.txt │ └── pci_tdisp_send_receive.c ├── cxl_tsp_responder_lib │ ├── CMakeLists.txt │ ├── cxl_tsp_rsp_error.c │ └── cxl_tsp_dispatch.c ├── pci_tdisp_responder_lib │ ├── CMakeLists.txt │ └── pci_tdisp_rsp_error.c ├── cxl_tsp_device_lib_sample │ ├── CMakeLists.txt │ ├── cxl_tsp_device_lock_configuration.c │ ├── cxl_tsp_device_set_te_state.c │ ├── cxl_tsp_device_get_capabilities.c │ ├── cxl_tsp_device_get_configuration.c │ ├── cxl_tsp_device_get_version.c │ ├── cxl_tsp_device_get_configuration_report.c │ └── cxl_tsp_device_set_configuration.c └── pci_tdisp_device_lib_sample │ ├── CMakeLists.txt │ ├── pci_tdisp_device_interface_state.c │ ├── pci_tdisp_device_interface_report.c │ ├── pci_tdisp_device_stop_interface.c │ ├── pci_tdisp_device_capabilities.c │ ├── pci_tdisp_device_start_interface.c │ ├── pci_tdisp_device_context.c │ └── pci_tdisp_device_version.c ├── spdm-device-sample └── spdm_device_sample │ ├── spdm_device_responder │ ├── support.c │ ├── spdm_responder_main.c │ ├── pci.c │ ├── spdm_responder_pci_doe.c │ └── CMakeLists.txt │ └── library │ ├── cryptstublib │ ├── rand.c │ ├── CMakeLists.txt │ └── timeclock.c │ ├── rnglib │ ├── CMakeLists.txt │ └── rnglib.c │ ├── debuglib │ ├── CMakeLists.txt │ └── debuglib.c │ ├── platform_lib │ ├── CMakeLists.txt │ ├── time.c │ └── watchdog.c │ ├── spdm_device_secret_lib │ ├── CMakeLists.txt │ ├── bin │ │ └── ecp384_raw_key.c │ ├── spdm_device_secret_lib_internal.h │ ├── read_pub_cert.c │ └── sign.c │ ├── pci_ide_km_device_lib │ ├── CMakeLists.txt │ ├── pci_ide_km_device_context.c │ ├── pci_ide_km_device_key_set_go.c │ ├── pci_ide_km_device_key_set_stop.c │ ├── pci_ide_km_device_query.c │ └── pci_ide_km_device_key_prog.c │ └── pci_tdisp_device_lib │ ├── CMakeLists.txt │ ├── pci_tdisp_device_interface_state.c │ ├── pci_tdisp_device_interface_report.c │ ├── pci_tdisp_device_stop_interface.c │ ├── pci_tdisp_device_capabilities.c │ ├── pci_tdisp_device_start_interface.c │ ├── pci_tdisp_device_context.c │ └── pci_tdisp_device_version.c ├── include └── library │ ├── pci_tdisp_common_lib.h │ ├── mctp_common_lib.h │ ├── pci_doe_common_lib.h │ ├── cxl_ide_km_common_lib.h │ ├── cxl_tsp_common_lib.h │ └── pci_ide_km_common_lib.h ├── script └── format_nix.sh ├── LICENSE.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .vscode/settings.json 3 | 4 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Repository maintainers are added to every pull request. 2 | * @jyao1 @steven-bellock 3 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/requirements.txt: -------------------------------------------------------------------------------- 1 | cbor>=1.0.0 2 | pycose>=0.1.2 3 | cose>=0.9.dev8 4 | jose>=1.0.0 5 | python_jose>=3.1.0 6 | cryptography>=2.3 7 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/SampleEvidence/device_measurement.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DMTF/spdm-emu/main/spdm_emu/spdm_device_verifier_tool/SampleEvidence/device_measurement.bin -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libspdm"] 2 | path = libspdm 3 | url = https://github.com/DMTF/libspdm 4 | [submodule "SPDM-Responder-Validator"] 5 | path = SPDM-Responder-Validator 6 | url = https://github.com/DMTF/SPDM-Responder-Validator 7 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/SampleTestKey/ecc-public-key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEvFmmGssG2SUTuzohvR75iIOKwTWx 3 | 2F4nVEd6amLu4K2vq6yN0Bqc6Or/j7mPia858sWFUYRwz59YIfyGY4917Q== 4 | -----END PUBLIC KEY----- 5 | -------------------------------------------------------------------------------- /spdm_emu/spdm_responder_emu/spdm_responder_mctp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "spdm_responder_emu.h" 8 | 9 | void *m_mctp_context; 10 | -------------------------------------------------------------------------------- /library/spdm_transport_none_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_spdm_transport_none_lib 8 | common.c 9 | none.c 10 | ) 11 | 12 | add_library(spdm_transport_none_lib STATIC ${src_spdm_transport_none_lib}) 13 | -------------------------------------------------------------------------------- /library/pci_doe_responder_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_pci_doe_responder_lib 8 | pci_doe_dispatch.c 9 | pci_doe_spdm_vendor_dispatch.c 10 | ) 11 | 12 | add_library(pci_doe_responder_lib STATIC ${src_pci_doe_responder_lib}) 13 | -------------------------------------------------------------------------------- /library/mctp_responder_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_mctp_responder_lib 8 | mctp_dispatch.c 9 | pldm_dispatch.c 10 | pldm_rsp_control_get_tid.c 11 | ) 12 | 13 | add_library(mctp_responder_lib STATIC ${src_mctp_responder_lib}) 14 | -------------------------------------------------------------------------------- /library/pci_doe_requester_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_pci_doe_requester_lib 8 | pci_doe_req_discovery.c 9 | pci_doe_spdm_vendor_send_receive.c 10 | ) 11 | 12 | add_library(pci_doe_requester_lib STATIC ${src_pci_doe_requester_lib}) 13 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | 4 | # Ref: https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot#example-dependabotyml-file-for-github-actions 5 | - package-ecosystem: "github-actions" 6 | directory: "/" 7 | schedule: 8 | # Check for updates to GitHub Actions every week 9 | interval: "weekly" -------------------------------------------------------------------------------- /library/mctp_requester_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_mctp_requester_lib 8 | mctp_send_receive.c 9 | pldm_send_receive.c 10 | pldm_req_control_get_tid.c 11 | ) 12 | 13 | add_library(mctp_requester_lib STATIC ${src_mctp_requester_lib}) 14 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/SampleTestKey/ecc-private-key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PARAMETERS----- 2 | BggqhkjOPQMBBw== 3 | -----END EC PARAMETERS----- 4 | -----BEGIN EC PRIVATE KEY----- 5 | MHcCAQEEIJhpdYVDD321nmG6UKGA1qbegCVRKeN8KuRvQljfap1QoAoGCCqGSM49 6 | AwEHoUQDQgAEvFmmGssG2SUTuzohvR75iIOKwTWx2F4nVEd6amLu4K2vq6yN0Bqc 7 | 6Or/j7mPia858sWFUYRwz59YIfyGY4917Q== 8 | -----END EC PRIVATE KEY----- 9 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/spdm_device_responder/support.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "spdm_responder.h" 8 | 9 | void libspdm_dump_hex_str(const uint8_t *buffer, size_t buffer_size) 10 | { 11 | } 12 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/cryptstublib/rand.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/debuglib.h" 9 | 10 | int rand() 11 | { 12 | LIBSPDM_ASSERT(false); 13 | return 1; 14 | } 15 | -------------------------------------------------------------------------------- /library/pci_ide_km_responder_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_pci_ide_km_responder_lib 8 | pci_ide_km_dispatch.c 9 | pci_ide_km_rsp_query.c 10 | pci_ide_km_rsp_key_prog.c 11 | pci_ide_km_rsp_key_set_go.c 12 | pci_ide_km_rsp_key_set_stop.c 13 | ) 14 | 15 | add_library(pci_ide_km_responder_lib STATIC ${src_pci_ide_km_responder_lib}) 16 | -------------------------------------------------------------------------------- /library/pci_ide_km_requester_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_pci_ide_km_requester_lib 8 | pci_ide_km_send_receive.c 9 | pci_ide_km_req_query.c 10 | pci_ide_km_req_key_prog.c 11 | pci_ide_km_req_key_set_go.c 12 | pci_ide_km_req_key_set_stop.c 13 | ) 14 | 15 | add_library(pci_ide_km_requester_lib STATIC ${src_pci_ide_km_requester_lib}) 16 | -------------------------------------------------------------------------------- /library/cxl_ide_km_responder_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_cxl_ide_km_responder_lib 8 | cxl_ide_km_dispatch.c 9 | cxl_ide_km_rsp_query.c 10 | cxl_ide_km_rsp_key_prog.c 11 | cxl_ide_km_rsp_key_set_go.c 12 | cxl_ide_km_rsp_key_set_stop.c 13 | cxl_ide_km_rsp_get_key.c 14 | ) 15 | 16 | add_library(cxl_ide_km_responder_lib STATIC ${src_cxl_ide_km_responder_lib}) 17 | -------------------------------------------------------------------------------- /library/pci_ide_km_device_lib_sample/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_pci_ide_km_device_lib_sample 8 | pci_ide_km_device_context.c 9 | pci_ide_km_device_query.c 10 | pci_ide_km_device_key_prog.c 11 | pci_ide_km_device_key_set_go.c 12 | pci_ide_km_device_key_set_stop.c 13 | ) 14 | 15 | add_library(pci_ide_km_device_lib_sample STATIC ${src_pci_ide_km_device_lib_sample}) 16 | -------------------------------------------------------------------------------- /library/cxl_ide_km_requester_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_cxl_ide_km_requester_lib 8 | cxl_ide_km_send_receive.c 9 | cxl_ide_km_req_query.c 10 | cxl_ide_km_req_key_prog.c 11 | cxl_ide_km_req_key_set_go.c 12 | cxl_ide_km_req_key_set_stop.c 13 | cxl_ide_km_req_get_key.c 14 | ) 15 | 16 | add_library(cxl_ide_km_requester_lib STATIC ${src_cxl_ide_km_requester_lib}) 17 | -------------------------------------------------------------------------------- /library/cxl_ide_km_device_lib_sample/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_cxl_ide_km_device_lib_sample 8 | cxl_ide_km_device_context.c 9 | cxl_ide_km_device_query.c 10 | cxl_ide_km_device_key_prog.c 11 | cxl_ide_km_device_key_set_go.c 12 | cxl_ide_km_device_key_set_stop.c 13 | cxl_ide_km_device_get_key.c 14 | ) 15 | 16 | add_library(cxl_ide_km_device_lib_sample STATIC ${src_cxl_ide_km_device_lib_sample}) 17 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/rnglib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 4 | add_compile_options(-Werror) 5 | endif() 6 | 7 | include_directories(${SPDM_EMU_DIR}/include 8 | ${SPDM_DEVICE_DIR}/include 9 | ${LIBSPDM_DIR}/include 10 | ${LIBSPDM_DIR}/include/hal 11 | ${LIBSPDM_DIR}/include/hal/${ARCH} 12 | ) 13 | 14 | set(src_rnglib 15 | rnglib.c 16 | ) 17 | 18 | add_library(rnglib STATIC ${src_rnglib}) 19 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/debuglib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 4 | add_compile_options(-Werror) 5 | endif() 6 | 7 | include_directories(${SPDM_EMU_DIR}/include 8 | ${SPDM_DEVICE_DIR}/include 9 | ${LIBSPDM_DIR}/include 10 | ${LIBSPDM_DIR}/include/hal 11 | ${LIBSPDM_DIR}/include/hal/${ARCH} 12 | ) 13 | 14 | set(src_debuglib 15 | debuglib.c 16 | ) 17 | 18 | add_library(debuglib STATIC ${src_debuglib}) 19 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/platform_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 4 | add_compile_options(-Werror) 5 | endif() 6 | 7 | include_directories(${SPDM_EMU_DIR}/include 8 | ${SPDM_DEVICE_DIR}/include 9 | ${LIBSPDM_DIR}/include 10 | ${LIBSPDM_DIR}/include/hal 11 | ${LIBSPDM_DIR}/include/hal/${ARCH} 12 | ) 13 | 14 | set(src_platform_lib 15 | time.c 16 | watchdog.c 17 | ) 18 | 19 | add_library(platform_lib STATIC ${src_platform_lib}) 20 | -------------------------------------------------------------------------------- /library/cxl_tsp_requester_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_cxl_tsp_requester_lib 8 | cxl_tsp_send_receive.c 9 | cxl_tsp_req_get_version.c 10 | cxl_tsp_req_get_capabilities.c 11 | cxl_tsp_req_set_configuration.c 12 | cxl_tsp_req_get_configuration.c 13 | cxl_tsp_req_get_configuration_report.c 14 | cxl_tsp_req_lock_configuration.c 15 | cxl_tsp_req_set_te_state.c 16 | ) 17 | 18 | add_library(cxl_tsp_requester_lib STATIC ${src_cxl_tsp_requester_lib}) 19 | -------------------------------------------------------------------------------- /include/library/pci_tdisp_common_lib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2024 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #ifndef PCI_TDISP_COMMON_LIB_H 8 | #define PCI_TDISP_COMMON_LIB_H 9 | 10 | #include "industry_standard/pci_tdisp.h" 11 | 12 | #define LIBTDISP_MAX_VERSION_COUNT 0x1 13 | #define LIBTDISP_INTERFACE_REPORT_MAX_SIZE 0x1000 14 | 15 | #define LIBTDISP_INTERFACE_REPORT_PORTION_LEN 0x40 16 | 17 | #define LIBTDISP_ERROR_MESSAGE_MAX_SIZE (sizeof(pci_tdisp_error_response_t)) 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /library/pci_tdisp_requester_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_pci_tdisp_requester_lib 8 | pci_tdisp_send_receive.c 9 | pci_tdisp_req_get_version.c 10 | pci_tdisp_req_get_capabilities.c 11 | pci_tdisp_req_lock_interface.c 12 | pci_tdisp_req_get_interface_report.c 13 | pci_tdisp_req_get_interface_state.c 14 | pci_tdisp_req_start_interface.c 15 | pci_tdisp_req_stop_interface.c 16 | ) 17 | 18 | add_library(pci_tdisp_requester_lib STATIC ${src_pci_tdisp_requester_lib}) 19 | -------------------------------------------------------------------------------- /library/cxl_tsp_responder_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_cxl_tsp_responder_lib 8 | cxl_tsp_dispatch.c 9 | cxl_tsp_rsp_get_version.c 10 | cxl_tsp_rsp_get_capabilities.c 11 | cxl_tsp_rsp_set_configuration.c 12 | cxl_tsp_rsp_get_configuration.c 13 | cxl_tsp_rsp_get_configuration_report.c 14 | cxl_tsp_rsp_lock_configuration.c 15 | cxl_tsp_rsp_set_te_state.c 16 | cxl_tsp_rsp_error.c 17 | ) 18 | 19 | add_library(cxl_tsp_responder_lib STATIC ${src_cxl_tsp_responder_lib}) 20 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/debuglib/debuglib.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include 8 | 9 | #include "library/debuglib.h" 10 | 11 | void libspdm_debug_assert(const char *file_name, size_t line_number, 12 | const char *description) 13 | { 14 | LIBSPDM_ASSERT(false); 15 | } 16 | 17 | void libspdm_debug_print(size_t error_level, const char *format, ...) 18 | { 19 | LIBSPDM_ASSERT(false); 20 | } 21 | -------------------------------------------------------------------------------- /library/pci_tdisp_responder_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_pci_tdisp_responder_lib 8 | pci_tdisp_dispatch.c 9 | pci_tdisp_rsp_error.c 10 | pci_tdisp_rsp_version.c 11 | pci_tdisp_rsp_capabilities.c 12 | pci_tdisp_rsp_lock_interface.c 13 | pci_tdisp_rsp_interface_report.c 14 | pci_tdisp_rsp_interface_state.c 15 | pci_tdisp_rsp_start_interface.c 16 | pci_tdisp_rsp_stop_interface.c 17 | ) 18 | 19 | add_library(pci_tdisp_responder_lib STATIC ${src_pci_tdisp_responder_lib}) 20 | -------------------------------------------------------------------------------- /library/cxl_tsp_device_lib_sample/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_cxl_tsp_device_lib_sample 8 | cxl_tsp_device_context.c 9 | cxl_tsp_device_get_version.c 10 | cxl_tsp_device_get_capabilities.c 11 | cxl_tsp_device_set_configuration.c 12 | cxl_tsp_device_get_configuration.c 13 | cxl_tsp_device_get_configuration_report.c 14 | cxl_tsp_device_lock_configuration.c 15 | cxl_tsp_device_set_te_state.c 16 | ) 17 | 18 | add_library(cxl_tsp_device_lib_sample STATIC ${src_cxl_tsp_device_lib_sample}) 19 | -------------------------------------------------------------------------------- /library/pci_tdisp_device_lib_sample/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | include_directories(${LIBSPDM_DIR}/include 4 | ${SPDM_EMU_DIR}/include 5 | ) 6 | 7 | set(src_pci_tdisp_device_lib_sample 8 | pci_tdisp_device_context.c 9 | pci_tdisp_device_version.c 10 | pci_tdisp_device_capabilities.c 11 | pci_tdisp_device_lock_interface.c 12 | pci_tdisp_device_interface_report.c 13 | pci_tdisp_device_interface_state.c 14 | pci_tdisp_device_start_interface.c 15 | pci_tdisp_device_stop_interface.c 16 | ) 17 | 18 | add_library(pci_tdisp_device_lib_sample STATIC ${src_pci_tdisp_device_lib_sample}) 19 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/platform_lib/time.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/debuglib.h" 9 | 10 | /** 11 | * Suspends the execution of the current thread until the time-out interval elapses. 12 | * 13 | * @param milliseconds The time interval for which execution is to be suspended, in milliseconds. 14 | * 15 | **/ 16 | void libspdm_sleep(uint64_t milliseconds) 17 | { 18 | LIBSPDM_ASSERT(false); 19 | } 20 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/cryptstublib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 4 | add_compile_options(-Wno-incompatible-pointer-types -Wno-pointer-sign) 5 | add_compile_options(-Werror) 6 | endif() 7 | 8 | include_directories(${SPDM_EMU_DIR}/include 9 | ${SPDM_DEVICE_DIR}/include 10 | ${LIBSPDM_DIR}/include 11 | ${LIBSPDM_DIR}/include/hal/${ARCH} 12 | ${LIBSPDM_DIR}/os_stub/include 13 | ) 14 | 15 | set(src_cryptstublib 16 | rand.c 17 | timeclock.c 18 | ) 19 | 20 | add_library(cryptstublib STATIC ${src_cryptstublib}) 21 | -------------------------------------------------------------------------------- /spdm_emu/spdm_requester_emu/spdm_requester_mctp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "spdm_requester_emu.h" 8 | 9 | void *m_mctp_context; 10 | 11 | libspdm_return_t mctp_process_session_message(void *spdm_context, uint32_t session_id) 12 | { 13 | uint8_t tid; 14 | libspdm_return_t status; 15 | 16 | status = pldm_control_get_tid (m_mctp_context, spdm_context, &session_id, &tid); 17 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 18 | return status; 19 | } 20 | 21 | return LIBSPDM_STATUS_SUCCESS; 22 | } 23 | -------------------------------------------------------------------------------- /include/library/mctp_common_lib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #ifndef __MCTP_COMMON_LIB_H__ 8 | #define __MCTP_COMMON_LIB_H__ 9 | 10 | #include "industry_standard/mctp.h" 11 | #include "industry_standard/pldm.h" 12 | 13 | 14 | /* MCTP app message - check below configuration 15 | * only PLDM*/ 16 | #define MCTP_MAX_MESSAGE_SIZE 0x100 17 | 18 | /* defintion for library*/ 19 | typedef struct { 20 | uint8_t pldm_type; /* BIT[0:5] type, BIT[6:7] RSVD*/ 21 | uint8_t pldm_command_code; 22 | } pldm_dispatch_type_t; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/spdm_device_secret_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 4 | add_compile_options(-Werror) 5 | endif() 6 | 7 | include_directories(${SPDM_DEVICE_DIR}/include 8 | ${SPDM_EMU_DIR}/include 9 | spdm_device_secret_lib 10 | ${LIBSPDM_DIR}/include 11 | ${LIBSPDM_DIR}/include/hal 12 | ${LIBSPDM_DIR}/os_stub 13 | ) 14 | 15 | set(src_spdm_device_secret_lib 16 | meas.c 17 | read_priv_key_raw_data.c 18 | read_pub_cert.c 19 | sign.c 20 | ) 21 | 22 | add_library(spdm_device_secret_lib STATIC ${src_spdm_device_secret_lib}) 23 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_ide_km_device_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 4 | add_compile_options(-Werror) 5 | endif() 6 | 7 | include_directories(${SPDM_DEVICE_DIR}/include 8 | ${LIBSPDM_DIR}/include 9 | ${LIBSPDM_DIR}/include/hal/${ARCH} 10 | ${SPDM_EMU_DIR}/include 11 | ) 12 | 13 | set(src_pci_ide_km_device_lib 14 | pci_ide_km_device_context.c 15 | pci_ide_km_device_query.c 16 | pci_ide_km_device_key_prog.c 17 | pci_ide_km_device_key_set_go.c 18 | pci_ide_km_device_key_set_stop.c 19 | ) 20 | 21 | add_library(pci_ide_km_device_lib STATIC ${src_pci_ide_km_device_lib}) 22 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/rnglib/rnglib.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/debuglib.h" 9 | 10 | /** 11 | * Generates a 64-bit random number. 12 | * 13 | * @param[out] rand_data buffer pointer to store the 64-bit random value. 14 | * 15 | * @retval true Random number generated successfully. 16 | * @retval false Failed to generate the random number. 17 | * 18 | **/ 19 | bool libspdm_get_random_number_64(uint64_t *rand_data) 20 | { 21 | LIBSPDM_ASSERT(false); 22 | return true; 23 | } 24 | -------------------------------------------------------------------------------- /include/library/pci_doe_common_lib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #ifndef __PCI_DOE_COMMON_LIB_H__ 8 | #define __PCI_DOE_COMMON_LIB_H__ 9 | 10 | #include "industry_standard/pcidoe.h" 11 | 12 | /* PCI DOE - check below configuration 13 | * only Discovery*/ 14 | #define LIBPCIDOE_MAX_NON_SPDM_MESSAGE_SIZE 12 15 | /* PCI DOE SPDM Vendor Defined - check below configuration 16 | * only IDE_KM*/ 17 | #define LIBPCIDOE_SPDM_VENDOR_MAX_MESSAGE_SIZE 0x400 18 | 19 | /* defintion for library*/ 20 | typedef struct { 21 | uint16_t vendor_id; 22 | uint8_t data_object_type; 23 | } pci_doe_data_object_protocol_t; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_tdisp_device_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 4 | add_compile_options(-Werror) 5 | endif() 6 | 7 | include_directories(${SPDM_DEVICE_DIR}/include 8 | ${LIBSPDM_DIR}/include 9 | ${LIBSPDM_DIR}/include/hal/${ARCH} 10 | ${SPDM_EMU_DIR}/include 11 | ) 12 | 13 | set(src_pci_tdisp_device_lib 14 | pci_tdisp_device_context.c 15 | pci_tdisp_device_version.c 16 | pci_tdisp_device_capabilities.c 17 | pci_tdisp_device_lock_interface.c 18 | pci_tdisp_device_interface_report.c 19 | pci_tdisp_device_interface_state.c 20 | pci_tdisp_device_start_interface.c 21 | pci_tdisp_device_stop_interface.c 22 | ) 23 | 24 | add_library(pci_tdisp_device_lib STATIC ${src_pci_tdisp_device_lib}) 25 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_validator_sample/spdm_device_validator_sample.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #ifndef __SPDM_DEVICE_VALIDATOR_SAMPLE_H__ 8 | #define __SPDM_DEVICE_VALIDATOR_SAMPLE_H__ 9 | 10 | #include "hal/base.h" 11 | #include "hal/library/memlib.h" 12 | #include "library/spdm_requester_lib.h" 13 | #include "library/spdm_transport_none_lib.h" 14 | #include "library/spdm_transport_mctp_lib.h" 15 | #include "library/spdm_transport_pcidoe_lib.h" 16 | #include "library/mctp_requester_lib.h" 17 | #include "library/pci_doe_requester_lib.h" 18 | #include "library/spdm_responder_conformance_test_lib.h" 19 | 20 | #include "os_include.h" 21 | #include "stdio.h" 22 | #include "spdm_emu.h" 23 | 24 | extern common_test_suite_config_t m_spdm_responder_validator_config; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /script/format_nix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Executes the Uncrustify code beautifier. 4 | # Beautification is needed to pass the CI/CD checks for a pull request. 5 | # This script can be run from any directory within the libspdm repository. 6 | 7 | set -e 8 | 9 | # Check if uncrustify is present. 10 | if ! command -v uncrustify &> /dev/null 11 | then 12 | echo "ERROR: Unable to execute uncrustify." 13 | exit 1 14 | fi 15 | 16 | # Change directory to top of repository. 17 | cd `dirname $0` 18 | cd ../ 19 | 20 | # Exclude non-libspdm submodules. 21 | EXCLUDE_PATH1="./libspdm/*" 22 | 23 | # Run uncrustify. 24 | if [ $# -eq 0 ]; 25 | then 26 | find -not -path "$EXCLUDE_PATH1" \ 27 | \( -name "*.c" -o -name "*.h" \) -exec uncrustify -q -c ./.uncrustify.cfg --replace --no-backup {} + 28 | exit $? 29 | elif [ $1 = "--check" ]; 30 | then 31 | find -not -path "$EXCLUDE_PATH1" \ 32 | \( -name "*.c" -o -name "*.h" \) -exec uncrustify -q -c ./.uncrustify.cfg --check {} + 33 | exit $? 34 | else 35 | echo "ERROR: Unknown argument." 36 | exit 1 37 | fi 38 | -------------------------------------------------------------------------------- /spdm_emu/spdm_responder_emu/spdm_responder_emu.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2025 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #ifndef __SPDM_RESPONDER_TEST_H__ 8 | #define __SPDM_RESPONDER_TEST_H__ 9 | 10 | #include "hal/base.h" 11 | #include "hal/library/memlib.h" 12 | #include "industry_standard/spdm_tcp_binding.h" 13 | #include "library/spdm_responder_lib.h" 14 | #include "library/spdm_transport_none_lib.h" 15 | #include "library/spdm_transport_mctp_lib.h" 16 | #include "library/spdm_transport_pcidoe_lib.h" 17 | #include "library/spdm_transport_tcp_lib.h" 18 | #include "library/mctp_responder_lib.h" 19 | #include "library/pci_doe_responder_lib.h" 20 | #include "library/pci_ide_km_responder_lib.h" 21 | #include "library/pci_tdisp_responder_lib.h" 22 | #include "library/cxl_ide_km_responder_lib.h" 23 | #include "library/cxl_tsp_responder_lib.h" 24 | 25 | #include "os_include.h" 26 | #include 27 | #include "spdm_emu.h" 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /spdm_emu/spdm_requester_emu/spdm_requester_emu.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2025 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #ifndef __SPDM_REQUESTER_TEST_H__ 8 | #define __SPDM_REQUESTER_TEST_H__ 9 | 10 | #include "hal/base.h" 11 | #include "hal/library/memlib.h" 12 | #include "industry_standard/spdm_tcp_binding.h" 13 | #include "library/spdm_requester_lib.h" 14 | #include "library/spdm_transport_none_lib.h" 15 | #include "library/spdm_transport_mctp_lib.h" 16 | #include "library/spdm_transport_pcidoe_lib.h" 17 | #include "library/spdm_transport_tcp_lib.h" 18 | #include "library/mctp_requester_lib.h" 19 | #include "library/pci_doe_requester_lib.h" 20 | #include "library/pci_ide_km_requester_lib.h" 21 | #include "library/pci_tdisp_requester_lib.h" 22 | #include "library/cxl_ide_km_requester_lib.h" 23 | #include "library/cxl_tsp_requester_lib.h" 24 | 25 | #include "os_include.h" 26 | #include "stdio.h" 27 | #include "spdm_emu.h" 28 | 29 | extern uint8_t m_other_slot_id; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/SampleTestKey/example.cer.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC/zCCAeegAwIBAgIUEC/C2kDCk1FbbxWDMjSNhcxsnfkwDQYJKoZIhvcNAQEL 3 | BQAwDzENMAsGA1UEAwwEdGVzdDAeFw0yMDA2MTUwMzAzNTNaFw0yMDA2MTYwMzAz 4 | NTNaMA8xDTALBgNVBAMMBHRlc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK 5 | AoIBAQDio8/jCx687P5RrkfOS/o4uJGVypSCgv7SmHWpCh1J7ATtx8T0GanFMOKK 6 | vaY1K7Qftobm5DfMQRgCVxeywprHd25tg9VzW7bBn6DTaQ8+tbyNjFnNHB//04An 7 | w+K2+JwwQmAu2Rfh+yl3JAKZcLES/0S3chL3lYT2IdC1W68yvZWTqegQXg4xyqyM 8 | pJj5jaXa5SbHLMEPzHD+NIzzhkyBSPugDwe95tnbKTrOVupMdURN7xgJiMqBc5Sk 9 | uG02yzk1cuPiE4JMRyOE7tG1SCWbSjGVn92HPvRw6FwQuMqbSKL3LTZWNF3Pf0Mb 10 | p4JezIj2cqAhErXqWP0DLV8rMhSlAgMBAAGjUzBRMB0GA1UdDgQWBBTuO0+UNQtt 11 | RcrJ4PgjZm1YtvJ2HjAfBgNVHSMEGDAWgBTuO0+UNQttRcrJ4PgjZm1YtvJ2HjAP 12 | BgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBfwbjiJFgTevrLFTX1 13 | AKUfcm10OsAOP4YMccqCTzC6K2tnlUUofDORZCn0Aaczz3P55LCvNV6BmGuyerzY 14 | VpbASM1Z1f5w9a7Ew0dGqAgOOuP6ehW+58NHjHP+hIS4zHIyY3n3A7jutNOFb5Kp 15 | F7xQXahHP8WoaJHBsPVIsGyePFWUXIU+Tqf1mTvVB0F4i9KaUosvlN2M6AhAJ5lj 16 | h7uWDPTAomJ5bW28+E5Bp5zOdGnWTdvAaftaISdEI3yMJqzwAb0e5AElJlO2T3kC 17 | yUf1kfzXE4Xe+XlYCsOOuwB/olXX1JkVZ0QFSDR3yKPKG2KoTFjhHtzGv7B5npC+ 18 | HjE4 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/platform_lib/watchdog.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/debuglib.h" 9 | 10 | /** 11 | * If no heartbeat arrives in seconds, the watchdog timeout event 12 | * should terminate the session. 13 | * 14 | * @param session_id Indicate the SPDM session ID. 15 | * @param seconds heartbeat period, in seconds. 16 | * 17 | **/ 18 | bool libspdm_start_watchdog(uint32_t session_id, uint16_t seconds) 19 | { 20 | LIBSPDM_ASSERT(false); 21 | return true; 22 | } 23 | 24 | /** 25 | * stop watchdog. 26 | * 27 | * @param session_id Indicate the SPDM session ID. 28 | * 29 | **/ 30 | bool libspdm_stop_watchdog(uint32_t session_id) 31 | { 32 | LIBSPDM_ASSERT(false); 33 | return true; 34 | } 35 | 36 | /** 37 | * Reset the watchdog in heartbeat response. 38 | * 39 | * @param session_id Indicate the SPDM session ID. 40 | * 41 | **/ 42 | bool libspdm_reset_watchdog(uint32_t session_id) 43 | { 44 | LIBSPDM_ASSERT(false); 45 | return true; 46 | } 47 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_attester_sample/spdm_device_attester_pci_doe.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "spdm_device_attester_sample.h" 8 | 9 | void *m_pci_doe_context; 10 | #define DOE_DISCOVERY_VERSION 0 11 | 12 | libspdm_return_t pci_doe_init_request() 13 | { 14 | pci_doe_data_object_protocol_t data_object_protocol[6]; 15 | size_t data_object_protocol_size; 16 | libspdm_return_t status; 17 | uint32_t index; 18 | 19 | data_object_protocol_size = sizeof(data_object_protocol); 20 | status = 21 | pci_doe_discovery (m_pci_doe_context, data_object_protocol, &data_object_protocol_size, DOE_DISCOVERY_VERSION); 22 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 23 | return status; 24 | } 25 | 26 | for (index = 0; index < data_object_protocol_size/sizeof(pci_doe_data_object_protocol_t); 27 | index++) { 28 | printf("DOE(0x%x) VendorId-0x%04x, DataObjectType-0x%02x\n", 29 | index, data_object_protocol[index].vendor_id, 30 | data_object_protocol[index].data_object_type); 31 | } 32 | 33 | return LIBSPDM_STATUS_SUCCESS; 34 | } 35 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_validator_sample/spdm_device_validator_pci_doe.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "spdm_device_validator_sample.h" 8 | 9 | void *m_pci_doe_context; 10 | #define DOE_DISCOVERY_VERSION 0 11 | 12 | libspdm_return_t pci_doe_init_request() 13 | { 14 | pci_doe_data_object_protocol_t data_object_protocol[6]; 15 | size_t data_object_protocol_size; 16 | libspdm_return_t status; 17 | uint32_t index; 18 | 19 | data_object_protocol_size = sizeof(data_object_protocol); 20 | status = 21 | pci_doe_discovery (m_pci_doe_context, data_object_protocol, &data_object_protocol_size, DOE_DISCOVERY_VERSION); 22 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 23 | return status; 24 | } 25 | 26 | for (index = 0; index < data_object_protocol_size/sizeof(pci_doe_data_object_protocol_t); 27 | index++) { 28 | printf("DOE(0x%x) VendorId-0x%04x, DataObjectType-0x%02x\n", 29 | index, data_object_protocol[index].vendor_id, 30 | data_object_protocol[index].data_object_type); 31 | } 32 | 33 | return LIBSPDM_STATUS_SUCCESS; 34 | } 35 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/spdm_device_responder/spdm_responder_main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "spdm_responder.h" 8 | 9 | 10 | /* Disable optimization to avoid code removal with VS2019.*/ 11 | 12 | #if defined(_MSC_EXTENSIONS) 13 | #pragma optimize("", off) 14 | #elif defined (__clang__) 15 | #pragma clang optimize off 16 | #endif 17 | 18 | void spdm_dispatch(void) 19 | { 20 | void *spdm_context; 21 | libspdm_return_t status; 22 | 23 | spdm_context = spdm_server_init(); 24 | if (spdm_context == NULL) { 25 | return; 26 | } 27 | 28 | status = pci_doe_init_responder (); 29 | if (status != LIBSPDM_STATUS_SUCCESS) { 30 | return; 31 | } 32 | 33 | while (true) { 34 | status = libspdm_responder_dispatch_message(spdm_context); 35 | if (status != LIBSPDM_STATUS_UNSUPPORTED_CAP) { 36 | continue; 37 | } 38 | } 39 | return; 40 | } 41 | 42 | /** 43 | * Main entry point. 44 | * 45 | * @return This function should never return. 46 | * 47 | **/ 48 | void ModuleEntryPoint(void) 49 | { 50 | spdm_dispatch(); 51 | 52 | return; 53 | } 54 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/SampleEvidence/SpdmSampleMeasurement.json: -------------------------------------------------------------------------------- 1 | { 2 | "evidences": [ 3 | { 4 | "evidence": { 5 | "index": 1, 6 | "digest": [ 7 | 8, 8 | "8d531d77d821e167114d1eb07e0ae19cfb565152408843c768f1135b548fdfa13a203e5c7f129ceacc017df26c999f62da26dbf2e1128345ec0f65d37f87ca41" 9 | ] 10 | } 11 | }, 12 | { 13 | "evidence": { 14 | "index": 2, 15 | "digest": [ 16 | 8, 17 | "9effd8a668f76d3fce35451a136f8ef6710260e9ca28beef897f559fcdba48a4c066560fb4900195cae4d4fab1f7d11243421008af8614d92a3fcabbbf75248f" 18 | ] 19 | } 20 | }, 21 | { 22 | "evidence": { 23 | "index": 3, 24 | "digest": [ 25 | 8, 26 | "ffde42483a687dd47d05f956a2d62007b71a2988084da1095ec2e43bca156680cae07d0b84cbc7fc9b1d4e80cd8669aa956aed8bb17b0a20a5031c288dfa8b9f" 27 | ] 28 | } 29 | }, 30 | { 31 | "evidence": { 32 | "index": 4, 33 | "digest": [ 34 | 8, 35 | "3a0bd5b08436b1d386122090cfa0446cf2571b74f2a15f44df735695dab84bbb1bebb3aef39af6a0f97279b5fb04d513a52dd16547fe88d0455815520c861ed4" 36 | ] 37 | } 38 | }, 39 | { 40 | "evidence": { 41 | "index": 16, 42 | "svn": 7 43 | } 44 | } 45 | ] 46 | } -------------------------------------------------------------------------------- /spdm_emu/spdm_emu_common/command.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2025 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #ifndef __SPDM_TEST_COMMAND_H__ 8 | #define __SPDM_TEST_COMMAND_H__ 9 | 10 | #define DEFAULT_SPDM_PLATFORM_PORT 2323 11 | #define TCP_SPDM_PLATFORM_PORT 4194 12 | 13 | 14 | /* Client->Server/Server->Client 15 | * command/response: 4 bytes (big endian) 16 | * transport_type: 4 bytes (big endian) 17 | * PayloadSize (excluding command and PayloadSize): 4 bytes (big endian) 18 | * payload (SPDM message, starting from SPDM_HEADER): PayloadSize (little endian)*/ 19 | 20 | 21 | #define SOCKET_TRANSPORT_TYPE_NONE 0x00 22 | #define SOCKET_TRANSPORT_TYPE_MCTP 0x01 23 | #define SOCKET_TRANSPORT_TYPE_PCI_DOE 0x02 24 | #define SOCKET_TRANSPORT_TYPE_TCP 0x03 25 | 26 | #define SOCKET_TCP_NO_ROLE_INQUIRY 0x00 27 | #define SOCKET_TCP_ROLE_INQUIRY 0x01 28 | 29 | #define SOCKET_SPDM_COMMAND_NORMAL 0x0001 30 | #define SOCKET_SPDM_COMMAND_OOB_ENCAP_KEY_UPDATE 0x8001 31 | #define SOCKET_SPDM_COMMAND_OOB_ENCAP_ENDPOINT_INFO 0x8002 32 | #define SOCKET_SPDM_COMMAND_CONTINUE 0xFFFD 33 | #define SOCKET_SPDM_COMMAND_SHUTDOWN 0xFFFE 34 | #define SOCKET_SPDM_COMMAND_UNKOWN 0xFFFF 35 | #define SOCKET_SPDM_COMMAND_TEST 0xDEAD 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /spdm_emu/spdm_emu_common/os_include.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #ifndef __WIN_NT_INCLUDE_H__ 8 | #define __WIN_NT_INCLUDE_H__ 9 | 10 | #ifdef _MSC_VER 11 | /* MSVC*/ 12 | 13 | /* Win32 include files do not compile clean with /W4, so we use the warning 14 | * pragma to suppress the warnings for Win32 only. This way our code can stil 15 | * compile at /W4 (highest warning level) with /WX (warnings cause build 16 | * errors).*/ 17 | 18 | #pragma warning(disable : 4115) 19 | #pragma warning(disable : 4201) 20 | #pragma warning(disable : 4028) 21 | #pragma warning(disable : 4133) 22 | 23 | #include "WinSock2.h" 24 | #include "winioctl.h" 25 | #include "windows.h" 26 | #include "windowsx.h" 27 | #include "WS2tcpip.h" 28 | 29 | 30 | /* Set the warnings back on as the EFI code must be /W4.*/ 31 | 32 | #pragma warning(default : 4115) 33 | #pragma warning(default : 4201) 34 | 35 | #else 36 | /* GCC*/ 37 | #include "stdio.h" 38 | #include "stdlib.h" 39 | #include "unistd.h" 40 | #include "errno.h" 41 | #include "sys/socket.h" 42 | #include "arpa/inet.h" 43 | typedef int SOCKET; 44 | #define closesocket(x) close(x) 45 | #define INVALID_SOCKET (-1) 46 | #define SOCKET_ERROR (-1) 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/SpdmSamplePolicy.rego: -------------------------------------------------------------------------------- 1 | # OPA playground: https://play.openpolicyagent.org/ 2 | 3 | package spdm 4 | 5 | evidence_arr := input.evidence.evidences 6 | 7 | reference_arr := input.reference.corim.unsigned_corim_map.corim_tags[0].comid_triples.comid_reference_triples 8 | 9 | ev_hash_list[hash] { 10 | evidence := evidence_arr[_] 11 | digest := evidence.evidence.digest 12 | hash := digest[1] 13 | } 14 | 15 | ev_svn[svn] { 16 | evidence := evidence_arr[_] 17 | svn := evidence.evidence.svn 18 | } 19 | 20 | ref_hash_list[hash] { 21 | references := reference_arr[_] 22 | reference := references[_] 23 | hashes := reference.comid_mval.comid_digests[0] 24 | hash := hashes[1] 25 | } 26 | 27 | ref_svn[svn] { 28 | references := reference_arr[_] 29 | reference := references[_] 30 | svn := reference.comid_mval.comid_svn 31 | } 32 | 33 | default SPDM_HASH_CHECK = false 34 | SPDM_HASH_CHECK { 35 | ev_hash_list == ref_hash_list 36 | } 37 | 38 | default SPDM_SVN_CHECK = false 39 | SPDM_SVN_CHECK { 40 | ev_svn == ref_svn 41 | } 42 | 43 | default error_code = 1 44 | error_code = 0 { 45 | SPDM_HASH_CHECK 46 | SPDM_SVN_CHECK 47 | } 48 | 49 | # Output: error code, hash check, svn check 50 | output := { 51 | "error_code": error_code, 52 | "SPDM_HASH_CHECK": SPDM_HASH_CHECK, 53 | "SPDM_SVN_CHECK": SPDM_SVN_CHECK, 54 | } -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/SampleTestKey/SampleCertChain/TestSub.pub.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDdTCCAl2gAwIBAgIBAzANBgkqhkiG9w0BAQsFADBSMQswCQYDVQQGEwJDTjEL 3 | MAkGA1UECAwCU0gxCzAJBgNVBAcMAlNIMQ4wDAYDVQQKDAVJTlRFTDEMMAoGA1UE 4 | CwwDU1NHMQswCQYDVQQDDAIwMDAeFw0yMDA4MTMwNzI1NDZaFw0zMDA4MTEwNzI1 5 | NDZaMEUxCzAJBgNVBAYTAkNOMQswCQYDVQQIDAJTSDEOMAwGA1UECgwFSU5URUwx 6 | DDAKBgNVBAsMA1NTRzELMAkGA1UEAwwCMDEwggEiMA0GCSqGSIb3DQEBAQUAA4IB 7 | DwAwggEKAoIBAQC4mNw7Gcjptz7KOABt5uAvvjNQWsiDBoJNwszOOQhMtl9H8bhR 8 | vf88bXGQe7Z4UyvzKJvupa1eXYBBF7y4MbIfXX8dB5jrf91KV1Sr1gFcyj27sn1Q 9 | ggshratY3m2LDInW+/ZGdqQzesKtG0+/ZfL2pWmFP2H+Hso5l2lZBXtw14DN3mHj 10 | 6+cqbfQiy7X0UZWuGkdnep1gXKyYKG0jgEIoTaT6IPp2o1dcQOExeDTK1C4qKXGE 11 | o9F6aMwqxFdDeQOLacqyWnJr+4kQR8nLa2PDB4qSdo+YYJb9DDwqsKbpuVwoIADV 12 | KtsjIyk8vos+V8j/cFDGrytz7fnyEzoEAujbAgMBAAGjYzBhMB0GA1UdDgQWBBS5 13 | 7lQ3yQYDdNHG3slQ1HdTLc74HzAfBgNVHSMEGDAWgBSinUdaXu4IcozoI8EBdxho 14 | 62gsNzAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG9w0B 15 | AQsFAAOCAQEAqgU+7z81ShaK1MefN/gMaBhxMYvXQZavg8L+k4kwXA7fqaT0bnTc 16 | xfFbEEOf6IMNOA3+bEgy6iZYXxfLU9ebV929PBP/72cHVVsZXbJ9aWDw/HkkUHWw 17 | wca4mRtkWpfaotaY/vOVamopmEB8n/CbvTu/53UNn0wOwXjmyl6cgfcaIWsAsxsV 18 | hjTTd8fW01CloqFJI+SylcOkPxhY05G6L/Uw39YyXphE7/p+TBf5Og3ey6oB72u3 19 | rRBQHriwaXlVDkDoZFoje2C7Q02a6GdrYwWEy8OLJmyoWVG0zGgQzFnipk0nlzKy 20 | adagmbW/s+rwV+HJZxlZHcMXp76WJooX7A== 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/SampleTestKey/SampleCertChain/TestRoot.pub.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDlTCCAn2gAwIBAgIUHiTnjvf1RJ+YNfhITRhJ+RGS50swDQYJKoZIhvcNAQEL 3 | BQAwUjELMAkGA1UEBhMCQ04xCzAJBgNVBAgMAlNIMQswCQYDVQQHDAJTSDEOMAwG 4 | A1UECgwFSU5URUwxDDAKBgNVBAsMA1NTRzELMAkGA1UEAwwCMDAwHhcNMjAwODEz 5 | MDcyNDIzWhcNMzAwODExMDcyNDIzWjBSMQswCQYDVQQGEwJDTjELMAkGA1UECAwC 6 | U0gxCzAJBgNVBAcMAlNIMQ4wDAYDVQQKDAVJTlRFTDEMMAoGA1UECwwDU1NHMQsw 7 | CQYDVQQDDAIwMDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOnAS4jc 8 | ZrBkXhYsOayJ30cJAiRmBfi63aMgmNm1++qdmqiPIoBXkWxgjSHZmm+baQcGXXwP 9 | uHXiAD7YWgPAZZ0W1zczgejGYgsGLA1wsFCYA37BgzUijEHjh075J+uCm4pGMj2k 10 | Knwo/c8clnVV/hWQhWbWJGY+L9ddPfn5mPKVuxJ6d7GHQoYUDREWrJT5K6b+R1LJ 11 | CEvZAColmcw6C5UJjY/qsBwHrxMbowdl5inQj36UmSRU72mKyIzvPY92clmyeZGs 12 | iCfQXjAfu9knwinMQaVRgUe6CDRHsAux95ddBP/NkzUgdvFvlzRvNN3gZUscxZHM 13 | Us/l5ciwmwe4SIUCAwEAAaNjMGEwHQYDVR0OBBYEFKKdR1pe7ghyjOgjwQF3GGjr 14 | aCw3MB8GA1UdIwQYMBaAFKKdR1pe7ghyjOgjwQF3GGjraCw3MA8GA1UdEwEB/wQF 15 | MAMBAf8wDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3DQEBCwUAA4IBAQCUcf1ufbcz 16 | BlaNlji4U1UUf4QCOWWLtSj1AW3LMvjh0a7aYl/rUdnAKtm9mCeDGsfkVoq5HKcr 17 | wvcXz0eNFoRXAayv5Gaa/iaTX6gKIJB6QHKQqTT6SzoLUqEFquAvq27rmh16n8K2 18 | 9DDzOXlqSTh3FQmERunBGugMDSfpD4OCnwP3+6JbNOlEPXiD6viOQ3OU3jihWJVL 19 | pkwxKNH19oNHnX4VurBoIcVnZCyHHgM/rujSCfQkfngDPUhEyETWMuoQvjbaPHSR 20 | 0fTu/dhBgUxghVbkkqxtl22yEbczRpA5ODZi03INH2zhSLtaN8zI04IAClzsfZ3y 21 | nRey12VyWuKB 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_attester_sample/spdm_device_attester_sample.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #ifndef __SPDM_DEVICE_ATTESTER_SAMPLE_H__ 8 | #define __SPDM_DEVICE_ATTESTER_SAMPLE_H__ 9 | 10 | #include "hal/base.h" 11 | #include "hal/library/memlib.h" 12 | #include "library/spdm_requester_lib.h" 13 | #include "library/spdm_transport_none_lib.h" 14 | #include "library/spdm_transport_mctp_lib.h" 15 | #include "library/spdm_transport_pcidoe_lib.h" 16 | #include "library/mctp_requester_lib.h" 17 | #include "library/pci_doe_requester_lib.h" 18 | 19 | #include "os_include.h" 20 | #include "stdio.h" 21 | #include "spdm_emu.h" 22 | 23 | typedef struct { 24 | size_t cert_chain_size; 25 | uint8_t cert_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE]; 26 | } spdm_attester_cert_chain_struct_t; 27 | 28 | libspdm_return_t spdm_send_receive_get_measurement(void *spdm_context, 29 | const uint32_t *session_id, 30 | uint8_t slot_id, 31 | uint8_t *measurement_record, 32 | uint32_t *measurement_record_length); 33 | 34 | void spdm_device_evidence_collection (void *spdm_context); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/library/cxl_ide_km_common_lib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #ifndef __CXL_IDE_KM_COMMON_LIB_H__ 8 | #define __CXL_IDE_KM_COMMON_LIB_H__ 9 | 10 | #include "industry_standard/cxl_idekm.h" 11 | 12 | /* 13 | * +--------------------------------------+ 14 | * | CXL IDE Capability | 15 | * +--------------------------------------+ 16 | * | CXL_IDE Control | 17 | * +--------------------------------------+ 18 | * | CXL_IDE Status | 19 | * +--------------------------------------+ 20 | * | CXL_IDE Error Status | 21 | * +--------------------------------------+ 22 | * | Key Refresh Time Capability | 23 | * +--------------------------------------+ 24 | * | Truncation Transmit Delay Capability | 25 | * +--------------------------------------+ 26 | * | Key Refresh Time Control | 27 | * +--------------------------------------+ 28 | * | Truncation Transmit Delay Control | 29 | * +--------------------------------------+ 30 | * | Key Refresh Time Capability2 | 31 | * +--------------------------------------+ 32 | */ 33 | 34 | #define CXL_IDE_KM_IDE_CAP_REG_BLOCK_MAX_COUNT 9 35 | 36 | typedef struct { 37 | uint32_t key[8]; 38 | uint32_t iv[3]; 39 | } cxl_ide_km_aes_256_gcm_key_buffer_t; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/SampleTestKey/SampleCertChain/TestCert.pub.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDxDCCAqygAwIBAgIBBDANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJDTjEL 3 | MAkGA1UECAwCU0gxDjAMBgNVBAoMBUlOVEVMMQwwCgYDVQQLDANTU0cxCzAJBgNV 4 | BAMMAjAxMB4XDTIwMDgxMzA3MjY0OFoXDTMwMDgxMTA3MjY0OFowRTELMAkGA1UE 5 | BhMCQ04xCzAJBgNVBAgMAlNIMQ4wDAYDVQQKDAVJTlRFTDEMMAoGA1UECwwDU1NH 6 | MQswCQYDVQQDDAIwMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALSb 7 | UFUrLtZGyyqAez+3nONX6ui2nq5SmGLmiFcrlBMf3pmF2siFADHufa5L7T7EkAbk 8 | yizS0w9xMUk5cnOLhgnEUYeMtILWX1JLbtuIVWvzHGSfDLTnNpFR8ANEkmkVHZh9 9 | gIfVrJtjk7qzOkgdaTHWlK3VuaK5fTD9ZgekOKReE/6zJljDCXkOaY7hFBlx4d6f 10 | pNeV2795wyBM8ZrX8+ub2DWjqxlFSkbg96+1A2M996dO8nRmBHyCqc9T+UmS4eIi 11 | dAQ48l7rJRHKbZgQqSkn6C7RFpCRyZtNYSGPcU/EBIxhOmctiJv/HZAw4SwcRcV/ 12 | zB0hHVToLIFp55FhEYUCAwEAAaOBvjCBuzAJBgNVHRMEAjAAMBEGCWCGSAGG+EIB 13 | AQQEAwIFoDAsBglghkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlm 14 | aWNhdGUwHQYDVR0OBBYEFE2VLV4g5hcKw/kiK9XiSjox/kVrMB8GA1UdIwQYMBaA 15 | FLnuVDfJBgN00cbeyVDUd1MtzvgfMA4GA1UdDwEB/wQEAwIF4DAdBgNVHSUEFjAU 16 | BggrBgEFBQcDAgYIKwYBBQUHAwQwDQYJKoZIhvcNAQELBQADggEBAKmAjBNvA3gM 17 | GUR7xVNG7BiHOEZjBTgHT3Vk3rXskQl3eeBHNlxmu1DTowrNDk+WYFqzdxK/BOBt 18 | qjQq58jZK6wGgFMhpQbPBHvYr0sNR0IRFcVk+lqE0IFf0J1+RTTYA9hXP0SpH0dV 19 | lzfdaF9UMaXwNZ+W/U3sM0oQd9xREP/43aYQjgXwxuFsixt4XdjokWuMNd2ozRCh 20 | kyjicNpH5dNyV+Xz/ViwxkWrjBSw+uQ7oE+vyR01reOMXDFyPcxC71V+VPtPonkP 21 | DTyKo+vnwuEDqv2AeXhG01dmwxerId7fcT4/+ypkzOlS16sSXO0kiXzX+WtQel2l 22 | uB23kEVRsDw= 23 | -----END CERTIFICATE----- 24 | -------------------------------------------------------------------------------- /library/cxl_tsp_device_lib_sample/cxl_tsp_device_lock_configuration.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2024 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_tsp_device_lib.h" 12 | 13 | /** 14 | * Process the TSP request and return the response. 15 | * 16 | * @param request the TSP request message, start from cxl_tsp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TSP response message, start from cxl_tsp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libcxltsp_error_code_t cxl_tsp_device_lock_configuration ( 25 | const void *pci_doe_context, 26 | const void *spdm_context, const uint32_t *session_id) 27 | { 28 | libcxltsp_device_context *device_context; 29 | 30 | device_context = libcxltsp_get_device_context (pci_doe_context); 31 | if (device_context == NULL) { 32 | return CXL_TSP_ERROR_CODE_UNSPECIFIED; 33 | } 34 | 35 | // TBD: need to set hardware state 36 | device_context->current_tsp_state = CXL_TSP_STATE_CONFIG_LOCKED; 37 | 38 | return CXL_TSP_ERROR_CODE_SUCCESS; 39 | } 40 | -------------------------------------------------------------------------------- /library/pci_ide_km_device_lib_sample/pci_ide_km_device_context.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_ide_km_device_lib.h" 12 | 13 | libidekm_device_port_context g_idekm_device_port_context; 14 | 15 | libidekm_device_port_context *libidekm_initialize_device_port_context ( 16 | uint8_t port_index 17 | ) 18 | { 19 | libspdm_zero_mem ( 20 | &g_idekm_device_port_context, 21 | sizeof(g_idekm_device_port_context) 22 | ); 23 | g_idekm_device_port_context.port_index = port_index; 24 | g_idekm_device_port_context.dev_func_num = 0; 25 | g_idekm_device_port_context.bus_num = 0; 26 | g_idekm_device_port_context.segment = 0; 27 | g_idekm_device_port_context.max_port_index = 7; 28 | 29 | g_idekm_device_port_context.ide_reg_buffer_count = PCI_IDE_KM_IDE_REG_BLOCK_SUPPORTED_COUNT; 30 | 31 | /* TBD: init the ide_reg_block */ 32 | 33 | return &g_idekm_device_port_context; 34 | } 35 | 36 | libidekm_device_port_context *libidekm_get_device_port_context ( 37 | uint8_t port_index 38 | ) 39 | { 40 | if (g_idekm_device_port_context.port_index == port_index) { 41 | return &g_idekm_device_port_context; 42 | } else { 43 | return NULL; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /library/cxl_tsp_device_lib_sample/cxl_tsp_device_set_te_state.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2024 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_tsp_device_lib.h" 12 | 13 | /** 14 | * Process the TSP request and return the response. 15 | * 16 | * @param request the TSP request message, start from cxl_tsp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TSP response message, start from cxl_tsp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libcxltsp_error_code_t cxl_tsp_device_set_te_state ( 25 | const void *pci_doe_context, 26 | const void *spdm_context, const uint32_t *session_id, 27 | uint8_t te_state, 28 | uint8_t number_of_memory_ranges, 29 | const cxl_tsp_memory_range_t *memory_ranges) 30 | { 31 | libcxltsp_device_context *device_context; 32 | 33 | device_context = libcxltsp_get_device_context (pci_doe_context); 34 | if (device_context == NULL) { 35 | return CXL_TSP_ERROR_CODE_UNSPECIFIED; 36 | } 37 | 38 | // TBD: need to set hardware state 39 | 40 | return CXL_TSP_ERROR_CODE_SUCCESS; 41 | } 42 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_ide_km_device_lib/pci_ide_km_device_context.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_ide_km_device_lib.h" 12 | 13 | libidekm_device_port_context g_idekm_device_port_context; 14 | 15 | libidekm_device_port_context *libidekm_initialize_device_port_context ( 16 | uint8_t port_index 17 | ) 18 | { 19 | libspdm_zero_mem ( 20 | &g_idekm_device_port_context, 21 | sizeof(g_idekm_device_port_context) 22 | ); 23 | g_idekm_device_port_context.port_index = port_index; 24 | g_idekm_device_port_context.dev_func_num = 0; 25 | g_idekm_device_port_context.bus_num = 0; 26 | g_idekm_device_port_context.segment = 0; 27 | g_idekm_device_port_context.max_port_index = 7; 28 | 29 | g_idekm_device_port_context.ide_reg_buffer_count = PCI_IDE_KM_IDE_REG_BLOCK_SUPPORTED_COUNT; 30 | 31 | /* TBD: init the ide_reg_block */ 32 | 33 | return &g_idekm_device_port_context; 34 | } 35 | 36 | libidekm_device_port_context *libidekm_get_device_port_context ( 37 | uint8_t port_index 38 | ) 39 | { 40 | if (g_idekm_device_port_context.port_index == port_index) { 41 | return &g_idekm_device_port_context; 42 | } else { 43 | return NULL; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /spdm_emu/spdm_responder_emu/spdm_responder_pci_doe.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "spdm_responder_emu.h" 8 | 9 | void *m_pci_doe_context; 10 | 11 | libspdm_return_t pci_doe_init_responder() 12 | { 13 | libspdm_return_t status; 14 | status = pci_doe_register_vendor_response_func ( 15 | m_pci_doe_context, 16 | SPDM_REGISTRY_ID_PCISIG, SPDM_VENDOR_ID_PCISIG, 17 | PCI_PROTOCOL_ID_IDE_KM, pci_ide_km_get_response); 18 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 19 | return status; 20 | } 21 | status = pci_doe_register_vendor_response_func ( 22 | m_pci_doe_context, 23 | SPDM_REGISTRY_ID_PCISIG, SPDM_VENDOR_ID_PCISIG, 24 | PCI_PROTOCOL_ID_TDISP, pci_tdisp_get_response); 25 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 26 | return status; 27 | } 28 | status = pci_doe_register_vendor_response_func ( 29 | m_pci_doe_context, 30 | SPDM_REGISTRY_ID_PCISIG, SPDM_VENDOR_ID_CXL, 31 | CXL_PROTOCOL_ID_IDE_KM, cxl_ide_km_get_response); 32 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 33 | return status; 34 | } 35 | status = pci_doe_register_vendor_response_func ( 36 | m_pci_doe_context, 37 | SPDM_REGISTRY_ID_PCISIG, SPDM_VENDOR_ID_CXL, 38 | CXL_PROTOCOL_ID_TSP, cxl_tsp_get_response); 39 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 40 | return status; 41 | } 42 | return LIBSPDM_STATUS_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/cryptstublib/timeclock.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/debuglib.h" 9 | 10 | #if defined(__GNUC__) && !defined(_WIN32) 11 | typedef size_t time_t; 12 | #elif defined(__clang__) 13 | typedef size_t time_t; 14 | #endif 15 | 16 | /* Structures Definitions*/ 17 | 18 | struct tm { 19 | int tm_sec; /* seconds after the minute [0-60] */ 20 | int tm_min; /* minutes after the hour [0-59] */ 21 | int tm_hour; /* hours since midnight [0-23] */ 22 | int tm_mday; /* day of the month [1-31] */ 23 | int tm_mon; /* months since January [0-11] */ 24 | int tm_year; /* years since 1900 */ 25 | int tm_wday; /* days since Sunday [0-6] */ 26 | int tm_yday; /* days since January 1 [0-365] */ 27 | int tm_isdst; /* Daylight Savings Time flag */ 28 | long tm_gmtoff; /* offset from CUT in seconds */ 29 | char *tm_zone; /* timezone abbreviation */ 30 | }; 31 | 32 | 33 | /* -- Time Management Routines --*/ 34 | 35 | 36 | time_t time(time_t *timer) 37 | { 38 | LIBSPDM_ASSERT(false); 39 | return 0; 40 | } 41 | 42 | struct tm *gmtime(const time_t *timer) 43 | { 44 | LIBSPDM_ASSERT(false); 45 | return NULL; 46 | } 47 | 48 | time_t _time64(time_t *t) 49 | { 50 | LIBSPDM_ASSERT(false); 51 | return 0; 52 | } 53 | 54 | struct tm *gmtime_r(const time_t *timep, struct tm *result) 55 | { 56 | LIBSPDM_ASSERT(false); 57 | return NULL; 58 | } 59 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/spdm_device_responder/pci.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "spdm_responder.h" 8 | 9 | uint32_t pci_cfg_read_32 (uint8_t bus, uint8_t device, uint8_t function, uint32_t offset) 10 | { 11 | size_t address; 12 | address = SPDM_DEVICE_PCIE_ADDRESS + PCI_ECAM_ADDRESS(bus, device, function, offset); 13 | return *(uint32_t *)address; 14 | } 15 | 16 | void pci_cfg_write_32 (uint8_t bus, uint8_t device, uint8_t function, uint32_t offset, 17 | uint32_t value) 18 | { 19 | size_t address; 20 | address = SPDM_DEVICE_PCIE_ADDRESS + PCI_ECAM_ADDRESS(bus, device, function, offset); 21 | *(uint32_t *)address = value; 22 | } 23 | 24 | uint32_t spdm_dev_pci_cfg_read_32 (uint32_t offset) 25 | { 26 | return pci_cfg_read_32 (SPDM_DEVICE_PCI_BUS, SPDM_DEVICE_PCI_DEVICE, SPDM_DEVICE_PCI_FUNCTION, 27 | offset); 28 | } 29 | 30 | void spdm_dev_pci_cfg_write_32 (uint32_t offset, uint32_t value) 31 | { 32 | pci_cfg_write_32 (SPDM_DEVICE_PCI_BUS, SPDM_DEVICE_PCI_DEVICE, SPDM_DEVICE_PCI_FUNCTION, offset, 33 | value); 34 | } 35 | 36 | uint32_t spdm_dev_pci_cfg_doe_read_32 (uint32_t doe_offset) 37 | { 38 | return spdm_dev_pci_cfg_read_32 (SPDM_DEVICE_DOE_OFFSET + doe_offset); 39 | } 40 | 41 | void spdm_dev_pci_cfg_doe_write_32 (uint32_t doe_offset, uint32_t value) 42 | { 43 | spdm_dev_pci_cfg_write_32 (SPDM_DEVICE_DOE_OFFSET + doe_offset, value); 44 | } 45 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2021-2025, Contributing Member(s) of Distributed Management Task Force, 4 | Inc.. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, 7 | are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its contributors 17 | may be used to endorse or promote products derived from this software without 18 | specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /spdm_emu/spdm_responder_emu/spdm_responder_tcp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2023 - 2005 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "spdm_responder_emu.h" 8 | 9 | bool InitConnectionAndRoleInquiry(SOCKET *sock, uint16_t port_number) { 10 | bool result; 11 | uint8_t role_inquiry_buf[sizeof(spdm_tcp_binding_header_t)]; 12 | size_t role_inquiry_size = sizeof(role_inquiry_buf); 13 | SOCKET responder_socket; 14 | 15 | result = init_client(&responder_socket, port_number); 16 | if (!result) { 17 | #ifdef _MSC_VER 18 | WSACleanup(); 19 | #endif 20 | return false; 21 | } 22 | 23 | void *message_ptr = &role_inquiry_buf; 24 | libspdm_return_t status = libspdm_tcp_encode_discovery_message( 25 | SPDM_TCP_MESSAGE_TYPE_ROLE_INQUIRY, 26 | &role_inquiry_size, 27 | &message_ptr 28 | ); 29 | 30 | if (status != LIBSPDM_STATUS_SUCCESS) { 31 | closesocket(responder_socket); 32 | printf("Failed to encode Role-Inquiry message. Status: 0x%x\n", status); 33 | return false; 34 | } 35 | 36 | /* Send role_inquiry request */ 37 | printf("Press ENTER to send Role-Inquiry request...\n"); 38 | getchar(); 39 | result = write_bytes(responder_socket, role_inquiry_buf, (uint32_t)role_inquiry_size); 40 | if (!result) { 41 | closesocket(responder_socket); 42 | printf("Error sending Role-Inquiry request.\n"); 43 | #ifdef _MSC_VER 44 | WSACleanup(); 45 | #endif 46 | return false; 47 | } 48 | 49 | *sock = responder_socket; 50 | return true; 51 | } 52 | -------------------------------------------------------------------------------- /spdm_emu/spdm_requester_emu/spdm_requester_endpoint_info.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2025 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "spdm_requester_emu.h" 8 | 9 | #if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP 10 | 11 | extern void *m_spdm_context; 12 | 13 | /** 14 | * This function executes SPDM endpoint info. 15 | * 16 | * @param[in] spdm_context The SPDM context for the device. 17 | **/ 18 | libspdm_return_t do_get_endpoint_info_via_spdm(const uint32_t *session_id) 19 | { 20 | libspdm_return_t status; 21 | void *spdm_context; 22 | uint8_t sub_code; 23 | uint8_t request_attributes; 24 | uint32_t ep_info_length; 25 | uint8_t ep_info_record[LIBSPDM_MAX_ENDPOINT_INFO_LENGTH]; 26 | 27 | spdm_context = m_spdm_context; 28 | 29 | sub_code = SPDM_GET_ENDPOINT_INFO_REQUEST_SUBCODE_DEVICE_CLASS_IDENTIFIER; 30 | request_attributes = 31 | SPDM_GET_ENDPOINT_INFO_REQUEST_ATTRIBUTE_SIGNATURE_REQUESTED; 32 | ep_info_length = LIBSPDM_MAX_ENDPOINT_INFO_LENGTH; 33 | 34 | status = libspdm_get_endpoint_info(spdm_context, session_id, request_attributes, 35 | sub_code, m_use_slot_id & SPDM_GET_ENDPOINT_INFO_REQUEST_SLOT_ID_MASK, 36 | &ep_info_length, ep_info_record, 37 | NULL, NULL, NULL); 38 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 39 | return status; 40 | } 41 | return LIBSPDM_STATUS_SUCCESS; 42 | } 43 | 44 | #endif /*LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP*/ -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/spdm_device_secret_lib/bin/ecp384_raw_key.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | /*ecp384 key for responder: https://lapo.it/asn1js/#MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDA0-Tw5nC64l4QCjOWcy-HO6RXQ1KwbLt4cgtNmLhrK3K7dez84YVgB4Q3tfzUDpKKhZANiAASM-ISdEQdJyhzQtRG84084PPDFjXNap2N-X2JgfxBDNMhPLLxwj02i_U4DiRZJykBqkRgJfyfv5KYmGv3U0VfbWxt1BfkVnTM0vpC3XtcFuXOFHkrTAFt9EGi_T8rmOEw */ 8 | 9 | /* https://github.com/DMTF/libspdm/blob/main/unit_test/sample_key/ecp384/end_responder.key */ 10 | uint8_t m_libspdm_ec384_responder_public_key[] = { 11 | 0x8C, 0xF8, 0x84, 0x9D, 0x11, 0x07, 0x49, 0xCA, 0x1C, 0xD0, 0xB5, 0x11, 0xBC, 0xE3, 0x4F, 0x38, 12 | 0x3C, 0xF0, 0xC5, 0x8D, 0x73, 0x5A, 0xA7, 0x63, 0x7E, 0x5F, 0x62, 0x60, 0x7F, 0x10, 0x43, 0x34, 13 | 0xC8, 0x4F, 0x2C, 0xBC, 0x70, 0x8F, 0x4D, 0xA2, 0xFD, 0x4E, 0x03, 0x89, 0x16, 0x49, 0xCA, 0x40, 14 | 0x6A, 0x91, 0x18, 0x09, 0x7F, 0x27, 0xEF, 0xE4, 0xA6, 0x26, 0x1A, 0xFD, 0xD4, 0xD1, 0x57, 0xDB, 15 | 0x5B, 0x1B, 0x75, 0x05, 0xF9, 0x15, 0x9D, 0x33, 0x34, 0xBE, 0x90, 0xB7, 0x5E, 0xD7, 0x05, 0xB9, 16 | 0x73, 0x85, 0x1E, 0x4A, 0xD3, 0x00, 0x5B, 0x7D, 0x10, 0x68, 0xBF, 0x4F, 0xCA, 0xE6, 0x38, 0x4C, 17 | }; 18 | uint8_t m_libspdm_ec384_responder_private_key[] = { 19 | 0x34, 0xF9, 0x3C, 0x39, 0x9C, 0x2E, 0xB8, 0x97, 0x84, 0x02, 0x8C, 0xE5, 0x9C, 0xCB, 0xE1, 0xCE, 20 | 0xE9, 0x15, 0xD0, 0xD4, 0xAC, 0x1B, 0x2E, 0xDE, 0x1C, 0x82, 0xD3, 0x66, 0x2E, 0x1A, 0xCA, 0xDC, 21 | 0xAE, 0xDD, 0x7B, 0x3F, 0x38, 0x61, 0x58, 0x01, 0xE1, 0x0D, 0xED, 0x7F, 0x35, 0x03, 0xA4, 0xA2, 22 | }; 23 | -------------------------------------------------------------------------------- /library/cxl_tsp_device_lib_sample/cxl_tsp_device_get_capabilities.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2024 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_tsp_device_lib.h" 12 | 13 | /** 14 | * Process the TSP request and return the response. 15 | * 16 | * @param request the TSP request message, start from cxl_tsp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TSP response message, start from cxl_tsp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libcxltsp_error_code_t cxl_tsp_device_get_capabilities ( 25 | const void *pci_doe_context, 26 | const void *spdm_context, const uint32_t *session_id, 27 | libcxltsp_device_capabilities_t *device_capabilities) 28 | { 29 | libcxltsp_device_context *device_context; 30 | 31 | device_context = libcxltsp_get_device_context (pci_doe_context); 32 | if (device_context == NULL) { 33 | return CXL_TSP_ERROR_CODE_UNSPECIFIED; 34 | } 35 | libspdm_copy_mem (device_capabilities, 36 | sizeof(libcxltsp_device_capabilities_t), 37 | &device_context->device_capabilities, 38 | sizeof(libcxltsp_device_capabilities_t)); 39 | 40 | return CXL_TSP_ERROR_CODE_SUCCESS; 41 | } 42 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/SampleTestKey/SampleCertChain/TestSub.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEAuJjcOxnI6bc+yjgAbebgL74zUFrIgwaCTcLMzjkITLZfR/G4 3 | Ub3/PG1xkHu2eFMr8yib7qWtXl2AQRe8uDGyH11/HQeY63/dSldUq9YBXMo9u7J9 4 | UIILIa2rWN5tiwyJ1vv2RnakM3rCrRtPv2Xy9qVphT9h/h7KOZdpWQV7cNeAzd5h 5 | 4+vnKm30Isu19FGVrhpHZ3qdYFysmChtI4BCKE2k+iD6dqNXXEDhMXg0ytQuKilx 6 | hKPRemjMKsRXQ3kDi2nKslpya/uJEEfJy2tjwweKknaPmGCW/Qw8KrCm6blcKCAA 7 | 1SrbIyMpPL6LPlfI/3BQxq8rc+358hM6BALo2wIDAQABAoIBAC3cfEqKm2nFRupC 8 | g4jKZUQ3QtRh2ZMD2Pesv+k0LiWw4XckTKCyTWkb36z/r1OxhifBHQxrSOk63ZRO 9 | a2pvnktAlUYHDyzi9X10uOqAHpKJBFFPhOatiEpztTA9AoYbNVud+Y+EBkNr6lXL 10 | hUKN95Djg5XBK31Q9Pjd7yRYwlREKb14lMpLPmxkPEnmbYXK3VTlEGSTCijJkzxN 11 | pGdbMifgoayLergbnxMjfIAY9OjYfJOCoboqEGFqSMhpQxNAnbnObb6sHfwqh1eV 12 | 2MNu1wlKLdxWy/uqNZplYt57xUQA4sNSXjwOl6GadDJNrli8jwtqosHyMb7PdG8G 13 | zorO1jECgYEA6pgjPSwcCra/nBasJu8alOR/uprZ4r9f/ym1al5dLLL3zppY3nce 14 | jB1wXIP5Rh+NH8ALu9lDrFRU7LTHLRBJzHEIojj/eUtwlAYn38m3WIgHr3ZmKjqY 15 | at0yBFwvgpCFl0sj+YffYCaqPsaL2bwYsYd/rl6bPMpxdjeg7ycNyQUCgYEAyXDY 16 | EcYehvThnwy9rVSkChFbUuHEsQJY6FTOofbb7gIrJB78OgD9x1WKfoVZHmAZqF9/ 17 | 9U2biaBMAB9CwyzufAaI6aDKYAtvQt20XTQuE9g1jBQI+D4Ex6VK7mIBqi9ojeyY 18 | YkSSRQ28FlEP/50OMmr9Rdo+Ew96QymegxAREF8CgYEAhJ+BvIGFUOFDrcB7jn86 19 | LdaIBzyn1TKP2LcBoqK6VhzPT3OerhX1pQy3ivXpJKWNqNdvSsFnKrN6V19UArvk 20 | nLmCQgOrGi119ZkNTczB5EDy51UuKM17gV6PejuLeGqvu3p1WgpgVAFH2blxMqTN 21 | 6P9LRY6igFmKj2SfjNQtTOkCgYALEYE90MYColf3VkrhyEHPL871yeP12ewqr+Y+ 22 | rgK9nC7kqDMxuLY5CrE2bHtOGPev8bdlMiN2t3EVnKIdeU2NUQqa07Pq/RXa9bWg 23 | XWqeuoWOsdcgVMAMfD+Ww5nV0Q8MpVBmLeBfnPaVv1SCtg1+pbRO70Pz5ijQoevM 24 | xcg6PwKBgGjpJNfpmoMKltwlDcLc6d8rU/mf2e07K8y5Jc3vrmh/Fl8faWOXLkAf 25 | Vvq6Kdaja+r6v1xk3nCvdjie4aufsBb7EJyAHqMKOzNRbXPjHbT0e6AOzdhkBkCK 26 | kF1LB3pK1Amhtd1SjZwRlIKYQD4yuMlM03nKIKcuTQyYJqyc9SGP 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/SampleTestKey/SampleCertChain/TestCert.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEAtJtQVSsu1kbLKoB7P7ec41fq6LaerlKYYuaIVyuUEx/emYXa 3 | yIUAMe59rkvtPsSQBuTKLNLTD3ExSTlyc4uGCcRRh4y0gtZfUktu24hVa/McZJ8M 4 | tOc2kVHwA0SSaRUdmH2Ah9Wsm2OTurM6SB1pMdaUrdW5orl9MP1mB6Q4pF4T/rMm 5 | WMMJeQ5pjuEUGXHh3p+k15Xbv3nDIEzxmtfz65vYNaOrGUVKRuD3r7UDYz33p07y 6 | dGYEfIKpz1P5SZLh4iJ0BDjyXuslEcptmBCpKSfoLtEWkJHJm01hIY9xT8QEjGE6 7 | Zy2Im/8dkDDhLBxFxX/MHSEdVOgsgWnnkWERhQIDAQABAoIBAGio4GKahafSmoVk 8 | swd3hckQ96YnvcjTQE9/vF6XeFWk0EAzG1e8CyLkS5ynjzIigjwcdTSIb5qxQ5hl 9 | W/etUN10ELL2TNzNEawE3pcFaEsINNnyeVCT9EE+NFIQeK/AdsgZYlRU9JOPntpA 10 | ZnPH51/kM4CRK+QqjWvITEn9Vn2YtDwX1Txwird2kjVZYEARj+xuO2+53neDKGRD 11 | /MHmOj4sFDR9FW8YM2dmbMunuZQJptUSfwHWGkijsMTb+YPS/ngBOLCl//2fMVq9 12 | bEDt015hKU8b/CKDDVSGHc5TmZJ7/u62eUf8IrUBFxbBb5W7mH0LPXM/hdoAD0DW 13 | jTofbfkCgYEA8LqgicfO1OoyPQqgvbRIAF/tFmtvuWbJCNP6fxWDjhgq2QwtwtqW 14 | sTemf7sbh8NZhgrDue/L16TUAu0zZ8uxQyOSclyxu4pOWnVP6HNTHA/7txbP/4MF 15 | rWLNssUnJRFEUn9Kxv8HVKgT5uagx4IXz6MNCB4FfnGC46vrUXIRAocCgYEAwBBR 16 | GlHZPApNJqcXHSEqCuxvjeIrrHtheH+2AFHkIu2X42ZVlEEES93+wftWNydYmC1a 17 | YHYdmvs0xQ0Z5+xDq0MPiWMNEUz0KIz7rfaNZK3v8fHUVit+w76aVO9tU71BMwKh 18 | S/T3oho1JTflnG08I3Y165oSMI8Ys4HGlzI/8pMCgYEAmxxlnOG2D9LnlBVpBVNI 19 | oZUtuyh20Mu99YZA/enq3oAL+9axFcCrIH1vNxZk4tGouYnuG7y7Z7O5ODmGyfah 20 | vVUKY83+Z4zyd67nUiwc/RP/aTW1yDmwSsxDJlGKq4O4tj92+0oQeyfhywIHzwWw 21 | OgYhu308pQCXCgQYmF4bP7kCgYA/3S0as1youkQtNiJZbU2tlDED3NDo6Z3fk5fR 22 | Q2m4s4ht9Pk/8t6a25Z6qjhg3pR3BZ2ntZ7iieViIJkcpVNa/1GLPYR63DvTwA1w 23 | KyuY7r16lg8lGBFuxVJMK9EOpz+m1pkLyMkO/efuGEghW7FDmWsUjIa/3tU3209N 24 | t0fMQQKBgQCE6sU43wcRBxP9E0ThLLFqINRoQgK+wHsZZbJLataDeyvRKeJFzmVu 25 | XA/bhq9SDraTUPlI3ILXtSe9oqdcw5oz98ASJ91S0+Zig8TLyA1GlWfNBAEvyN8R 26 | udgP2fzoUuwlPjB6tqEU/XiZJZnS4v2qk+weNf2PPPbWIuQu8Nk7XQ== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/SampleTestKey/SampleCertChain/TestRoot.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEA6cBLiNxmsGReFiw5rInfRwkCJGYF+LrdoyCY2bX76p2aqI8i 3 | gFeRbGCNIdmab5tpBwZdfA+4deIAPthaA8BlnRbXNzOB6MZiCwYsDXCwUJgDfsGD 4 | NSKMQeOHTvkn64KbikYyPaQqfCj9zxyWdVX+FZCFZtYkZj4v1109+fmY8pW7Enp3 5 | sYdChhQNERaslPkrpv5HUskIS9kAKiWZzDoLlQmNj+qwHAevExujB2XmKdCPfpSZ 6 | JFTvaYrIjO89j3ZyWbJ5kayIJ9BeMB+72SfCKcxBpVGBR7oINEewC7H3l10E/82T 7 | NSB28W+XNG803eBlSxzFkcxSz+XlyLCbB7hIhQIDAQABAoIBADg7kHBORU3t90xy 8 | OzWsvVADdMZ43LrniWYy81J8myvn2krulCg36L4fxBP+m056HpwYBelQhtmlEtYL 9 | iiwY3tkZo5CeDYSIJRHt3C8niuL4ju6xcvUXaJJ5QBXZjqbzdqOfG3sEwUu5OMXY 10 | ZMG5fDSH3e/NWFhYYX336m72grrooJ4FHepXFbzfMMnp7aMbF8NfM0GdqO0sDA3s 11 | x/okJKjZo4VIvRNRXe3ibewdUFvE3jeffAIM4VEbyKkAUSAabKlkyDc4oanbsSgv 12 | Zn9WHqrkan8OhYapUyHP/yQutF+cQHqecNGu8q2VAmzhBzAZoZtSDul3Ee0fop6i 13 | XXFQFkECgYEA/hcL3XM0VK5nQAwV6uGq5Nt4wAn+MlP4yzteMJunD19ztzhtFLIF 14 | t1dljkWTp33GchWojGa/VQm/vW0O82EMq+5YECLbwCE1CNwF4cEYIBitpqqjAbGt 15 | 5yb8AFSsyxZ/pKXXLdFO2gz0BvBWfGIfcz1ZKhAMfn60clHhdUN2M6kCgYEA64Ic 16 | JlEUBhoaignML98BVEwKsrCqMI9SudpnUbIEcI0JFbfGUAnwinebAAd+D+P5U1e/ 17 | ZxfqTtZwT+0aF9abtYkLV3ljfSFxCNHNbWNs5quFNCO+9CbngC9gQpBQBQI8GrYD 18 | lwrGulazvr1NS+a+zpNfF/203NrckNErw8uB930CgYB3go2BHlOp1NIZjNWuQXBo 19 | 7lWwNcMLFvX5WTYnNL7x+xppPjAIQOdxYbkRnuYhLIZvWIKLbzRlIg2+YhJbJPWZ 20 | 1KQ1CsBDcRsJzLszgOgBCLp8ntvGyzSZeXukCC+x4iYtYheApGcrJlaNAPQc0uYq 21 | BNvwbdYClUP4VUzvI8jv6QKBgQDfa26DFzXU2BzHSaYw3/Hl48HeZWT/bmh/smeE 22 | BErb76BnvxFeyx8sbW1ZaMI6Fv9oBn2pMvHw2tRvrrKrXMgZPyrIUHuGsRwHzumA 23 | 1erxJlTW8vZrryC95bP/UeLn7YfRm0zqlKmVCz24PORAlmX7mamEHAbh4quOozFO 24 | rRjeDQKBgQChdk/UHAHLo34OlDiMuk17Z7Z43fjL5HDncCv4TExn5B+JgcGEoaZV 25 | 38+d33wa7u7slMVzfLTFe2GgxZHyQd6it7pxVUrAQ1lzFbB+de16KENQvZV3pfkK 26 | OOgZZ3aRGTr7kI7pntLSVhy1L2oNj/V4XzCm38bBb9hMgLNTlYL+7A== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /library/pci_tdisp_device_lib_sample/pci_tdisp_device_interface_state.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | /** 14 | * Process the TDISP request and return the response. 15 | * 16 | * @param request the TDISP request message, start from pci_tdisp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TDISP response message, start from pci_tdisp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libtdisp_error_code_t pci_tdisp_device_get_interface_state (const void *pci_doe_context, 25 | const void *spdm_context, 26 | const uint32_t *session_id, 27 | const pci_tdisp_interface_id_t *interface_id, 28 | uint8_t *tdi_state) 29 | { 30 | libtdisp_interface_context *interface_context; 31 | 32 | interface_context = libtdisp_get_interface_context (interface_id); 33 | if (interface_context == NULL) { 34 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE; 35 | } 36 | *tdi_state = interface_context->tdi_state; 37 | 38 | return PCI_TDISP_ERROR_CODE_SUCCESS; 39 | } 40 | -------------------------------------------------------------------------------- /library/cxl_ide_km_device_lib_sample/cxl_ide_km_device_key_set_go.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_ide_km_device_lib.h" 12 | 13 | /** 14 | * Process the IDE_KM request and return the response. 15 | * 16 | * @param request the IDE_KM request message, start from cxl_ide_km_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the IDE_KM response message, start from cxl_ide_km_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libspdm_return_t cxl_ide_km_device_key_set_go (const void *pci_doe_context, 25 | const void *spdm_context, const uint32_t *session_id, 26 | uint8_t stream_id, uint8_t key_sub_stream, 27 | uint8_t port_index) 28 | { 29 | libcxlidekm_device_port_context *device_port_context; 30 | uint8_t index; 31 | 32 | device_port_context = libcxlidekm_get_device_port_context (port_index); 33 | if (device_port_context == NULL) { 34 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 35 | } 36 | 37 | index = (key_sub_stream & CXL_IDE_KM_KEY_DIRECTION_MASK) >> 1; 38 | 39 | /* key set go */ 40 | 41 | device_port_context->is_key_set_go[index] = true; 42 | 43 | return LIBSPDM_STATUS_SUCCESS; 44 | } 45 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_tdisp_device_lib/pci_tdisp_device_interface_state.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | /** 14 | * Process the TDISP request and return the response. 15 | * 16 | * @param request the TDISP request message, start from pci_tdisp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TDISP response message, start from pci_tdisp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libtdisp_error_code_t pci_tdisp_device_get_interface_state (const void *pci_doe_context, 25 | const void *spdm_context, 26 | const uint32_t *session_id, 27 | const pci_tdisp_interface_id_t *interface_id, 28 | uint8_t *tdi_state) 29 | { 30 | libtdisp_interface_context *interface_context; 31 | 32 | interface_context = libtdisp_get_interface_context (interface_id); 33 | if (interface_context == NULL) { 34 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE; 35 | } 36 | *tdi_state = interface_context->tdi_state; 37 | 38 | return PCI_TDISP_ERROR_CODE_SUCCESS; 39 | } 40 | -------------------------------------------------------------------------------- /library/pci_ide_km_device_lib_sample/pci_ide_km_device_key_set_go.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_ide_km_device_lib.h" 12 | 13 | /** 14 | * Process the IDE_KM request and return the response. 15 | * 16 | * @param request the IDE_KM request message, start from pci_ide_km_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the IDE_KM response message, start from pci_ide_km_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libspdm_return_t pci_ide_km_device_key_set_go (const void *pci_doe_context, 25 | const void *spdm_context, const uint32_t *session_id, 26 | uint8_t stream_id, uint8_t key_sub_stream, 27 | uint8_t port_index) 28 | { 29 | libidekm_device_port_context *device_port_context; 30 | uint8_t index; 31 | 32 | device_port_context = libidekm_get_device_port_context (port_index); 33 | if (device_port_context == NULL) { 34 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 35 | } 36 | 37 | index = key_sub_stream & (PCI_IDE_KM_KEY_SET_MASK | PCI_IDE_KM_KEY_DIRECTION_MASK); 38 | 39 | /* key set go */ 40 | 41 | device_port_context->is_key_set_go[index] = true; 42 | 43 | return LIBSPDM_STATUS_SUCCESS; 44 | } 45 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/spdm_device_secret_lib/spdm_device_secret_lib_internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | /** @file 8 | * SPDM common library. 9 | * It follows the SPDM Specification. 10 | **/ 11 | 12 | #ifndef __SPDM_DEVICE_SECRET_LIB_INTERNAL_H__ 13 | #define __SPDM_DEVICE_SECRET_LIB_INTERNAL_H__ 14 | 15 | #include "hal/library/cryptlib.h" 16 | #include "library/spdm_crypt_lib.h" 17 | #include "spdm_crypt_ext_lib/spdm_crypt_ext_lib.h" 18 | #include "spdm_crypt_ext_lib/cryptlib_ext.h" 19 | #include "hal/library/responder/asymsignlib.h" 20 | #include "hal/library/responder/csrlib.h" 21 | #include "hal/library/responder/measlib.h" 22 | #include "hal/library/responder/psklib.h" 23 | #include "hal/library/responder/setcertlib.h" 24 | #include "hal/library/debuglib.h" 25 | 26 | #define LIBSPDM_MEASUREMENT_BLOCK_HASH_NUMBER 4 27 | #define LIBSPDM_MEASUREMENT_BLOCK_NUMBER (LIBSPDM_MEASUREMENT_BLOCK_HASH_NUMBER /*Index - 1~4*/ + \ 28 | 1 /*SVN - 0x10*/ + \ 29 | 1 /*Manifest - 0xFD*/ + 1 /*DEVICE_MODE - 0xFE*/) 30 | #define LIBSPDM_MEASUREMENT_RAW_DATA_SIZE 72 31 | #define LIBSPDM_MEASUREMENT_MANIFEST_SIZE 128 32 | #define LIBSPDM_MEASUREMENT_INDEX_SVN 0x10 33 | 34 | /* public cert*/ 35 | 36 | bool libspdm_read_responder_public_certificate_chain( 37 | uint32_t base_hash_algo, uint32_t base_asym_algo, void **data, 38 | size_t *size, void **hash, size_t *hash_size); 39 | 40 | bool libspdm_get_responder_private_key_from_raw_data(uint32_t base_asym_algo, void **context); 41 | 42 | /* External*/ 43 | 44 | void libspdm_dump_hex_str(const uint8_t *buffer, size_t buffer_size); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/SampleTestKey/example.key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQDio8/jCx687P5R 3 | rkfOS/o4uJGVypSCgv7SmHWpCh1J7ATtx8T0GanFMOKKvaY1K7Qftobm5DfMQRgC 4 | VxeywprHd25tg9VzW7bBn6DTaQ8+tbyNjFnNHB//04Anw+K2+JwwQmAu2Rfh+yl3 5 | JAKZcLES/0S3chL3lYT2IdC1W68yvZWTqegQXg4xyqyMpJj5jaXa5SbHLMEPzHD+ 6 | NIzzhkyBSPugDwe95tnbKTrOVupMdURN7xgJiMqBc5SkuG02yzk1cuPiE4JMRyOE 7 | 7tG1SCWbSjGVn92HPvRw6FwQuMqbSKL3LTZWNF3Pf0Mbp4JezIj2cqAhErXqWP0D 8 | LV8rMhSlAgMBAAECggEBAJGZublb8IBhJLVm6Jyg9Pyxnl4ECkqaS4kSByz04YIX 9 | DceQungzcHzNfgyx7/BixlJFWf9FiI9BFmKSfxgJq5QPpzLWKi/1MMDNg22uJewc 10 | pyisjRiXQ/t/beqeDq2LpBPg4JfYQl6ck7QFv2HCIxBYTFYqBANo3EWfzcxlPXWz 11 | XrrXzF2y1Ps6/iKLAkOzOpFNrX1dCWxmk20yD7mofHVMfY895DFDoJwHZf1CBN9l 12 | 6p9knwlagAs0DopLROe3L0THpMwhDdSOKXK31rBl3ShBe5o/viFXXf/wDHuWGfmP 13 | 7LlaiuZNLE9TrCxOlEmfo8R+AEJX67qcIkXmTxD9e2ECgYEA9AIvE3uhN39/oyu5 14 | nXSbBsl0/obV1MRdb+Xakz8KMFeFzw0XhCdYQ1qGTTzCltx80qL4jJn1VB1330SD 15 | gz8MUnVjzG/pLz++VWJshB3hBcJvHx/QEiW72NJNb6smZGtWaqGWKKji5auU8EL5 16 | ZF8ltEYwvuCsQllxirvyXhkIv/kCgYEA7cceA0+2a3ajoX/AF9Gl53zW6n/QoM4D 17 | xEAstTY7SwNrkETNL6wuAj3sTJgXZIVD27HWo3pEn14glMbsPZvb+LSljtQXA3dH 18 | 2Vwcvay6sGTbgsDYzyytWhfSgEpwGktxKES3LJvM5W5eeRqcUpFiqXHFb3M37i9M 19 | JLYYevSSPQ0CgYEAuka8h4QW5BZKa1ejAMgW3UyIKxLmROKPbjAr98LlVVhLh3A4 20 | JqQepnSCGI6tApxaEjdlxXh3J/rDG0fjmhtUndKOGHDKtE5WUDquGwHwWgQ/7qPL 21 | pT73M6QAh6JB0eF7fDXVOz8K0Eh3kB+g4fYdA42eAunjt1cu7bljYmB8JIkCgYEA 22 | y2xCXQrhQebp7szghoAxs222YEChODGIP2m31gBjkbWHXJHACT0Az6IyewTTXog0 23 | mcv3mTyNYNqifSYCDmM9OfUyfpMsbSarLWYEoLEZtrdSpPZfhj7uv9kJmgAVECni 24 | 0VSYcW2JSe+2m10MyAbhpZ1UEBk+jGOifPXc07RRODECgYEAqiTcjL81B/tj6/8Z 25 | G0HW1+PZnB6t31Y+iu5AUV2pJUlsiBCupnprkxeCxMaK4fcTIglz6KdHs3JeWg80 26 | QSnknn+Lz22X2t5W24gKc16enqdq5DAlwHDmdP8GjIJsHKJGm14gmtALxhnG7O0u 27 | JEXhIhkEJpx3ZLwH9S4zg36AwZY= 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /library/cxl_tsp_responder_lib/cxl_tsp_rsp_error.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "hal/library/debuglib.h" 10 | #include "library/spdm_requester_lib.h" 11 | #include "library/spdm_transport_pcidoe_lib.h" 12 | #include "library/cxl_tsp_responder_lib.h" 13 | #include "library/cxl_tsp_device_lib.h" 14 | 15 | /** 16 | * Process the TSP request and return the response. 17 | * 18 | * @param request the TSP request message, start from pci_tsp_header_t. 19 | * @param request_size size in bytes of request. 20 | * @param response the TSP response message, start from pci_tsp_header_t. 21 | * @param response_size size in bytes of response. 22 | * 23 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 24 | * @return ERROR The request is not processed. 25 | **/ 26 | libspdm_return_t cxl_tsp_get_response_error ( 27 | const void *pci_doe_context, 28 | const void *spdm_context, const uint32_t *session_id, 29 | const cxl_tsp_header_t *tsp_header, 30 | uint32_t error_code, uint32_t error_data, 31 | void *response, size_t *response_size) 32 | { 33 | cxl_tsp_error_rsp_t *tsp_response; 34 | 35 | tsp_response = response; 36 | 37 | LIBSPDM_ASSERT (*response_size >= sizeof(cxl_tsp_error_rsp_t)); 38 | *response_size = sizeof(cxl_tsp_error_rsp_t); 39 | 40 | libspdm_zero_mem (response, *response_size); 41 | tsp_response->header.tsp_version = tsp_header->tsp_version; 42 | tsp_response->header.op_code = CXL_TSP_OPCODE_ERROR_RSP; 43 | 44 | tsp_response->error_code = error_code; 45 | tsp_response->error_data = error_data; 46 | 47 | return LIBSPDM_STATUS_SUCCESS; 48 | } 49 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_ide_km_device_lib/pci_ide_km_device_key_set_go.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_ide_km_device_lib.h" 12 | 13 | /** 14 | * Process the IDE_KM request and return the response. 15 | * 16 | * @param request the IDE_KM request message, start from pci_ide_km_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the IDE_KM response message, start from pci_ide_km_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libspdm_return_t pci_ide_km_device_key_set_go (const void *pci_doe_context, 25 | const void *spdm_context, const uint32_t *session_id, 26 | uint8_t stream_id, uint8_t key_sub_stream, 27 | uint8_t port_index) 28 | { 29 | libidekm_device_port_context *device_port_context; 30 | uint8_t index; 31 | 32 | device_port_context = libidekm_get_device_port_context (port_index); 33 | if (device_port_context == NULL) { 34 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 35 | } 36 | 37 | index = key_sub_stream & (PCI_IDE_KM_KEY_SET_MASK | PCI_IDE_KM_KEY_DIRECTION_MASK); 38 | 39 | /* key set go */ 40 | 41 | device_port_context->is_key_set_go[index] = true; 42 | 43 | return LIBSPDM_STATUS_SUCCESS; 44 | } 45 | -------------------------------------------------------------------------------- /library/cxl_ide_km_device_lib_sample/cxl_ide_km_device_key_set_stop.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_ide_km_device_lib.h" 12 | 13 | /** 14 | * Process the IDE_KM request and return the response. 15 | * 16 | * @param request the IDE_KM request message, start from cxl_ide_km_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the IDE_KM response message, start from cxl_ide_km_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libspdm_return_t cxl_ide_km_device_key_set_stop (const void *pci_doe_context, 25 | const void *spdm_context, 26 | const uint32_t *session_id, 27 | uint8_t stream_id, uint8_t key_sub_stream, 28 | uint8_t port_index) 29 | { 30 | libcxlidekm_device_port_context *device_port_context; 31 | uint8_t index; 32 | 33 | device_port_context = libcxlidekm_get_device_port_context (port_index); 34 | if (device_port_context == NULL) { 35 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 36 | } 37 | 38 | index = (key_sub_stream & CXL_IDE_KM_KEY_DIRECTION_MASK) >> 1; 39 | 40 | /* key set stop */ 41 | 42 | device_port_context->is_key_set_go[index] = false; 43 | 44 | return LIBSPDM_STATUS_SUCCESS; 45 | } 46 | -------------------------------------------------------------------------------- /library/cxl_ide_km_device_lib_sample/cxl_ide_km_device_context.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_ide_km_device_lib.h" 12 | 13 | libcxlidekm_device_port_context g_cxlidekm_device_port_context; 14 | 15 | libcxlidekm_device_port_context *libcxlidekm_initialize_device_port_context ( 16 | uint8_t port_index 17 | ) 18 | { 19 | libspdm_zero_mem ( 20 | &g_cxlidekm_device_port_context, 21 | sizeof(g_cxlidekm_device_port_context) 22 | ); 23 | g_cxlidekm_device_port_context.port_index = port_index; 24 | g_cxlidekm_device_port_context.dev_func_num = 0; 25 | g_cxlidekm_device_port_context.bus_num = 0; 26 | g_cxlidekm_device_port_context.segment = 0; 27 | g_cxlidekm_device_port_context.max_port_index = 7; 28 | g_cxlidekm_device_port_context.caps = CXL_IDE_KM_QUERY_RESP_CAP_VERSION_1 | 29 | CXL_IDE_KM_QUERY_RESP_IV_GEN_CAP | 30 | CXL_IDE_KM_QUERY_RESP_KEY_GEN_CAP | 31 | CXL_IDE_KM_QUERY_RESP_K_SET_STOP_CAP; 32 | g_cxlidekm_device_port_context.ide_reg_buffer_count = CXL_IDE_KM_IDE_CAP_REG_BLOCK_MAX_COUNT; 33 | 34 | /* TBD: init the ide_reg_block */ 35 | 36 | return &g_cxlidekm_device_port_context; 37 | } 38 | 39 | libcxlidekm_device_port_context *libcxlidekm_get_device_port_context ( 40 | uint8_t port_index 41 | ) 42 | { 43 | if (g_cxlidekm_device_port_context.port_index == port_index) { 44 | return &g_cxlidekm_device_port_context; 45 | } else { 46 | return NULL; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /library/pci_ide_km_device_lib_sample/pci_ide_km_device_key_set_stop.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_ide_km_device_lib.h" 12 | 13 | /** 14 | * Process the IDE_KM request and return the response. 15 | * 16 | * @param request the IDE_KM request message, start from pci_ide_km_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the IDE_KM response message, start from pci_ide_km_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libspdm_return_t pci_ide_km_device_key_set_stop (const void *pci_doe_context, 25 | const void *spdm_context, 26 | const uint32_t *session_id, 27 | uint8_t stream_id, uint8_t key_sub_stream, 28 | uint8_t port_index) 29 | { 30 | libidekm_device_port_context *device_port_context; 31 | uint8_t index; 32 | 33 | device_port_context = libidekm_get_device_port_context (port_index); 34 | if (device_port_context == NULL) { 35 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 36 | } 37 | 38 | index = key_sub_stream & (PCI_IDE_KM_KEY_SET_MASK | PCI_IDE_KM_KEY_DIRECTION_MASK); 39 | 40 | /* key set stop */ 41 | 42 | device_port_context->is_key_set_go[index] = false; 43 | 44 | return LIBSPDM_STATUS_SUCCESS; 45 | } 46 | -------------------------------------------------------------------------------- /library/pci_tdisp_device_lib_sample/pci_tdisp_device_interface_report.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | /** 14 | * Process the TDISP request and return the response. 15 | * 16 | * @param request the TDISP request message, start from pci_tdisp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TDISP response message, start from pci_tdisp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libtdisp_error_code_t pci_tdisp_device_get_interface_report (const void *pci_doe_context, 25 | const void *spdm_context, 26 | const uint32_t *session_id, 27 | const pci_tdisp_interface_id_t *interface_id, 28 | uint8_t **interface_report, uint16_t *interface_report_size) 29 | { 30 | libtdisp_interface_context *interface_context; 31 | 32 | interface_context = libtdisp_get_interface_context (interface_id); 33 | if (interface_context == NULL) { 34 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE; 35 | } 36 | *interface_report_size = interface_context->interface_report_size; 37 | *interface_report = interface_context->interface_report; 38 | 39 | return PCI_TDISP_ERROR_CODE_SUCCESS; 40 | } 41 | -------------------------------------------------------------------------------- /library/cxl_tsp_device_lib_sample/cxl_tsp_device_get_configuration.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2024 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_tsp_device_lib.h" 12 | 13 | /** 14 | * Process the TSP request and return the response. 15 | * 16 | * @param request the TSP request message, start from cxl_tsp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TSP response message, start from cxl_tsp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libcxltsp_error_code_t cxl_tsp_device_get_configuration ( 25 | const void *pci_doe_context, 26 | const void *spdm_context, const uint32_t *session_id, 27 | libcxltsp_device_configuration_t *device_configuration, 28 | uint8_t *current_tsp_state) 29 | { 30 | libcxltsp_device_context *device_context; 31 | 32 | device_context = libcxltsp_get_device_context (pci_doe_context); 33 | if (device_context == NULL) { 34 | return CXL_TSP_ERROR_CODE_UNSPECIFIED; 35 | } 36 | if (device_configuration != NULL) { 37 | libspdm_copy_mem (device_configuration, 38 | sizeof(libcxltsp_device_configuration_t), 39 | &device_context->device_configuration, 40 | sizeof(libcxltsp_device_configuration_t)); 41 | } 42 | 43 | // TBD: need to get hardware state 44 | *current_tsp_state = device_context->current_tsp_state; 45 | 46 | return CXL_TSP_ERROR_CODE_SUCCESS; 47 | } 48 | -------------------------------------------------------------------------------- /library/pci_tdisp_device_lib_sample/pci_tdisp_device_stop_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | /** 14 | * Process the TDISP request and return the response. 15 | * 16 | * @param request the TDISP request message, start from pci_tdisp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TDISP response message, start from pci_tdisp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libtdisp_error_code_t pci_tdisp_device_stop_interface (const void *pci_doe_context, 25 | const void *spdm_context, 26 | const uint32_t *session_id, 27 | const pci_tdisp_interface_id_t *interface_id) 28 | { 29 | libtdisp_interface_context *interface_context; 30 | 31 | interface_context = libtdisp_get_interface_context (interface_id); 32 | if (interface_context == NULL) { 33 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE; 34 | } 35 | if (interface_context->tdi_state == PCI_TDISP_INTERFACE_STATE_CONFIG_UNLOCKED) { 36 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE_STATE; 37 | } 38 | 39 | /* stop the interface */ 40 | 41 | interface_context->tdi_state = PCI_TDISP_INTERFACE_STATE_CONFIG_UNLOCKED; 42 | 43 | return PCI_TDISP_ERROR_CODE_SUCCESS; 44 | } 45 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_ide_km_device_lib/pci_ide_km_device_key_set_stop.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_ide_km_device_lib.h" 12 | 13 | /** 14 | * Process the IDE_KM request and return the response. 15 | * 16 | * @param request the IDE_KM request message, start from pci_ide_km_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the IDE_KM response message, start from pci_ide_km_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libspdm_return_t pci_ide_km_device_key_set_stop (const void *pci_doe_context, 25 | const void *spdm_context, 26 | const uint32_t *session_id, 27 | uint8_t stream_id, uint8_t key_sub_stream, 28 | uint8_t port_index) 29 | { 30 | libidekm_device_port_context *device_port_context; 31 | uint8_t index; 32 | 33 | device_port_context = libidekm_get_device_port_context (port_index); 34 | if (device_port_context == NULL) { 35 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 36 | } 37 | 38 | index = key_sub_stream & (PCI_IDE_KM_KEY_SET_MASK | PCI_IDE_KM_KEY_DIRECTION_MASK); 39 | 40 | /* key set stop */ 41 | 42 | device_port_context->is_key_set_go[index] = false; 43 | 44 | return LIBSPDM_STATUS_SUCCESS; 45 | } 46 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_tdisp_device_lib/pci_tdisp_device_interface_report.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | /** 14 | * Process the TDISP request and return the response. 15 | * 16 | * @param request the TDISP request message, start from pci_tdisp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TDISP response message, start from pci_tdisp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libtdisp_error_code_t pci_tdisp_device_get_interface_report (const void *pci_doe_context, 25 | const void *spdm_context, 26 | const uint32_t *session_id, 27 | const pci_tdisp_interface_id_t *interface_id, 28 | uint8_t **interface_report, uint16_t *interface_report_size) 29 | { 30 | libtdisp_interface_context *interface_context; 31 | 32 | interface_context = libtdisp_get_interface_context (interface_id); 33 | if (interface_context == NULL) { 34 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE; 35 | } 36 | *interface_report_size = interface_context->interface_report_size; 37 | *interface_report = interface_context->interface_report; 38 | 39 | return PCI_TDISP_ERROR_CODE_SUCCESS; 40 | } 41 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_tdisp_device_lib/pci_tdisp_device_stop_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | /** 14 | * Process the TDISP request and return the response. 15 | * 16 | * @param request the TDISP request message, start from pci_tdisp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TDISP response message, start from pci_tdisp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libtdisp_error_code_t pci_tdisp_device_stop_interface (const void *pci_doe_context, 25 | const void *spdm_context, 26 | const uint32_t *session_id, 27 | const pci_tdisp_interface_id_t *interface_id) 28 | { 29 | libtdisp_interface_context *interface_context; 30 | 31 | interface_context = libtdisp_get_interface_context (interface_id); 32 | if (interface_context == NULL) { 33 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE; 34 | } 35 | if (interface_context->tdi_state == PCI_TDISP_INTERFACE_STATE_CONFIG_UNLOCKED) { 36 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE_STATE; 37 | } 38 | 39 | /* stop the interface */ 40 | 41 | interface_context->tdi_state = PCI_TDISP_INTERFACE_STATE_CONFIG_UNLOCKED; 42 | 43 | return PCI_TDISP_ERROR_CODE_SUCCESS; 44 | } 45 | -------------------------------------------------------------------------------- /library/cxl_tsp_device_lib_sample/cxl_tsp_device_get_version.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2024 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_tsp_device_lib.h" 12 | 13 | /** 14 | * Process the TSP request and return the response. 15 | * 16 | * @param request the TSP request message, start from cxl_tsp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TSP response message, start from cxl_tsp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libcxltsp_error_code_t cxl_tsp_device_get_version ( 25 | const void *pci_doe_context, 26 | const void *spdm_context, const uint32_t *session_id, 27 | uint8_t *version_number_entry_count, 28 | cxl_tsp_version_number_t *version_number_entry) 29 | { 30 | libcxltsp_device_context *device_context; 31 | 32 | device_context = libcxltsp_initialize_device_context (pci_doe_context); 33 | if (device_context == NULL) { 34 | return CXL_TSP_ERROR_CODE_UNSPECIFIED; 35 | } 36 | 37 | libcxltsp_initialize_session_id ((void *)spdm_context, *session_id); 38 | 39 | libspdm_copy_mem (version_number_entry, 40 | sizeof(cxl_tsp_version_number_t) * (*version_number_entry_count), 41 | device_context->supported_tsp_versions, 42 | sizeof(cxl_tsp_version_number_t) * 43 | device_context->supported_tsp_versions_count); 44 | *version_number_entry_count = device_context->supported_tsp_versions_count; 45 | 46 | return CXL_TSP_ERROR_CODE_SUCCESS; 47 | } 48 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/spdm_device_responder/spdm_responder_pci_doe.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "spdm_responder.h" 8 | #include "library/pci_doe_responder_lib.h" 9 | #include "library/pci_ide_km_responder_lib.h" 10 | #include "library/pci_tdisp_responder_lib.h" 11 | 12 | void *m_pci_doe_context; 13 | 14 | libspdm_return_t pci_doe_init_responder() 15 | { 16 | libspdm_return_t status; 17 | status = pci_doe_register_vendor_response_func ( 18 | m_pci_doe_context, 19 | SPDM_REGISTRY_ID_PCISIG, SPDM_VENDOR_ID_PCISIG, 20 | PCI_PROTOCOL_ID_IDE_KM, pci_ide_km_get_response); 21 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 22 | return status; 23 | } 24 | status = pci_doe_register_vendor_response_func ( 25 | m_pci_doe_context, 26 | SPDM_REGISTRY_ID_PCISIG, SPDM_VENDOR_ID_PCISIG, 27 | PCI_PROTOCOL_ID_TDISP, pci_tdisp_get_response); 28 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 29 | return status; 30 | } 31 | return LIBSPDM_STATUS_SUCCESS; 32 | } 33 | 34 | libspdm_return_t spdm_get_response_vendor_defined_request( 35 | void *spdm_context, const uint32_t *session_id, bool is_app_message, 36 | size_t request_size, const void *request, size_t *response_size, 37 | void *response) 38 | { 39 | libspdm_return_t status; 40 | 41 | LIBSPDM_ASSERT(!is_app_message); 42 | status = pci_doe_get_response_spdm_vendor_defined_request ( 43 | m_pci_doe_context, spdm_context, session_id, 44 | request, request_size, response, response_size); 45 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 46 | libspdm_generate_error_response(spdm_context, 47 | SPDM_ERROR_CODE_INVALID_REQUEST, 0, 48 | response_size, response); 49 | } 50 | return LIBSPDM_STATUS_SUCCESS; 51 | } 52 | -------------------------------------------------------------------------------- /spdm_emu/spdm_emu_common/nv_storage.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #ifndef __SPDM_EMU_NV_STORAGE_LIB_H__ 8 | #define __SPDM_EMU_NV_STORAGE_LIB_H__ 9 | 10 | #include "hal/base.h" 11 | #include "industry_standard/spdm.h" 12 | 13 | #define SPDM_NEGOTIATED_STATE_STRUCT_VERSION 1 14 | 15 | #pragma pack(1) 16 | typedef struct { 17 | uint32_t version; 18 | uint8_t spdm_version; 19 | uint8_t requester_cap_ct_exponent; 20 | uint32_t requester_cap_flags; 21 | uint8_t responder_cap_ct_exponent; 22 | uint32_t responder_cap_flags; 23 | uint8_t measurement_spec; 24 | uint8_t other_params_support; 25 | uint8_t mel_spec; 26 | uint32_t measurement_hash_algo; 27 | uint32_t base_asym_algo; 28 | uint32_t base_hash_algo; 29 | uint16_t dhe_named_group; 30 | uint16_t aead_cipher_suite; 31 | uint16_t req_base_asym_alg; 32 | uint16_t key_schedule; 33 | size_t vca_buffer_size; 34 | uint8_t vca_buffer[LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE]; 35 | } spdm_negotiated_state_struct_t; 36 | #pragma pack() 37 | 38 | /** 39 | * privision the capability and algorithm for PKS version only case. 40 | */ 41 | libspdm_return_t spdm_provision_psk_version_only(void *spdm_context, 42 | bool is_requester); 43 | 44 | /** 45 | * Load the negotiated_state from NV storage to an SPDM context. 46 | */ 47 | libspdm_return_t spdm_load_negotiated_state(void *spdm_context, 48 | bool is_requester); 49 | 50 | /** 51 | * Save the negotiated_state to NV storage from an SPDM context. 52 | */ 53 | libspdm_return_t spdm_save_negotiated_state(void *spdm_context, 54 | bool is_requester); 55 | 56 | /** 57 | * Clear the negotiated_state in the NV storage. 58 | */ 59 | libspdm_return_t spdm_clear_negotiated_state(void *spdm_context); 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /library/cxl_ide_km_device_lib_sample/cxl_ide_km_device_get_key.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_ide_km_device_lib.h" 12 | #include "library/spdm_crypt_lib.h" 13 | 14 | /** 15 | * Process the IDE_KM request and return the response. 16 | * 17 | * @param request the IDE_KM request message, start from cxl_ide_km_header_t. 18 | * @param request_size size in bytes of request. 19 | * @param response the IDE_KM response message, start from cxl_ide_km_header_t. 20 | * @param response_size size in bytes of response. 21 | * 22 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 23 | * @return ERROR The request is not processed. 24 | **/ 25 | libspdm_return_t cxl_ide_km_device_get_key (const void *pci_doe_context, 26 | const void *spdm_context, const uint32_t *session_id, 27 | uint8_t stream_id, uint8_t key_sub_stream, 28 | uint8_t port_index, 29 | cxl_ide_km_aes_256_gcm_key_buffer_t *key_buffer) 30 | { 31 | libcxlidekm_device_port_context *device_port_context; 32 | bool result; 33 | 34 | device_port_context = libcxlidekm_get_device_port_context (port_index); 35 | if (device_port_context == NULL) { 36 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 37 | } 38 | 39 | /* get key */ 40 | 41 | result = libspdm_get_random_number(sizeof(key_buffer->key), (void *)key_buffer->key); 42 | if (!result) { 43 | return LIBSPDM_STATUS_LOW_ENTROPY; 44 | } 45 | key_buffer->iv[0] = 0; 46 | key_buffer->iv[1] = 1; 47 | key_buffer->iv[2] = 2; 48 | 49 | return LIBSPDM_STATUS_SUCCESS; 50 | } 51 | -------------------------------------------------------------------------------- /.github/workflows/chunk_device_sample.yml: -------------------------------------------------------------------------------- 1 | name: Device Sample 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | workflow_dispatch: 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} 12 | cancel-in-progress: true 13 | 14 | env: 15 | BUILD_TYPE: Release 16 | 17 | jobs: 18 | arm_mbedtls_build: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v6 22 | with: 23 | submodules: recursive 24 | 25 | - name: Build 26 | run: | 27 | wget https://developer.arm.com/-/media/Files/downloads/gnu/11.2-2022.02/binrel/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu.tar.xz 28 | tar -xvf gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu.tar.xz -C ~/ 29 | export PATH=~/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin:$PATH 30 | cd spdm-device-sample/spdm_device_sample 31 | cmake --version 32 | mkdir build 33 | cd build 34 | cmake -E env CFLAGS="-DLIBSPDM_DEBUG_LIBSPDM_ASSERT_CONFIG=3" cmake -DARCH=aarch64 -DTOOLCHAIN=ARM_GNU -DTARGET=Release -DCRYPTO=mbedtls .. 35 | make -j`nproc` 36 | 37 | VS2019_mbedtls_build: 38 | runs-on: windows-latest 39 | steps: 40 | - uses: actions/checkout@v6 41 | with: 42 | submodules: recursive 43 | #ilammy/msvc-dev-cmd@v1 is GitHub Action for configuring Developer Command Prompt for Microsoft Visual Studio on Windows. 44 | #This sets up the environment for compiling C/C++ code from command line. 45 | - name: Add msbuild to PATH 46 | uses: ilammy/msvc-dev-cmd@v1 47 | with: 48 | arch: x64 49 | 50 | - name: Build 51 | run: | 52 | cd spdm-device-sample\spdm_device_sample 53 | mkdir build 54 | cd build 55 | cmake -E env CFLAGS="-DLIBSPDM_DEBUG_LIBSPDM_ASSERT_CONFIG=3" cmake -G"NMake Makefiles" -DARCH=x64 -DTOOLCHAIN=VS2019 -DTARGET=Release -DCRYPTO=mbedtls .. 56 | nmake 57 | -------------------------------------------------------------------------------- /include/library/cxl_tsp_common_lib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2024 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #ifndef __CXL_TSP_COMMON_LIB_H__ 8 | #define __CXL_TSP_COMMON_LIB_H__ 9 | 10 | #include "industry_standard/cxl_idekm.h" 11 | #include "industry_standard/cxl_tsp.h" 12 | 13 | #define LIBCXLTSP_MAX_VERSION_COUNT 0x1 14 | #define LIBCXLTSP_CONFIGURATION_REPORT_MAX_SIZE 0x1000 15 | 16 | #define LIBCXLTSP_CONFIGURATION_REPORT_PORTION_LEN 0x200 17 | 18 | #define LIBCXLTSP_ERROR_MESSAGE_MAX_SIZE (sizeof(cxl_tsp_error_rsp_t)) 19 | 20 | typedef struct { 21 | uint16_t memory_encryption_features_supported; 22 | uint32_t memory_encryption_algorithms_supported; 23 | uint16_t memory_encryption_number_of_range_based_keys; 24 | uint16_t te_state_change_and_access_control_features_supported; 25 | uint32_t supported_explicit_oob_te_state_granularity; 26 | uint32_t supported_explicit_ib_te_state_granularity; 27 | uint16_t configuration_features_supported; 28 | uint32_t number_of_ckids; 29 | uint8_t number_of_secondary_sessions; 30 | } libcxltsp_device_capabilities_t; 31 | 32 | typedef struct { 33 | uint16_t memory_encryption_features_enable; 34 | uint32_t memory_encryption_algorithm_select; 35 | uint16_t te_state_change_and_access_control_features_enable; 36 | uint32_t explicit_oob_te_state_granularity; 37 | uint16_t configuration_features_enable; 38 | uint32_t ckid_base; 39 | uint32_t number_of_ckids; 40 | cxl_tsp_explicit_ib_te_state_granularity_entry_t explicit_ib_te_state_granularity_entry[8]; 41 | } libcxltsp_device_configuration_t; 42 | 43 | typedef struct { 44 | uint16_t configuration_validity_flags; 45 | uint8_t secondary_session_ckid_type; 46 | cxl_tsp_secondary_session_psk_key_material_t secondary_session_psk_key_material[4]; 47 | } libcxltsp_device_2nd_session_info_t; 48 | 49 | typedef enum { 50 | LIB_CXL_TSP_SESSION_TYPE_PRIMARY, 51 | LIB_CXL_TSP_SESSION_TYPE_SECONDARY, 52 | LIB_CXL_TSP_SESSION_TYPE_OTHER, 53 | } libcxltsp_session_type; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /library/pci_ide_km_device_lib_sample/pci_ide_km_device_query.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_ide_km_device_lib.h" 12 | 13 | /** 14 | * Process the IDE_KM request and return the response. 15 | * 16 | * @param request the IDE_KM request message, start from pci_ide_km_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the IDE_KM response message, start from pci_ide_km_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libspdm_return_t pci_ide_km_device_query (const void *pci_doe_context, 25 | const void *spdm_context, const uint32_t *session_id, 26 | uint8_t port_index, uint8_t *dev_func_num, 27 | uint8_t *bus_num, uint8_t *segment, 28 | uint8_t *max_port_index, 29 | uint32_t **ide_reg_buffer, uint32_t *ide_reg_buffer_count) 30 | { 31 | libidekm_device_port_context *device_port_context; 32 | 33 | device_port_context = libidekm_initialize_device_port_context (port_index); 34 | if (device_port_context == NULL) { 35 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 36 | } 37 | 38 | *dev_func_num = device_port_context->dev_func_num; 39 | *bus_num = device_port_context->bus_num; 40 | *segment = device_port_context->segment; 41 | *max_port_index = device_port_context->max_port_index; 42 | 43 | *ide_reg_buffer = device_port_context->ide_reg_buffer; 44 | *ide_reg_buffer_count = device_port_context->ide_reg_buffer_count; 45 | 46 | return LIBSPDM_STATUS_SUCCESS; 47 | } 48 | -------------------------------------------------------------------------------- /library/pci_tdisp_responder_lib/pci_tdisp_rsp_error.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "hal/library/debuglib.h" 10 | #include "library/spdm_requester_lib.h" 11 | #include "library/spdm_transport_pcidoe_lib.h" 12 | #include "library/pci_tdisp_responder_lib.h" 13 | #include "library/pci_tdisp_device_lib.h" 14 | 15 | /** 16 | * Process the TDISP request and return the response. 17 | * 18 | * @param request the TDISP request message, start from pci_tdisp_header_t. 19 | * @param request_size size in bytes of request. 20 | * @param response the TDISP response message, start from pci_tdisp_header_t. 21 | * @param response_size size in bytes of response. 22 | * 23 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 24 | * @return ERROR The request is not processed. 25 | **/ 26 | libspdm_return_t pci_tdisp_get_response_error (const void *pci_doe_context, 27 | const void *spdm_context, const uint32_t *session_id, 28 | const pci_tdisp_header_t *tdisp_header, 29 | uint32_t error_code, uint32_t error_data, 30 | void *response, size_t *response_size) 31 | { 32 | pci_tdisp_error_response_t *tdisp_response; 33 | 34 | tdisp_response = response; 35 | 36 | LIBSPDM_ASSERT (*response_size >= sizeof(pci_tdisp_error_response_t)); 37 | *response_size = sizeof(pci_tdisp_error_response_t); 38 | 39 | libspdm_zero_mem (response, *response_size); 40 | tdisp_response->header.version = tdisp_header->version; 41 | tdisp_response->header.message_type = PCI_TDISP_ERROR; 42 | tdisp_response->header.interface_id.function_id = tdisp_header->interface_id.function_id; 43 | 44 | tdisp_response->error_code = error_code; 45 | tdisp_response->error_data = error_data; 46 | 47 | return LIBSPDM_STATUS_SUCCESS; 48 | } 49 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_ide_km_device_lib/pci_ide_km_device_query.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_ide_km_device_lib.h" 12 | 13 | /** 14 | * Process the IDE_KM request and return the response. 15 | * 16 | * @param request the IDE_KM request message, start from pci_ide_km_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the IDE_KM response message, start from pci_ide_km_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libspdm_return_t pci_ide_km_device_query (const void *pci_doe_context, 25 | const void *spdm_context, const uint32_t *session_id, 26 | uint8_t port_index, uint8_t *dev_func_num, 27 | uint8_t *bus_num, uint8_t *segment, 28 | uint8_t *max_port_index, 29 | uint32_t **ide_reg_buffer, uint32_t *ide_reg_buffer_count) 30 | { 31 | libidekm_device_port_context *device_port_context; 32 | 33 | device_port_context = libidekm_initialize_device_port_context (port_index); 34 | if (device_port_context == NULL) { 35 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 36 | } 37 | 38 | *dev_func_num = device_port_context->dev_func_num; 39 | *bus_num = device_port_context->bus_num; 40 | *segment = device_port_context->segment; 41 | *max_port_index = device_port_context->max_port_index; 42 | 43 | *ide_reg_buffer = device_port_context->ide_reg_buffer; 44 | *ide_reg_buffer_count = device_port_context->ide_reg_buffer_count; 45 | 46 | return LIBSPDM_STATUS_SUCCESS; 47 | } 48 | -------------------------------------------------------------------------------- /spdm_emu/spdm_device_verifier_tool/OpaTool.py: -------------------------------------------------------------------------------- 1 | ## 2 | # 3 | # Copyright Notice: 4 | # Copyright 2021-2022 DMTF. All rights reserved. 5 | # License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 6 | # 7 | # This tool generates OPA input file from evidence file and reference file. 8 | # 9 | ## 10 | 11 | import os 12 | import json 13 | import argparse 14 | 15 | def is_json(file): 16 | with open(file, "r") as fp: 17 | try: 18 | json_data = json.loads(fp.read()) 19 | except Exception: 20 | return False 21 | return True 22 | 23 | def gen_opa_input(evidence_path, reference_path, opa): 24 | opa_temp = { 25 | "evidence": "", 26 | "reference": "" 27 | } 28 | with open(evidence_path, 'r') as fp: 29 | evidence_data = json.loads(fp.read()) 30 | opa_temp["evidence"] = evidence_data 31 | 32 | with open(reference_path, 'r') as fp: 33 | reference_data = json.loads(fp.read()) 34 | opa_temp["reference"] = reference_data 35 | 36 | with open(opa, 'w') as fp: 37 | fp.write(json.dumps(opa_temp, indent=2)) 38 | 39 | if __name__ == '__main__': 40 | parser = argparse.ArgumentParser() 41 | 42 | parser.add_argument('-e', dest='Evidence', type=str, help='Json evidence file path', required=True) 43 | parser.add_argument('-r', dest='Reference', type=str, help='Json reference file path', required=True) 44 | parser.add_argument('-o', dest='Opa', type=str, help='Json OPA file path', required=True) 45 | 46 | args = parser.parse_args() 47 | 48 | if not os.path.exists(args.Evidence): 49 | raise Exception("ERROR: Could not locate json Evidence file '%s' !" % args.Evidence) 50 | if not is_json(args.Evidence): 51 | raise Exception("ERROR: '%s' is not a json format file and cannot be parse !" % args.Evidence) 52 | if not os.path.exists(args.Reference): 53 | raise Exception("ERROR: Could not locate json Reference file '%s' !" % args.Reference) 54 | if not is_json(args.Reference): 55 | raise Exception("ERROR: '%s' is not a json format file and cannot be parse !" % args.Reference) 56 | 57 | gen_opa_input(args.Evidence, args.Reference, args.Opa) 58 | -------------------------------------------------------------------------------- /library/pci_tdisp_requester_lib/pci_tdisp_send_receive.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_requester_lib.h" 12 | 13 | /** 14 | * Send and receive a TDISP message 15 | * 16 | * @param spdm_context A pointer to the SPDM context. 17 | * @param session_id Indicates if it is a secured message protected via SPDM session. 18 | * If session_id is NULL, it is a normal message. 19 | * If session_id is NOT NULL, it is a secured message. 20 | * @param request the TDISP request message, start from pci_tdisp_header_t. 21 | * @param request_size size in bytes of request. 22 | * @param response the TDISP response message, start from pci_tdisp_header_t. 23 | * @param response_size size in bytes of response. 24 | * 25 | * @retval LIBSPDM_STATUS_SUCCESS The TDISP request is sent and response is received. 26 | * @return ERROR The TDISP response is not received correctly. 27 | **/ 28 | libspdm_return_t pci_tdisp_send_receive_data (void *spdm_context, const uint32_t *session_id, 29 | const void *request, size_t request_size, 30 | void *response, size_t *response_size) 31 | { 32 | libspdm_return_t status; 33 | pci_protocol_header_t pci_protocol; 34 | 35 | pci_protocol.protocol_id = PCI_PROTOCOL_ID_TDISP; 36 | status = pci_doe_spdm_vendor_send_receive_data (spdm_context, session_id, 37 | pci_protocol, 38 | request, request_size, response, response_size); 39 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 40 | return status; 41 | } 42 | 43 | return LIBSPDM_STATUS_SUCCESS; 44 | } 45 | -------------------------------------------------------------------------------- /library/cxl_tsp_requester_lib/cxl_tsp_send_receive.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_tsp_requester_lib.h" 12 | 13 | /** 14 | * Send and receive an TSP message 15 | * 16 | * @param spdm_context A pointer to the SPDM context. 17 | * @param session_id Indicates if it is a secured message protected via SPDM session. 18 | * If session_id is NULL, it is a normal message. 19 | * If session_id is NOT NULL, it is a secured message. 20 | * @param request the TSP request message, start from cxl_tsp_header_t. 21 | * @param request_size size in bytes of request. 22 | * @param response the TSP response message, start from cxl_tsp_header_t. 23 | * @param response_size size in bytes of response. 24 | * 25 | * @retval LIBSPDM_STATUS_SUCCESS The IDM_KM request is sent and response is received. 26 | * @return ERROR The IDM_KM response is not received correctly. 27 | **/ 28 | libspdm_return_t cxl_tsp_send_receive_data ( 29 | void *spdm_context, const uint32_t *session_id, 30 | const void *request, size_t request_size, 31 | void *response, size_t *response_size) 32 | { 33 | libspdm_return_t status; 34 | cxl_protocol_header_t cxl_protocol; 35 | 36 | cxl_protocol.protocol_id = CXL_PROTOCOL_ID_TSP; 37 | status = pci_doe_spdm_vendor_send_receive_data_ex (spdm_context, session_id, 38 | SPDM_VENDOR_ID_CXL, cxl_protocol, 39 | request, request_size, response, 40 | response_size); 41 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 42 | return status; 43 | } 44 | 45 | return LIBSPDM_STATUS_SUCCESS; 46 | } 47 | -------------------------------------------------------------------------------- /library/mctp_requester_lib/pldm_send_receive.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_mctp_lib.h" 11 | #include "library/mctp_requester_lib.h" 12 | 13 | /** 14 | * Send and receive an PLDM message 15 | * 16 | * @param spdm_context A pointer to the SPDM context. 17 | * @param session_id Indicates if it is a secured message protected via SPDM session. 18 | * If session_id is NULL, it is a normal message. 19 | * If session_id is NOT NULL, it is a secured message. 20 | * @param request the PLDM request message, start from pldm_message_header_t. 21 | * @param request_size size in bytes of request. 22 | * @param response the PLDM response message, start from pldm_message_header_t. 23 | * @param response_size size in bytes of response. 24 | * 25 | * @retval LIBSPDM_STATUS_SUCCESS The PLDM request is sent and response is received. 26 | * @return ERROR The PLDM response is not received correctly. 27 | **/ 28 | libspdm_return_t pldm_send_receive_data (const void *mctp_context, 29 | void *spdm_context, const uint32_t *session_id, 30 | const void *request, size_t request_size, 31 | void *response, size_t *response_size) 32 | { 33 | libspdm_return_t status; 34 | mctp_message_header_t mctp_header; 35 | 36 | mctp_header.message_type = MCTP_MESSAGE_TYPE_PLDM; 37 | status = mctp_send_receive_data (mctp_context, spdm_context, session_id, 38 | mctp_header, 39 | request, request_size, response, response_size); 40 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 41 | return status; 42 | } 43 | 44 | return LIBSPDM_STATUS_SUCCESS; 45 | } 46 | -------------------------------------------------------------------------------- /library/pci_ide_km_requester_lib/pci_ide_km_send_receive.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_ide_km_requester_lib.h" 12 | 13 | /** 14 | * Send and receive an IDE_KM message 15 | * 16 | * @param spdm_context A pointer to the SPDM context. 17 | * @param session_id Indicates if it is a secured message protected via SPDM session. 18 | * If session_id is NULL, it is a normal message. 19 | * If session_id is NOT NULL, it is a secured message. 20 | * @param request the IDE_KM request message, start from pci_ide_km_header_t. 21 | * @param request_size size in bytes of request. 22 | * @param response the IDE_KM response message, start from pci_ide_km_header_t. 23 | * @param response_size size in bytes of response. 24 | * 25 | * @retval LIBSPDM_STATUS_SUCCESS The IDM_KM request is sent and response is received. 26 | * @return ERROR The IDM_KM response is not received correctly. 27 | **/ 28 | libspdm_return_t pci_ide_km_send_receive_data (void *spdm_context, const uint32_t *session_id, 29 | const void *request, size_t request_size, 30 | void *response, size_t *response_size) 31 | { 32 | libspdm_return_t status; 33 | pci_protocol_header_t pci_protocol; 34 | 35 | pci_protocol.protocol_id = PCI_PROTOCOL_ID_IDE_KM; 36 | status = pci_doe_spdm_vendor_send_receive_data (spdm_context, session_id, 37 | pci_protocol, 38 | request, request_size, response, response_size); 39 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 40 | return status; 41 | } 42 | 43 | return LIBSPDM_STATUS_SUCCESS; 44 | } 45 | -------------------------------------------------------------------------------- /library/cxl_ide_km_device_lib_sample/cxl_ide_km_device_query.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_ide_km_device_lib.h" 12 | 13 | /** 14 | * Process the IDE_KM request and return the response. 15 | * 16 | * @param request the IDE_KM request message, start from cxl_ide_km_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the IDE_KM response message, start from cxl_ide_km_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libspdm_return_t cxl_ide_km_device_query (const void *pci_doe_context, 25 | const void *spdm_context, const uint32_t *session_id, 26 | uint8_t port_index, uint8_t *dev_func_num, 27 | uint8_t *bus_num, uint8_t *segment, 28 | uint8_t *max_port_index, 29 | uint8_t *caps, 30 | uint32_t **ide_reg_buffer, uint32_t *ide_reg_buffer_count) 31 | { 32 | libcxlidekm_device_port_context *device_port_context; 33 | 34 | device_port_context = libcxlidekm_initialize_device_port_context (port_index); 35 | if (device_port_context == NULL) { 36 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 37 | } 38 | 39 | *dev_func_num = device_port_context->dev_func_num; 40 | *bus_num = device_port_context->bus_num; 41 | *segment = device_port_context->segment; 42 | *max_port_index = device_port_context->max_port_index; 43 | *caps = device_port_context->caps; 44 | *ide_reg_buffer = device_port_context->ide_reg_buffer; 45 | *ide_reg_buffer_count = device_port_context->ide_reg_buffer_count; 46 | 47 | return LIBSPDM_STATUS_SUCCESS; 48 | } 49 | -------------------------------------------------------------------------------- /library/pci_tdisp_device_lib_sample/pci_tdisp_device_capabilities.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | /** 14 | * Process the TDISP request and return the response. 15 | * 16 | * @param request the TDISP request message, start from pci_tdisp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TDISP response message, start from pci_tdisp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libtdisp_error_code_t pci_tdisp_device_get_capabilities (const void *pci_doe_context, 25 | const void *spdm_context, 26 | const uint32_t *session_id, 27 | const pci_tdisp_interface_id_t *interface_id, 28 | const pci_tdisp_requester_capabilities_t *req_caps, 29 | pci_tdisp_responder_capabilities_t *rsp_caps) 30 | { 31 | libtdisp_interface_context *interface_context; 32 | 33 | interface_context = libtdisp_get_interface_context (interface_id); 34 | if (interface_context == NULL) { 35 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE; 36 | } 37 | libspdm_copy_mem (&interface_context->tdisp_req_caps, 38 | sizeof(interface_context->tdisp_req_caps), 39 | req_caps, 40 | sizeof(*req_caps)); 41 | libspdm_copy_mem (rsp_caps, 42 | sizeof(*rsp_caps), 43 | &interface_context->tdisp_rsp_caps, 44 | sizeof(interface_context->tdisp_rsp_caps)); 45 | 46 | return PCI_TDISP_ERROR_CODE_SUCCESS; 47 | } 48 | -------------------------------------------------------------------------------- /library/cxl_ide_km_requester_lib/cxl_ide_km_send_receive.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_ide_km_requester_lib.h" 12 | 13 | /** 14 | * Send and receive an IDE_KM message 15 | * 16 | * @param spdm_context A pointer to the SPDM context. 17 | * @param session_id Indicates if it is a secured message protected via SPDM session. 18 | * If session_id is NULL, it is a normal message. 19 | * If session_id is NOT NULL, it is a secured message. 20 | * @param request the IDE_KM request message, start from cxl_ide_km_header_t. 21 | * @param request_size size in bytes of request. 22 | * @param response the IDE_KM response message, start from cxl_ide_km_header_t. 23 | * @param response_size size in bytes of response. 24 | * 25 | * @retval LIBSPDM_STATUS_SUCCESS The IDM_KM request is sent and response is received. 26 | * @return ERROR The IDM_KM response is not received correctly. 27 | **/ 28 | libspdm_return_t cxl_ide_km_send_receive_data (void *spdm_context, const uint32_t *session_id, 29 | const void *request, size_t request_size, 30 | void *response, size_t *response_size) 31 | { 32 | libspdm_return_t status; 33 | cxl_protocol_header_t cxl_protocol; 34 | 35 | cxl_protocol.protocol_id = CXL_PROTOCOL_ID_IDE_KM; 36 | status = pci_doe_spdm_vendor_send_receive_data_ex (spdm_context, session_id, 37 | SPDM_VENDOR_ID_CXL, cxl_protocol, 38 | request, request_size, response, 39 | response_size); 40 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 41 | return status; 42 | } 43 | 44 | return LIBSPDM_STATUS_SUCCESS; 45 | } 46 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_tdisp_device_lib/pci_tdisp_device_capabilities.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | /** 14 | * Process the TDISP request and return the response. 15 | * 16 | * @param request the TDISP request message, start from pci_tdisp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TDISP response message, start from pci_tdisp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libtdisp_error_code_t pci_tdisp_device_get_capabilities (const void *pci_doe_context, 25 | const void *spdm_context, 26 | const uint32_t *session_id, 27 | const pci_tdisp_interface_id_t *interface_id, 28 | const pci_tdisp_requester_capabilities_t *req_caps, 29 | pci_tdisp_responder_capabilities_t *rsp_caps) 30 | { 31 | libtdisp_interface_context *interface_context; 32 | 33 | interface_context = libtdisp_get_interface_context (interface_id); 34 | if (interface_context == NULL) { 35 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE; 36 | } 37 | libspdm_copy_mem (&interface_context->tdisp_req_caps, 38 | sizeof(interface_context->tdisp_req_caps), 39 | req_caps, 40 | sizeof(*req_caps)); 41 | libspdm_copy_mem (rsp_caps, 42 | sizeof(*rsp_caps), 43 | &interface_context->tdisp_rsp_caps, 44 | sizeof(interface_context->tdisp_rsp_caps)); 45 | 46 | return PCI_TDISP_ERROR_CODE_SUCCESS; 47 | } 48 | -------------------------------------------------------------------------------- /library/cxl_ide_km_device_lib_sample/cxl_ide_km_device_key_prog.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_ide_km_device_lib.h" 12 | 13 | /** 14 | * Process the IDE_KM request and return the response. 15 | * 16 | * @param request the IDE_KM request message, start from cxl_ide_km_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the IDE_KM response message, start from cxl_ide_km_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libspdm_return_t cxl_ide_km_device_key_prog (const void *pci_doe_context, 25 | const void *spdm_context, const uint32_t *session_id, 26 | uint8_t stream_id, uint8_t key_sub_stream, 27 | uint8_t port_index, 28 | uint8_t *kp_ack_status, 29 | const cxl_ide_km_aes_256_gcm_key_buffer_t *key_buffer) 30 | { 31 | libcxlidekm_device_port_context *device_port_context; 32 | uint8_t index; 33 | 34 | device_port_context = libcxlidekm_get_device_port_context (port_index); 35 | if (device_port_context == NULL) { 36 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 37 | } 38 | 39 | index = (key_sub_stream & CXL_IDE_KM_KEY_DIRECTION_MASK) >> 1; 40 | 41 | /* program key */ 42 | 43 | libspdm_copy_mem (&device_port_context->key_buffer[index], 44 | sizeof(device_port_context->key_buffer[index]), 45 | key_buffer, 46 | sizeof(cxl_ide_km_aes_256_gcm_key_buffer_t) 47 | ); 48 | device_port_context->is_key_prog[index] = true; 49 | 50 | *kp_ack_status = CXL_IDE_KM_KP_ACK_STATUS_SUCCESS; 51 | 52 | return LIBSPDM_STATUS_SUCCESS; 53 | } 54 | -------------------------------------------------------------------------------- /library/pci_tdisp_device_lib_sample/pci_tdisp_device_start_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | /** 14 | * Process the TDISP request and return the response. 15 | * 16 | * @param request the TDISP request message, start from pci_tdisp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TDISP response message, start from pci_tdisp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libtdisp_error_code_t pci_tdisp_device_start_interface (const void *pci_doe_context, 25 | const void *spdm_context, 26 | const uint32_t *session_id, 27 | const pci_tdisp_interface_id_t *interface_id, 28 | const uint8_t *start_interface_nonce) 29 | { 30 | libtdisp_interface_context *interface_context; 31 | 32 | interface_context = libtdisp_get_interface_context (interface_id); 33 | if (interface_context == NULL) { 34 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE; 35 | } 36 | if (interface_context->tdi_state != PCI_TDISP_INTERFACE_STATE_CONFIG_LOCKED) { 37 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE_STATE; 38 | } 39 | if (!libspdm_consttime_is_mem_equal (start_interface_nonce, 40 | interface_context->start_interface_nonce, 41 | sizeof(interface_context->start_interface_nonce))) { 42 | return PCI_TDISP_ERROR_CODE_INVALID_NONCE; 43 | } 44 | 45 | /* start the interface */ 46 | 47 | interface_context->tdi_state = PCI_TDISP_INTERFACE_STATE_RUN; 48 | 49 | return PCI_TDISP_ERROR_CODE_SUCCESS; 50 | } 51 | -------------------------------------------------------------------------------- /library/pci_ide_km_device_lib_sample/pci_ide_km_device_key_prog.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_ide_km_device_lib.h" 12 | 13 | /** 14 | * Process the IDE_KM request and return the response. 15 | * 16 | * @param request the IDE_KM request message, start from pci_ide_km_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the IDE_KM response message, start from pci_ide_km_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libspdm_return_t pci_ide_km_device_key_prog (const void *pci_doe_context, 25 | const void *spdm_context, const uint32_t *session_id, 26 | uint8_t stream_id, uint8_t key_sub_stream, 27 | uint8_t port_index, 28 | uint8_t *kp_ack_status, 29 | const pci_ide_km_aes_256_gcm_key_buffer_t *key_buffer) 30 | { 31 | libidekm_device_port_context *device_port_context; 32 | uint8_t index; 33 | 34 | device_port_context = libidekm_get_device_port_context (port_index); 35 | if (device_port_context == NULL) { 36 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 37 | } 38 | 39 | index = key_sub_stream & (PCI_IDE_KM_KEY_SET_MASK | PCI_IDE_KM_KEY_DIRECTION_MASK); 40 | 41 | /* program key */ 42 | 43 | libspdm_copy_mem (&device_port_context->key_buffer[index], 44 | sizeof(device_port_context->key_buffer[index]), 45 | key_buffer, 46 | sizeof(pci_ide_km_aes_256_gcm_key_buffer_t) 47 | ); 48 | device_port_context->is_key_prog[index] = true; 49 | 50 | *kp_ack_status = PCI_IDE_KM_KP_ACK_STATUS_SUCCESS; 51 | 52 | return LIBSPDM_STATUS_SUCCESS; 53 | } 54 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_tdisp_device_lib/pci_tdisp_device_start_interface.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | /** 14 | * Process the TDISP request and return the response. 15 | * 16 | * @param request the TDISP request message, start from pci_tdisp_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the TDISP response message, start from pci_tdisp_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libtdisp_error_code_t pci_tdisp_device_start_interface (const void *pci_doe_context, 25 | const void *spdm_context, 26 | const uint32_t *session_id, 27 | const pci_tdisp_interface_id_t *interface_id, 28 | const uint8_t *start_interface_nonce) 29 | { 30 | libtdisp_interface_context *interface_context; 31 | 32 | interface_context = libtdisp_get_interface_context (interface_id); 33 | if (interface_context == NULL) { 34 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE; 35 | } 36 | if (interface_context->tdi_state != PCI_TDISP_INTERFACE_STATE_CONFIG_LOCKED) { 37 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE_STATE; 38 | } 39 | if (libspdm_consttime_is_mem_equal (start_interface_nonce, 40 | interface_context->start_interface_nonce, 41 | sizeof(interface_context->start_interface_nonce))) { 42 | return PCI_TDISP_ERROR_CODE_INVALID_NONCE; 43 | } 44 | 45 | /* start the interface */ 46 | 47 | interface_context->tdi_state = PCI_TDISP_INTERFACE_STATE_RUN; 48 | 49 | return PCI_TDISP_ERROR_CODE_SUCCESS; 50 | } 51 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_ide_km_device_lib/pci_ide_km_device_key_prog.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_ide_km_device_lib.h" 12 | 13 | /** 14 | * Process the IDE_KM request and return the response. 15 | * 16 | * @param request the IDE_KM request message, start from pci_ide_km_header_t. 17 | * @param request_size size in bytes of request. 18 | * @param response the IDE_KM response message, start from pci_ide_km_header_t. 19 | * @param response_size size in bytes of response. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 22 | * @return ERROR The request is not processed. 23 | **/ 24 | libspdm_return_t pci_ide_km_device_key_prog (const void *pci_doe_context, 25 | const void *spdm_context, const uint32_t *session_id, 26 | uint8_t stream_id, uint8_t key_sub_stream, 27 | uint8_t port_index, 28 | uint8_t *kp_ack_status, 29 | const pci_ide_km_aes_256_gcm_key_buffer_t *key_buffer) 30 | { 31 | libidekm_device_port_context *device_port_context; 32 | uint8_t index; 33 | 34 | device_port_context = libidekm_get_device_port_context (port_index); 35 | if (device_port_context == NULL) { 36 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 37 | } 38 | 39 | index = key_sub_stream & (PCI_IDE_KM_KEY_SET_MASK | PCI_IDE_KM_KEY_DIRECTION_MASK); 40 | 41 | /* program key */ 42 | 43 | libspdm_copy_mem (&device_port_context->key_buffer[index], 44 | sizeof(device_port_context->key_buffer[index]), 45 | key_buffer, 46 | sizeof(pci_ide_km_aes_256_gcm_key_buffer_t) 47 | ); 48 | device_port_context->is_key_prog[index] = true; 49 | 50 | *kp_ack_status = PCI_IDE_KM_KP_ACK_STATUS_SUCCESS; 51 | 52 | return LIBSPDM_STATUS_SUCCESS; 53 | } 54 | -------------------------------------------------------------------------------- /library/pci_tdisp_device_lib_sample/pci_tdisp_device_context.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | libtdisp_interface_context g_tdisp_interface_context; 14 | 15 | libtdisp_interface_context *libtdisp_initialize_interface_context ( 16 | const pci_tdisp_interface_id_t *interface_id 17 | ) 18 | { 19 | libspdm_zero_mem ( 20 | &g_tdisp_interface_context, 21 | sizeof(g_tdisp_interface_context) 22 | ); 23 | libspdm_copy_mem ( 24 | &g_tdisp_interface_context.interface_id, 25 | sizeof(g_tdisp_interface_context.interface_id), 26 | interface_id, 27 | sizeof(*interface_id) 28 | ); 29 | g_tdisp_interface_context.supported_tdisp_versions_count = 1; 30 | g_tdisp_interface_context.supported_tdisp_versions[0] = PCI_TDISP_MESSAGE_VERSION_10; 31 | 32 | g_tdisp_interface_context.tdisp_rsp_caps.dsm_caps = 0; 33 | g_tdisp_interface_context.tdisp_rsp_caps.req_msg_supported[0] = 0xFE; 34 | g_tdisp_interface_context.tdisp_rsp_caps.lock_interface_flags_supported = 35 | PCI_TDISP_LOCK_INTERFACE_FLAGS_NO_FW_UPDATE | 36 | PCI_TDISP_LOCK_INTERFACE_FLAGS_SYSTEM_CACHE_LINE_SIZE | 37 | PCI_TDISP_LOCK_INTERFACE_FLAGS_LOCK_MSIX; 38 | g_tdisp_interface_context.tdisp_rsp_caps.dev_addr_width = 48; 39 | g_tdisp_interface_context.tdisp_rsp_caps.num_req_this = 0; 40 | g_tdisp_interface_context.tdisp_rsp_caps.num_req_all = 0; 41 | 42 | g_tdisp_interface_context.tdi_state = PCI_TDISP_INTERFACE_STATE_CONFIG_UNLOCKED; 43 | 44 | return &g_tdisp_interface_context; 45 | } 46 | 47 | libtdisp_interface_context *libtdisp_get_interface_context ( 48 | const pci_tdisp_interface_id_t *interface_id 49 | ) 50 | { 51 | if (libspdm_consttime_is_mem_equal (&g_tdisp_interface_context.interface_id, 52 | interface_id, 53 | sizeof(g_tdisp_interface_context.interface_id))) { 54 | return &g_tdisp_interface_context; 55 | } else { 56 | return NULL; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_tdisp_device_lib/pci_tdisp_device_context.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | libtdisp_interface_context g_tdisp_interface_context; 14 | 15 | libtdisp_interface_context *libtdisp_initialize_interface_context ( 16 | const pci_tdisp_interface_id_t *interface_id 17 | ) 18 | { 19 | libspdm_zero_mem ( 20 | &g_tdisp_interface_context, 21 | sizeof(g_tdisp_interface_context) 22 | ); 23 | libspdm_copy_mem ( 24 | &g_tdisp_interface_context.interface_id, 25 | sizeof(g_tdisp_interface_context.interface_id), 26 | interface_id, 27 | sizeof(*interface_id) 28 | ); 29 | g_tdisp_interface_context.supported_tdisp_versions_count = 1; 30 | g_tdisp_interface_context.supported_tdisp_versions[0] = PCI_TDISP_MESSAGE_VERSION_10; 31 | 32 | g_tdisp_interface_context.tdisp_rsp_caps.dsm_caps = 0; 33 | g_tdisp_interface_context.tdisp_rsp_caps.req_msg_supported[0] = 0xFE; 34 | g_tdisp_interface_context.tdisp_rsp_caps.lock_interface_flags_supported = 35 | PCI_TDISP_LOCK_INTERFACE_FLAGS_NO_FW_UPDATE | 36 | PCI_TDISP_LOCK_INTERFACE_FLAGS_SYSTEM_CACHE_LINE_SIZE | 37 | PCI_TDISP_LOCK_INTERFACE_FLAGS_LOCK_MSIX; 38 | g_tdisp_interface_context.tdisp_rsp_caps.dev_addr_width = 48; 39 | g_tdisp_interface_context.tdisp_rsp_caps.num_req_this = 0; 40 | g_tdisp_interface_context.tdisp_rsp_caps.num_req_all = 0; 41 | 42 | g_tdisp_interface_context.tdi_state = PCI_TDISP_INTERFACE_STATE_CONFIG_UNLOCKED; 43 | 44 | return &g_tdisp_interface_context; 45 | } 46 | 47 | libtdisp_interface_context *libtdisp_get_interface_context ( 48 | const pci_tdisp_interface_id_t *interface_id 49 | ) 50 | { 51 | if (libspdm_consttime_is_mem_equal (&g_tdisp_interface_context.interface_id, 52 | interface_id, 53 | sizeof(g_tdisp_interface_context.interface_id))) { 54 | return &g_tdisp_interface_context; 55 | } else { 56 | return NULL; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /library/pci_tdisp_device_lib_sample/pci_tdisp_device_version.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | #pragma pack(1) 14 | typedef struct { 15 | pci_tdisp_header_t header; 16 | uint8_t version_num_count; 17 | pci_tdisp_version_number_t version_num_entry[1]; 18 | } pci_tdisp_version_response_mine_t; 19 | #pragma pack() 20 | 21 | /** 22 | * Process the TDISP request and return the response. 23 | * 24 | * @param request the TDISP request message, start from pci_tdisp_header_t. 25 | * @param request_size size in bytes of request. 26 | * @param response the TDISP response message, start from pci_tdisp_header_t. 27 | * @param response_size size in bytes of response. 28 | * 29 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 30 | * @return ERROR The request is not processed. 31 | **/ 32 | libtdisp_error_code_t pci_tdisp_device_get_version (const void *pci_doe_context, 33 | const void *spdm_context, 34 | const uint32_t *session_id, 35 | const pci_tdisp_interface_id_t *interface_id, 36 | uint8_t *version_num_count, 37 | pci_tdisp_version_number_t *version_num_entry) 38 | { 39 | libtdisp_interface_context *interface_context; 40 | 41 | interface_context = libtdisp_initialize_interface_context (interface_id); 42 | if (interface_context == NULL) { 43 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE; 44 | } 45 | libspdm_copy_mem (version_num_entry, 46 | sizeof(pci_tdisp_version_number_t) * (*version_num_count), 47 | interface_context->supported_tdisp_versions, 48 | sizeof(pci_tdisp_version_number_t) * 49 | interface_context->supported_tdisp_versions_count); 50 | *version_num_count = interface_context->supported_tdisp_versions_count; 51 | 52 | return PCI_TDISP_ERROR_CODE_SUCCESS; 53 | } 54 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/pci_tdisp_device_lib/pci_tdisp_device_version.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_tdisp_device_lib.h" 12 | 13 | #pragma pack(1) 14 | typedef struct { 15 | pci_tdisp_header_t header; 16 | uint8_t version_num_count; 17 | pci_tdisp_version_number_t version_num_entry[1]; 18 | } pci_tdisp_version_response_mine_t; 19 | #pragma pack() 20 | 21 | /** 22 | * Process the TDISP request and return the response. 23 | * 24 | * @param request the TDISP request message, start from pci_tdisp_header_t. 25 | * @param request_size size in bytes of request. 26 | * @param response the TDISP response message, start from pci_tdisp_header_t. 27 | * @param response_size size in bytes of response. 28 | * 29 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 30 | * @return ERROR The request is not processed. 31 | **/ 32 | libtdisp_error_code_t pci_tdisp_device_get_version (const void *pci_doe_context, 33 | const void *spdm_context, 34 | const uint32_t *session_id, 35 | const pci_tdisp_interface_id_t *interface_id, 36 | uint8_t *version_num_count, 37 | pci_tdisp_version_number_t *version_num_entry) 38 | { 39 | libtdisp_interface_context *interface_context; 40 | 41 | interface_context = libtdisp_initialize_interface_context (interface_id); 42 | if (interface_context == NULL) { 43 | return PCI_TDISP_ERROR_CODE_INVALID_INTERFACE; 44 | } 45 | libspdm_copy_mem (version_num_entry, 46 | sizeof(pci_tdisp_version_number_t) * (*version_num_count), 47 | interface_context->supported_tdisp_versions, 48 | sizeof(pci_tdisp_version_number_t) * 49 | interface_context->supported_tdisp_versions_count); 50 | *version_num_count = interface_context->supported_tdisp_versions_count; 51 | 52 | return PCI_TDISP_ERROR_CODE_SUCCESS; 53 | } 54 | -------------------------------------------------------------------------------- /library/pci_ide_km_responder_lib/pci_ide_km_dispatch.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_ide_km_device_lib.h" 12 | 13 | typedef struct { 14 | uint8_t object_id; 15 | pci_ide_km_get_response_func_t func; 16 | } pci_ide_km_dispatch_struct_t; 17 | 18 | pci_ide_km_dispatch_struct_t m_pci_ide_km_dispatch[] = { 19 | {PCI_IDE_KM_OBJECT_ID_QUERY, pci_ide_km_get_response_query}, 20 | {PCI_IDE_KM_OBJECT_ID_KEY_PROG, pci_ide_km_get_response_key_prog}, 21 | {PCI_IDE_KM_OBJECT_ID_K_SET_GO, pci_ide_km_get_response_key_set_go}, 22 | {PCI_IDE_KM_OBJECT_ID_K_SET_STOP, pci_ide_km_get_response_key_set_stop}, 23 | }; 24 | 25 | /** 26 | * Process the IDE_KM request and return the response. 27 | * 28 | * @param request the IDE_KM request message, start from pci_ide_km_header_t. 29 | * @param request_size size in bytes of request. 30 | * @param response the IDE_KM response message, start from pci_ide_km_header_t. 31 | * @param response_size size in bytes of response. 32 | * 33 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 34 | * @return ERROR The request is not processed. 35 | **/ 36 | libspdm_return_t pci_ide_km_get_response (const void *pci_doe_context, 37 | const void *spdm_context, const uint32_t *session_id, 38 | const void *request, size_t request_size, 39 | void *response, size_t *response_size) 40 | { 41 | const pci_ide_km_header_t *ide_km_request; 42 | size_t index; 43 | 44 | ide_km_request = request; 45 | if (request_size < sizeof(pci_ide_km_header_t)) { 46 | return LIBSPDM_STATUS_INVALID_MSG_SIZE; 47 | } 48 | 49 | for (index = 0; index < LIBSPDM_ARRAY_SIZE(m_pci_ide_km_dispatch); index++) { 50 | if (ide_km_request->object_id == m_pci_ide_km_dispatch[index].object_id) { 51 | return m_pci_ide_km_dispatch[index].func ( 52 | pci_doe_context, spdm_context, session_id, 53 | request, request_size, response, response_size); 54 | } 55 | } 56 | 57 | return LIBSPDM_STATUS_UNSUPPORTED_CAP; 58 | } 59 | -------------------------------------------------------------------------------- /library/mctp_responder_lib/pldm_rsp_control_get_tid.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "hal/library/debuglib.h" 10 | #include "library/spdm_requester_lib.h" 11 | #include "library/spdm_transport_mctp_lib.h" 12 | #include "library/mctp_responder_lib.h" 13 | 14 | /** 15 | * Process the PLDM request and return the response. 16 | * 17 | * @param request the PLDM request message, start from pldm_message_header_t. 18 | * @param request_size size in bytes of request. 19 | * @param response the PLDM response message, start from pldm_message_header_t. 20 | * @param response_size size in bytes of response. 21 | * 22 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 23 | * @return ERROR The request is not processed. 24 | **/ 25 | libspdm_return_t pldm_get_response_control_get_tid (const void *mctp_context, 26 | const void *spdm_context, 27 | const uint32_t *session_id, 28 | const void *request, size_t request_size, 29 | void *response, size_t *response_size) 30 | { 31 | const pldm_get_tid_request_t *app_request; 32 | pldm_get_tid_response_t *app_response; 33 | 34 | app_request = request; 35 | if (request_size != sizeof(pldm_get_tid_request_t)) { 36 | return LIBSPDM_STATUS_INVALID_MSG_SIZE; 37 | } 38 | LIBSPDM_ASSERT (*response_size >= sizeof(pldm_get_tid_response_t)); 39 | *response_size = sizeof(pldm_get_tid_response_t); 40 | 41 | libspdm_zero_mem (response, *response_size); 42 | 43 | app_response = response; 44 | app_response->pldm_header.instance_id = app_request->pldm_header.instance_id & 45 | PLDM_HEADER_INSTANCE_ID_MASK; 46 | app_response->pldm_header.pldm_type = app_request->pldm_header.pldm_type; /* both version and type*/ 47 | app_response->pldm_header.pldm_command_code = app_request->pldm_header.pldm_command_code; 48 | app_response->pldm_response_header.pldm_completion_code = PLDM_BASE_CODE_SUCCESS; 49 | 50 | /* TBD - need PLDM context to get the info*/ 51 | app_response->tid = 1; 52 | 53 | return LIBSPDM_STATUS_SUCCESS; 54 | } 55 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/spdm_device_responder/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 4 | if(ARCH STREQUAL "x64") 5 | set(CMAKE_EXE_LINKER_FLAGS "-nostdlib -flto -Wl,--entry,ModuleEntryPoint") 6 | elseif(ARCH STREQUAL "aarch64") 7 | if(TOOLCHAIN STREQUAL "ARM_DS2022") 8 | set(CMAKE_EXE_LINKER_FLAGS "--target=aarch64-arm-none-eabi -nostdlib -flto -Wl,--entry,ModuleEntryPoint,--undefined=__udivti3") 9 | elseif(TOOLCHAIN STREQUAL "ARM_GNU") 10 | set(CMAKE_EXE_LINKER_FLAGS "-nostdlib -flto -Wl,--entry,ModuleEntryPoint,--undefined=__udivti3") 11 | elseif(TOOLCHAIN STREQUAL "AARCH64_GCC") 12 | set(CMAKE_EXE_LINKER_FLAGS "-nostdlib -flto -Wl,--entry,ModuleEntryPoint") 13 | endif() 14 | endif() 15 | elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") 16 | set(CMAKE_EXE_LINKER_FLAGS "/DLL /ENTRY:ModuleEntryPoint /NOLOGO /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /NODEFAULTLIB /IGNORE:4086 /MAP /OPT:REF") 17 | endif() 18 | 19 | include_directories(${SPDM_DEVICE_DIR}/include 20 | ${SPDM_DEVICE_DIR}/spdm_device_responder 21 | ${LIBSPDM_DIR}/include 22 | ${LIBSPDM_DIR}/os_stub 23 | ${LIBSPDM_DIR}/os_stub/include 24 | ${SPDM_EMU_DIR}/include 25 | ${PROJECT_SOURCE_DIR}/library 26 | ) 27 | 28 | set(src_spdm_device_responder 29 | spdm_responder_init.c 30 | spdm_responder_main.c 31 | compiler_stub.c 32 | support.c 33 | spdm_responder_pci_doe.c 34 | pci.c 35 | ) 36 | 37 | set(spdm_device_responder_LIBRARY 38 | memlib 39 | debuglib 40 | spdm_responder_lib 41 | spdm_common_lib 42 | cryptstublib 43 | ${CRYPTO_LIB_PATHS} 44 | cryptlib_${CRYPTO} 45 | rnglib 46 | malloclib_simple 47 | spdm_crypt_lib 48 | spdm_secured_message_lib 49 | spdm_transport_pcidoe_lib 50 | spdm_device_secret_lib 51 | spdm_crypt_ext_lib 52 | intrinsiclib 53 | platform_lib 54 | pci_doe_responder_lib 55 | pci_ide_km_responder_lib 56 | pci_ide_km_device_lib 57 | pci_tdisp_responder_lib 58 | pci_tdisp_device_lib 59 | ) 60 | 61 | if(TOOLCHAIN STREQUAL "ARM_DS2022" OR TOOLCHAIN STREQUAL "ARM_GNU") 62 | set(spdm_device_responder_LIBRARY ${spdm_device_responder_LIBRARY} armbuild_lib) 63 | endif() 64 | 65 | add_executable(spdm_device_responder ${src_spdm_device_responder}) 66 | target_link_libraries(spdm_device_responder ${spdm_device_responder_LIBRARY}) 67 | 68 | 69 | -------------------------------------------------------------------------------- /library/pci_doe_responder_lib/pci_doe_dispatch.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/pci_doe_responder_lib.h" 12 | 13 | pci_doe_data_object_protocol_t m_data_object_protocol[] = { 14 | {PCI_DOE_VENDOR_ID_PCISIG, PCI_DOE_DATA_OBJECT_TYPE_DOE_DISCOVERY}, 15 | {PCI_DOE_VENDOR_ID_PCISIG, PCI_DOE_DATA_OBJECT_TYPE_SPDM}, 16 | {PCI_DOE_VENDOR_ID_PCISIG, PCI_DOE_DATA_OBJECT_TYPE_SECURED_SPDM}, 17 | }; 18 | 19 | /** 20 | * Process the DOE request and return the response. 21 | * 22 | * @param request the PCI_DOE request message, start from pci_doe_data_object_header_t. 23 | * @param request_size size in bytes of request. 24 | * @param response the PCI_DOE response message, start from pci_doe_data_object_header_t. 25 | * @param response_size size in bytes of response. 26 | * 27 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 28 | * @return ERROR The request is not processed. 29 | **/ 30 | libspdm_return_t pci_doe_get_response_doe_request(const void *pci_doe_context, 31 | const void *request, size_t request_size, 32 | void *response, size_t *response_size) 33 | { 34 | uint8_t index = 0; 35 | uint32_t *reply = response; 36 | libspdm_return_t ret; 37 | 38 | ret = libspdm_pci_doe_decode_discovery_request(request_size, request, &index); 39 | 40 | if (ret != LIBSPDM_STATUS_SUCCESS) { 41 | return ret; 42 | } 43 | 44 | if (index >= LIBSPDM_ARRAY_SIZE(m_data_object_protocol)) { 45 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 46 | } else if (index == LIBSPDM_ARRAY_SIZE(m_data_object_protocol) - 1) { 47 | reply[2] = m_data_object_protocol[index].data_object_type << 16 | 48 | m_data_object_protocol[index].vendor_id; 49 | } else { 50 | reply[2] = (index + 1) << 24 | 51 | m_data_object_protocol[index].data_object_type << 16 | 52 | m_data_object_protocol[index].vendor_id; 53 | } 54 | 55 | return libspdm_pci_doe_encode_discovery( 56 | sizeof(uint32_t), 57 | &reply[2], 58 | response_size, 59 | &response 60 | ); 61 | } 62 | -------------------------------------------------------------------------------- /library/cxl_tsp_requester_lib/cxl_tsp_req_lock_configuration.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_tsp_requester_lib.h" 12 | 13 | /** 14 | * Send and receive an TSP message 15 | * 16 | * @param spdm_context A pointer to the SPDM context. 17 | * @param session_id Indicates if it is a secured message protected via SPDM session. 18 | * If session_id is NULL, it is a normal message. 19 | * If session_id is NOT NULL, it is a secured message. 20 | * 21 | * @retval LIBSPDM_STATUS_SUCCESS The TSP request is sent and response is received. 22 | * @return ERROR The TSP response is not received correctly. 23 | **/ 24 | libspdm_return_t cxl_tsp_lock_configuration( 25 | const void *pci_doe_context, 26 | void *spdm_context, const uint32_t *session_id) 27 | { 28 | libspdm_return_t status; 29 | cxl_tsp_lock_target_configuration_req_t request; 30 | size_t request_size; 31 | uint8_t res_buf[LIBCXLTSP_ERROR_MESSAGE_MAX_SIZE]; 32 | cxl_tsp_lock_target_configuration_rsp_t *response; 33 | size_t response_size; 34 | 35 | libspdm_zero_mem (&request, sizeof(request)); 36 | request.header.tsp_version = CXL_TSP_MESSAGE_VERSION_10; 37 | request.header.op_code = CXL_TSP_OPCODE_LOCK_TARGET_CONFIGURATION; 38 | 39 | request_size = sizeof(request); 40 | response = (void *)res_buf; 41 | response_size = sizeof(res_buf); 42 | status = cxl_tsp_send_receive_data(spdm_context, session_id, 43 | &request, request_size, 44 | response, &response_size); 45 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 46 | return status; 47 | } 48 | 49 | if (response_size != sizeof(cxl_tsp_lock_target_configuration_rsp_t)) { 50 | return LIBSPDM_STATUS_INVALID_MSG_SIZE; 51 | } 52 | if (response->header.tsp_version != request.header.tsp_version) { 53 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 54 | } 55 | if (response->header.op_code != CXL_TSP_OPCODE_LOCK_TARGET_CONFIGURATION_RSP) { 56 | return LIBSPDM_STATUS_INVALID_MSG_FIELD; 57 | } 58 | 59 | return LIBSPDM_STATUS_SUCCESS; 60 | } 61 | -------------------------------------------------------------------------------- /library/cxl_ide_km_responder_lib/cxl_ide_km_dispatch.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_ide_km_device_lib.h" 12 | 13 | typedef struct { 14 | uint8_t object_id; 15 | cxl_ide_km_get_response_func_t func; 16 | } cxl_ide_km_dispatch_struct_t; 17 | 18 | cxl_ide_km_dispatch_struct_t m_cxl_ide_km_dispatch[] = { 19 | {CXL_IDE_KM_OBJECT_ID_QUERY, cxl_ide_km_get_response_query}, 20 | {CXL_IDE_KM_OBJECT_ID_KEY_PROG, cxl_ide_km_get_response_key_prog}, 21 | {CXL_IDE_KM_OBJECT_ID_K_SET_GO, cxl_ide_km_get_response_key_set_go}, 22 | {CXL_IDE_KM_OBJECT_ID_K_SET_STOP, cxl_ide_km_get_response_key_set_stop}, 23 | {CXL_IDE_KM_OBJECT_ID_GET_KEY, cxl_ide_km_get_response_get_key}, 24 | }; 25 | 26 | /** 27 | * Process the IDE_KM request and return the response. 28 | * 29 | * @param request the IDE_KM request message, start from cxl_ide_km_header_t. 30 | * @param request_size size in bytes of request. 31 | * @param response the IDE_KM response message, start from cxl_ide_km_header_t. 32 | * @param response_size size in bytes of response. 33 | * 34 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 35 | * @return ERROR The request is not processed. 36 | **/ 37 | libspdm_return_t cxl_ide_km_get_response (const void *pci_doe_context, 38 | const void *spdm_context, const uint32_t *session_id, 39 | const void *request, size_t request_size, 40 | void *response, size_t *response_size) 41 | { 42 | const cxl_ide_km_header_t *ide_km_request; 43 | size_t index; 44 | 45 | ide_km_request = request; 46 | if (request_size < sizeof(cxl_ide_km_header_t)) { 47 | return LIBSPDM_STATUS_INVALID_MSG_SIZE; 48 | } 49 | 50 | for (index = 0; index < LIBSPDM_ARRAY_SIZE(m_cxl_ide_km_dispatch); index++) { 51 | if (ide_km_request->object_id == m_cxl_ide_km_dispatch[index].object_id) { 52 | return m_cxl_ide_km_dispatch[index].func ( 53 | pci_doe_context, spdm_context, session_id, 54 | request, request_size, response, response_size); 55 | } 56 | } 57 | 58 | return LIBSPDM_STATUS_UNSUPPORTED_CAP; 59 | } 60 | -------------------------------------------------------------------------------- /library/cxl_tsp_device_lib_sample/cxl_tsp_device_get_configuration_report.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2024 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_tsp_device_lib.h" 12 | 13 | #pragma pack(1) 14 | typedef struct { 15 | uint8_t valid_tsp_report_fields; 16 | uint8_t reserved[3]; 17 | uint8_t pcie_dvsec_for_cxl_devices[0x3c]; 18 | uint8_t pcie_dvsec_for_flex_bus_port[0x20]; 19 | uint8_t cxl_link_capability_structure[0x38]; 20 | uint8_t cxl_timeout_and_isolation_capability_structure[0x10]; 21 | uint8_t cxl_hdm_decoder_capability_structure[0x10]; 22 | /* uint8_t cxl_hdm_decoder[0x1f][decoder_count]; */ 23 | uint8_t cxl_ide_capability_structure[0x24]; 24 | } cxl_tsp_target_configuration_report_mine_t; 25 | #pragma pack() 26 | 27 | /** 28 | * Process the TSP request and return the response. 29 | * 30 | * @param request the TSP request message, start from cxl_tsp_header_t. 31 | * @param request_size size in bytes of request. 32 | * @param response the TSP response message, start from cxl_tsp_header_t. 33 | * @param response_size size in bytes of response. 34 | * 35 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 36 | * @return ERROR The request is not processed. 37 | **/ 38 | libcxltsp_error_code_t cxl_tsp_device_get_configuration_report ( 39 | const void *pci_doe_context, 40 | const void *spdm_context, const uint32_t *session_id, 41 | uint8_t **configuration_report, uint16_t *configuration_report_size) 42 | { 43 | libcxltsp_device_context *device_context; 44 | cxl_tsp_target_configuration_report_mine_t *report; 45 | 46 | device_context = libcxltsp_get_device_context (pci_doe_context); 47 | if (device_context == NULL) { 48 | return CXL_TSP_ERROR_CODE_UNSPECIFIED; 49 | } 50 | 51 | report = (cxl_tsp_target_configuration_report_mine_t *)device_context->configuration_report; 52 | // TBD: fill hardware data 53 | report->valid_tsp_report_fields = 1; 54 | device_context->configuration_report_size = sizeof(cxl_tsp_target_configuration_report_mine_t); 55 | 56 | *configuration_report_size = device_context->configuration_report_size; 57 | *configuration_report = device_context->configuration_report; 58 | 59 | return CXL_TSP_ERROR_CODE_SUCCESS; 60 | } 61 | -------------------------------------------------------------------------------- /.github/workflows/pqc_check.yml: -------------------------------------------------------------------------------- 1 | name: PQC 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | workflow_dispatch: 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} 12 | cancel-in-progress: true 13 | 14 | env: 15 | BUILD_TYPE: Release 16 | 17 | jobs: 18 | gcc_openssl_build: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v6 22 | with: 23 | submodules: recursive 24 | 25 | - name: Build 26 | run: | 27 | mkdir build 28 | cd build 29 | cmake -E env CFLAGS="-DLIBSPDM_DEBUG_LIBSPDM_ASSERT_CONFIG=3" cmake -DARCH=x64 -DTOOLCHAIN=GCC -DTARGET=Release -DCRYPTO=openssl .. 30 | make copy_sample_key 31 | make -j`nproc` 32 | - name: Enable_PQC 33 | run: | 34 | cd build/bin 35 | 36 | test_port=2323 37 | TCPListeningnum=`netstat -an | grep ":$test_port " | awk '/^tcp.*/ && $NF == "LISTEN" {print $0}' | wc -l` 38 | UDPListeningnum=`netstat -an | grep ":$test_port " | awk '/^udp.*/ && $NF == "0.0.0.0:*" {print $0}' | wc -l` 39 | Listeningnum=$((TCPListeningnum + UDPListeningnum)) 40 | if [ $Listeningnum -eq 0 ]; then 41 | echo "port is not used" 42 | else 43 | echo "port is used" 44 | fi 45 | ./spdm_responder_emu --pqc_first TRUE & 46 | sleep 5s 47 | ./spdm_requester_emu >requester.log 48 | 49 | VS2019_openssl_build: 50 | runs-on: windows-latest 51 | 52 | steps: 53 | - uses: actions/checkout@v6 54 | with: 55 | submodules: recursive 56 | #ilammy/msvc-dev-cmd@v1 is GitHub Action for configuring Developer Command Prompt for Microsoft Visual Studio on Windows. 57 | #This sets up the environment for compiling C/C++ code from command line. 58 | - name: Add msbuild to PATH 59 | uses: ilammy/msvc-dev-cmd@v1 60 | with: 61 | arch: x64 62 | 63 | - name: Build 64 | run: | 65 | mkdir build 66 | cd build 67 | cmake -E env CFLAGS="-DLIBSPDM_DEBUG_LIBSPDM_ASSERT_CONFIG=3" cmake -G"NMake Makefiles" -DARCH=x64 -DTOOLCHAIN=VS2019 -DTARGET=Release -DCRYPTO=openssl .. 68 | nmake copy_sample_key 69 | nmake 70 | - name: Enable_PQC 71 | run: | 72 | cd build/bin 73 | ./spdm_responder_emu --pqc_first TRUE & 74 | sleep 5s 75 | ./spdm_requester_emu 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This spdm-emu is a sample SPDM emulator implementation using [libspdm](https://github.com/DMTF/libspdm) 2 | 3 | ## Feature 4 | 5 | 1) An SPDM requester emulator and a SPDM responder emulator that can run in OS environment. 6 | 7 | ## Document 8 | 9 | 1) User guide 10 | 11 | The user guide can be found at [user_guide](https://github.com/DMTF/spdm-emu/blob/main/doc/spdm_emu.md) 12 | 13 | ## Prerequisit 14 | 15 | ### Build Tool 16 | 17 | 1) [Visual Studio](https://visualstudio.microsoft.com/) (VS2015 or VS2019 or VS2022) 18 | 19 | 2) [GCC](https://gcc.gnu.org/) (above GCC5) 20 | 21 | 3) [LLVM](https://llvm.org/) (LLVM9) 22 | 23 | Download and install [LLVM9](http://releases.llvm.org/download.html#9.0.0). Ensure LLVM9 executable directory is in PATH environment variable. 24 | 25 | ## Build 26 | 27 | ### Git Submodule 28 | 29 | spdm_emu uses submodules for libspdm. 30 | 31 | To get a full buildable repo, please use `git submodule update --init --recursive`. 32 | If there is an update for submodules, please use `git submodule update`. 33 | 34 | ### Windows Build with CMake 35 | 36 | Use x86 command prompt for ARCH=ia32 and x64 command prompt for ARCH=x64. (TOOLCHAIN=VS2022|VS2019|VS2015|CLANG) 37 | ``` 38 | cd spdm-emu 39 | mkdir build 40 | cd build 41 | cmake -G"NMake Makefiles" -DARCH= -DTOOLCHAIN= -DTARGET= -DCRYPTO= .. 42 | nmake copy_sample_key 43 | nmake 44 | ``` 45 | 46 | ### Linux Build with CMake 47 | 48 | (TOOLCHAIN=GCC|CLANG) 49 | ``` 50 | cd spdm-emu 51 | mkdir build 52 | cd build 53 | cmake -DARCH= -DTOOLCHAIN= -DTARGET= -DCRYPTO= .. 54 | make copy_sample_key 55 | make 56 | ``` 57 | 58 | ## Run Test 59 | 60 | ### Run spdm_emu 61 | 62 | The spdm_emu output is at spdm-emu/build/bin. 63 | Open one command prompt at output dir to run `spdm_responder_emu` and another command prompt to run `spdm_requester_emu`. 64 | 65 | Please refer to [spdm_emu](https://github.com/DMTF/spdm-emu/blob/main/doc/spdm_emu.md) for detail. 66 | 67 | ## Feature not implemented yet 68 | 69 | 1) Please refer to [issues](https://github.com/DMTF/spdm-emu/issues) for detail 70 | 71 | ## Known limitation 72 | This package is only the sample code to show the concept. 73 | It does not have a full validation such as robustness functional test and fuzzing test. It does not meet the production quality yet. 74 | Any codes including the API definition, the libary and the drivers are subject to change. 75 | 76 | -------------------------------------------------------------------------------- /library/cxl_tsp_responder_lib/cxl_tsp_dispatch.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_tsp_device_lib.h" 12 | 13 | typedef struct { 14 | uint8_t op_code; 15 | cxl_tsp_get_response_func_t func; 16 | } cxl_tsp_dispatch_struct_t; 17 | 18 | cxl_tsp_dispatch_struct_t m_cxl_tsp_dispatch[] = { 19 | {CXL_TSP_OPCODE_GET_TARGET_TSP_VERSION, cxl_tsp_get_response_get_version}, 20 | {CXL_TSP_OPCODE_GET_TARGET_CAPABILITIES, cxl_tsp_get_response_get_capabilities}, 21 | {CXL_TSP_OPCODE_SET_TARGET_CONFIGURATION, cxl_tsp_get_response_set_configuration}, 22 | {CXL_TSP_OPCODE_GET_TARGET_CONFIGURATION, cxl_tsp_get_response_get_configuration}, 23 | {CXL_TSP_OPCODE_GET_TARGET_CONFIGURATION_REPORT, cxl_tsp_get_response_get_configuration_report}, 24 | {CXL_TSP_OPCODE_LOCK_TARGET_CONFIGURATION, cxl_tsp_get_response_lock_configuration}, 25 | {CXL_TSP_OPCODE_SET_TARGET_TE_STATE, cxl_tsp_get_response_set_te_state}, 26 | }; 27 | 28 | /** 29 | * Process the TSP request and return the response. 30 | * 31 | * @param request the TSP request message, start from cxl_tsp_header_t. 32 | * @param request_size size in bytes of request. 33 | * @param response the TSP response message, start from cxl_tsp_header_t. 34 | * @param response_size size in bytes of response. 35 | * 36 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 37 | * @return ERROR The request is not processed. 38 | **/ 39 | libspdm_return_t cxl_tsp_get_response ( 40 | const void *pci_doe_context, 41 | const void *spdm_context, const uint32_t *session_id, 42 | const void *request, size_t request_size, 43 | void *response, size_t *response_size) 44 | { 45 | const cxl_tsp_header_t *tsp_request; 46 | size_t index; 47 | 48 | tsp_request = request; 49 | if (request_size < sizeof(cxl_tsp_header_t)) { 50 | return LIBSPDM_STATUS_INVALID_MSG_SIZE; 51 | } 52 | 53 | for (index = 0; index < LIBSPDM_ARRAY_SIZE(m_cxl_tsp_dispatch); index++) { 54 | if (tsp_request->op_code == m_cxl_tsp_dispatch[index].op_code) { 55 | return m_cxl_tsp_dispatch[index].func ( 56 | pci_doe_context, spdm_context, session_id, 57 | request, request_size, response, response_size); 58 | } 59 | } 60 | 61 | return LIBSPDM_STATUS_UNSUPPORTED_CAP; 62 | } 63 | -------------------------------------------------------------------------------- /spdm_emu/spdm_requester_emu/spdm_requester_tcp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2023 - 2005 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "spdm_requester_emu.h" 8 | 9 | SOCKET CreateSocketAndRoleInquiry(SOCKET *sock, uint16_t port_number) { 10 | bool result; 11 | struct sockaddr_in peer_address; 12 | uint32_t length; 13 | char buffer[INET_ADDRSTRLEN]; 14 | uint8_t role_inquiry_buf[sizeof(spdm_tcp_binding_header_t)]; 15 | size_t role_inquiry_size = sizeof(role_inquiry_buf); 16 | SOCKET requester_socket, incoming_socket; 17 | 18 | result = create_socket(port_number, &requester_socket); 19 | if (!result) { 20 | printf("Create platform service socket failed\n"); 21 | #ifdef _MSC_VER 22 | WSACleanup(); 23 | #endif 24 | return INVALID_SOCKET; 25 | } 26 | 27 | printf("Platform server listening on port %d\n", port_number); 28 | length = sizeof(peer_address); 29 | incoming_socket = accept(requester_socket, (struct sockaddr *)&peer_address, 30 | (socklen_t *)&length); 31 | if (incoming_socket == INVALID_SOCKET) { 32 | closesocket(requester_socket); 33 | printf("Accept error. Error: 0x%x\n", 34 | #ifdef _MSC_VER 35 | WSAGetLastError() 36 | #else 37 | errno 38 | #endif 39 | ); 40 | #ifdef _MSC_VER 41 | WSACleanup(); 42 | #endif 43 | return INVALID_SOCKET; 44 | } 45 | 46 | inet_ntop(AF_INET, &peer_address.sin_addr, buffer, sizeof(buffer)); 47 | printf("Connected to peer at: %s\n", buffer); 48 | 49 | libspdm_zero_mem(role_inquiry_buf, sizeof(role_inquiry_buf)); 50 | result = read_bytes(incoming_socket, role_inquiry_buf, sizeof(role_inquiry_buf)); 51 | if (!result) { 52 | closesocket(requester_socket); 53 | closesocket(incoming_socket); 54 | printf("Failed to read Role-Inquiry data\n"); 55 | #ifdef _MSC_VER 56 | WSACleanup(); 57 | #endif 58 | return INVALID_SOCKET; 59 | } 60 | 61 | uint8_t message_type = 0; 62 | libspdm_return_t status = libspdm_tcp_decode_discovery_message( 63 | role_inquiry_size, role_inquiry_buf, &message_type 64 | ); 65 | 66 | if (status != LIBSPDM_STATUS_SUCCESS || message_type != SPDM_TCP_MESSAGE_TYPE_ROLE_INQUIRY) { 67 | closesocket(requester_socket); 68 | closesocket(incoming_socket); 69 | printf("Invalid or unexpected Role-Inquiry message. Status: 0x%x\n", status); 70 | #ifdef _MSC_VER 71 | WSACleanup(); 72 | #endif 73 | return INVALID_SOCKET; 74 | } 75 | 76 | *sock = requester_socket; 77 | return incoming_socket; 78 | } 79 | -------------------------------------------------------------------------------- /library/cxl_tsp_device_lib_sample/cxl_tsp_device_set_configuration.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2024 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "library/spdm_requester_lib.h" 10 | #include "library/spdm_transport_pcidoe_lib.h" 11 | #include "library/cxl_tsp_device_lib.h" 12 | 13 | extern uint8_t m_cxl_tsp_2nd_session_psk[CXL_TSP_2ND_SESSION_COUNT][CXL_TSP_2ND_SESSION_KEY_SIZE]; 14 | 15 | /** 16 | * Process the TSP request and return the response. 17 | * 18 | * @param request the TSP request message, start from cxl_tsp_header_t. 19 | * @param request_size size in bytes of request. 20 | * @param response the TSP response message, start from cxl_tsp_header_t. 21 | * @param response_size size in bytes of response. 22 | * 23 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 24 | * @return ERROR The request is not processed. 25 | **/ 26 | libcxltsp_error_code_t cxl_tsp_device_set_configuration ( 27 | const void *pci_doe_context, 28 | const void *spdm_context, const uint32_t *session_id, 29 | const libcxltsp_device_configuration_t *device_configuration, 30 | const libcxltsp_device_2nd_session_info_t *device_2nd_session_info) 31 | { 32 | libcxltsp_device_context *device_context; 33 | size_t index; 34 | 35 | device_context = libcxltsp_get_device_context (pci_doe_context); 36 | if (device_context == NULL) { 37 | return CXL_TSP_ERROR_CODE_UNSPECIFIED; 38 | } 39 | libspdm_copy_mem (&device_context->device_configuration, 40 | sizeof(libcxltsp_device_configuration_t), 41 | device_configuration, 42 | sizeof(libcxltsp_device_configuration_t)); 43 | libspdm_copy_mem (&device_context->device_2nd_session_info, 44 | sizeof(libcxltsp_device_2nd_session_info_t), 45 | device_2nd_session_info, 46 | sizeof(libcxltsp_device_2nd_session_info_t)); 47 | 48 | for (index = 0; index < CXL_TSP_2ND_SESSION_COUNT; index++) { 49 | if ((device_context->device_2nd_session_info.configuration_validity_flags & (0x1 << index)) != 0) { 50 | libspdm_copy_mem( 51 | m_cxl_tsp_2nd_session_psk[index], 52 | sizeof(m_cxl_tsp_2nd_session_psk[index]), 53 | &device_context->device_2nd_session_info.secondary_session_psk_key_material[index], 54 | sizeof(device_context->device_2nd_session_info.secondary_session_psk_key_material[index])); 55 | } 56 | } 57 | return CXL_TSP_ERROR_CODE_SUCCESS; 58 | } 59 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/spdm_device_secret_lib/read_pub_cert.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | /** @file 8 | * SPDM common library. 9 | * It follows the SPDM Specification. 10 | **/ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | #include "library/memlib.h" 23 | #include "spdm_device_secret_lib_internal.h" 24 | 25 | #if LIBSPDM_ECDSA_SUPPORT 26 | #include "bin/ecp384_bundle_responder_certchain.c" 27 | #endif 28 | 29 | #include "bin/ecp384_root_ca.c" 30 | 31 | bool libspdm_read_responder_public_certificate_chain( 32 | uint32_t base_hash_algo, uint32_t base_asym_algo, void **data, 33 | size_t *size, void **hash, size_t *hash_size) 34 | { 35 | bool res; 36 | spdm_cert_chain_t *cert_chain; 37 | size_t cert_chain_size; 38 | const uint8_t *root_cert; 39 | size_t root_cert_len; 40 | size_t digest_size; 41 | 42 | *data = NULL; 43 | *size = 0; 44 | if (hash != NULL) { 45 | *hash = NULL; 46 | } 47 | if (hash_size != NULL) { 48 | *hash_size = 0; 49 | } 50 | 51 | if (base_asym_algo == 0) { 52 | return false; 53 | } 54 | 55 | digest_size = libspdm_get_hash_size(base_hash_algo); 56 | #if LIBSPDM_SHA384_SUPPORT 57 | LIBSPDM_ASSERT(digest_size == LIBSPDM_SHA384_DIGEST_SIZE); 58 | #endif 59 | 60 | switch (base_asym_algo) { 61 | #if LIBSPDM_ECDSA_SUPPORT 62 | case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384: 63 | cert_chain = (void *)m_libspdm_ecp384_bundle_responder_certchain; 64 | cert_chain_size = sizeof(m_libspdm_ecp384_bundle_responder_certchain); 65 | break; 66 | #endif 67 | default: 68 | LIBSPDM_ASSERT(false); 69 | return false; 70 | } 71 | 72 | /* patch */ 73 | cert_chain->length = (uint32_t)cert_chain_size; 74 | 75 | /* Get Root Certificate and calculate hash value*/ 76 | 77 | root_cert = m_libspdm_ec384_responder_root_ca; 78 | root_cert_len = sizeof(m_libspdm_ec384_responder_root_ca); 79 | 80 | res = libspdm_hash_all(base_hash_algo, root_cert, root_cert_len, 81 | (uint8_t *)(cert_chain + 1)); 82 | if (!res) { 83 | return res; 84 | } 85 | *data = cert_chain; 86 | *size = cert_chain_size; 87 | if (hash != NULL) { 88 | *hash = (cert_chain + 1); 89 | } 90 | if (hash_size != NULL) { 91 | *hash_size = digest_size; 92 | } 93 | 94 | return true; 95 | } 96 | -------------------------------------------------------------------------------- /include/library/pci_ide_km_common_lib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #ifndef __PCI_IDE_KM_COMMON_LIB_H__ 8 | #define __PCI_IDE_KM_COMMON_LIB_H__ 9 | 10 | #include "industry_standard/pci_idekm.h" 11 | 12 | /* 13 | * +---------------------------------+ 14 | * | IDE Capability | 15 | * +---------------------------------+ 16 | * | IDE Control | 17 | * +---------------------------------+ ------ 18 | * | Link IDE Stream Control | | 19 | * +---------------------------------+ > PCI_IDE_KM_LINK_IDE_REG_BLOCK_MAX_COUNT 20 | * | Link IDE Stream Status | | 21 | * +---------------------------------+ ------ 22 | * | Selective IDE Stream Capability | | 23 | * +---------------------------------+ | 24 | * | Selective IDE Stream Control | | 25 | * +---------------------------------+ | 26 | * | Selective IDE Stream Status | | 27 | * +---------------------------------+ | 28 | * | IDE RID Association Reg 1 | | 29 | * +---------------------------------+ > PCI_IDE_KM_SELECTIVE_IDE_REG_BLOCK_MAX_COUNT 30 | * | IDE RID Association Reg 2 | | 31 | * +---------------------------------+ -- | 32 | * | IDE Address Association Reg 1 | | | 33 | * +---------------------------------+ | | 34 | * | IDE Address Association Reg 2 | > PCI_IDE_KM_SELECTIVE_IDE_ADDRESS_ASSOCIATION_REG_BLOCK_MAX_COUNT 35 | * +---------------------------------+ | | 36 | * | IDE Address Association Reg 3 | | | 37 | * +---------------------------------+ ------ 38 | */ 39 | 40 | /* (2 + 2 * 8 + (3 + 2 + 3 * 15) * 255) = 12768 */ 41 | #define PCI_IDE_KM_IDE_REG_BLOCK_MAX_COUNT \ 42 | (2 + \ 43 | 2 * PCI_IDE_KM_LINK_IDE_REG_BLOCK_MAX_COUNT + \ 44 | (3 + 2 + 3 * PCI_IDE_KM_SELECTIVE_IDE_ADDRESS_ASSOCIATION_REG_BLOCK_MAX_COUNT) * \ 45 | PCI_IDE_KM_SELECTIVE_IDE_REG_BLOCK_MAX_COUNT) 46 | 47 | 48 | 49 | #define PCI_IDE_KM_LINK_IDE_REG_BLOCK_SUPPORTED_COUNT 4 50 | #define PCI_IDE_KM_SELECTIVE_IDE_REG_BLOCK_SUPPORTED_COUNT 8 51 | #define PCI_IDE_KM_SELECTIVE_IDE_ADDRESS_ASSOCIATION_REG_BLOCK_SUPPORTED_COUNT 1 52 | 53 | /* (2 + 2 * 4 + (3 + 2 + 3 * 1) * 8) = 74 */ 54 | #define PCI_IDE_KM_IDE_REG_BLOCK_SUPPORTED_COUNT \ 55 | (2 + \ 56 | 2 * PCI_IDE_KM_LINK_IDE_REG_BLOCK_SUPPORTED_COUNT + \ 57 | (3 + 2 + 3 * PCI_IDE_KM_SELECTIVE_IDE_ADDRESS_ASSOCIATION_REG_BLOCK_SUPPORTED_COUNT) * \ 58 | PCI_IDE_KM_SELECTIVE_IDE_REG_BLOCK_SUPPORTED_COUNT) 59 | 60 | typedef struct { 61 | uint32_t key[8]; 62 | uint32_t iv[2]; 63 | } pci_ide_km_aes_256_gcm_key_buffer_t; 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /library/cxl_ide_km_responder_lib/cxl_ide_km_rsp_key_set_go.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "hal/library/debuglib.h" 10 | #include "library/spdm_requester_lib.h" 11 | #include "library/spdm_transport_pcidoe_lib.h" 12 | #include "library/cxl_ide_km_device_lib.h" 13 | 14 | /** 15 | * Process the IDE_KM request and return the response. 16 | * 17 | * @param request the IDE_KM request message, start from cxl_ide_km_header_t. 18 | * @param request_size size in bytes of request. 19 | * @param response the IDE_KM response message, start from cxl_ide_km_header_t. 20 | * @param response_size size in bytes of response. 21 | * 22 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 23 | * @return ERROR The request is not processed. 24 | **/ 25 | libspdm_return_t cxl_ide_km_get_response_key_set_go (const void *pci_doe_context, 26 | const void *spdm_context, 27 | const uint32_t *session_id, 28 | const void *request, size_t request_size, 29 | void *response, size_t *response_size) 30 | { 31 | const cxl_ide_km_k_set_go_t *ide_km_request; 32 | cxl_ide_km_k_gostop_ack_t *ide_km_response; 33 | libspdm_return_t status; 34 | 35 | ide_km_request = request; 36 | ide_km_response = response; 37 | if (request_size != sizeof(cxl_ide_km_k_set_go_t)) { 38 | return LIBSPDM_STATUS_INVALID_MSG_SIZE; 39 | } 40 | LIBSPDM_ASSERT (*response_size >= sizeof(cxl_ide_km_k_gostop_ack_t)); 41 | *response_size = sizeof(cxl_ide_km_k_gostop_ack_t); 42 | 43 | libspdm_zero_mem (response, *response_size); 44 | ide_km_response->header.object_id = CXL_IDE_KM_OBJECT_ID_K_SET_GOSTOP_ACK; 45 | 46 | ide_km_response->stream_id = ide_km_request->stream_id; 47 | ide_km_response->key_sub_stream = ide_km_request->key_sub_stream; 48 | ide_km_response->port_index = ide_km_request->port_index; 49 | 50 | status = cxl_ide_km_device_key_set_go (pci_doe_context, spdm_context, session_id, 51 | ide_km_request->stream_id, 52 | ide_km_request->key_sub_stream, 53 | ide_km_request->port_index 54 | ); 55 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 56 | return status; 57 | } 58 | 59 | return LIBSPDM_STATUS_SUCCESS; 60 | } 61 | -------------------------------------------------------------------------------- /library/pci_ide_km_responder_lib/pci_ide_km_rsp_key_set_go.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "hal/library/debuglib.h" 10 | #include "library/spdm_requester_lib.h" 11 | #include "library/spdm_transport_pcidoe_lib.h" 12 | #include "library/pci_ide_km_device_lib.h" 13 | 14 | /** 15 | * Process the IDE_KM request and return the response. 16 | * 17 | * @param request the IDE_KM request message, start from pci_ide_km_header_t. 18 | * @param request_size size in bytes of request. 19 | * @param response the IDE_KM response message, start from pci_ide_km_header_t. 20 | * @param response_size size in bytes of response. 21 | * 22 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 23 | * @return ERROR The request is not processed. 24 | **/ 25 | libspdm_return_t pci_ide_km_get_response_key_set_go (const void *pci_doe_context, 26 | const void *spdm_context, 27 | const uint32_t *session_id, 28 | const void *request, size_t request_size, 29 | void *response, size_t *response_size) 30 | { 31 | const pci_ide_km_k_set_go_t *ide_km_request; 32 | pci_ide_km_k_gostop_ack_t *ide_km_response; 33 | libspdm_return_t status; 34 | 35 | ide_km_request = request; 36 | ide_km_response = response; 37 | if (request_size != sizeof(pci_ide_km_k_set_go_t)) { 38 | return LIBSPDM_STATUS_INVALID_MSG_SIZE; 39 | } 40 | LIBSPDM_ASSERT (*response_size >= sizeof(pci_ide_km_k_gostop_ack_t)); 41 | *response_size = sizeof(pci_ide_km_k_gostop_ack_t); 42 | 43 | libspdm_zero_mem (response, *response_size); 44 | ide_km_response->header.object_id = PCI_IDE_KM_OBJECT_ID_K_SET_GOSTOP_ACK; 45 | 46 | ide_km_response->stream_id = ide_km_request->stream_id; 47 | ide_km_response->key_sub_stream = ide_km_request->key_sub_stream; 48 | ide_km_response->port_index = ide_km_request->port_index; 49 | 50 | status = pci_ide_km_device_key_set_go (pci_doe_context, spdm_context, session_id, 51 | ide_km_request->stream_id, 52 | ide_km_request->key_sub_stream, 53 | ide_km_request->port_index 54 | ); 55 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 56 | return status; 57 | } 58 | 59 | return LIBSPDM_STATUS_SUCCESS; 60 | } 61 | -------------------------------------------------------------------------------- /library/cxl_ide_km_responder_lib/cxl_ide_km_rsp_key_set_stop.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "hal/library/debuglib.h" 10 | #include "library/spdm_requester_lib.h" 11 | #include "library/spdm_transport_pcidoe_lib.h" 12 | #include "library/cxl_ide_km_device_lib.h" 13 | 14 | /** 15 | * Process the IDE_KM request and return the response. 16 | * 17 | * @param request the IDE_KM request message, start from cxl_ide_km_header_t. 18 | * @param request_size size in bytes of request. 19 | * @param response the IDE_KM response message, start from cxl_ide_km_header_t. 20 | * @param response_size size in bytes of response. 21 | * 22 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 23 | * @return ERROR The request is not processed. 24 | **/ 25 | libspdm_return_t cxl_ide_km_get_response_key_set_stop (const void *pci_doe_context, 26 | const void *spdm_context, 27 | const uint32_t *session_id, 28 | const void *request, size_t request_size, 29 | void *response, size_t *response_size) 30 | { 31 | const cxl_ide_km_k_set_stop_t *ide_km_request; 32 | cxl_ide_km_k_gostop_ack_t *ide_km_response; 33 | libspdm_return_t status; 34 | 35 | ide_km_request = request; 36 | ide_km_response = response; 37 | if (request_size != sizeof(cxl_ide_km_k_set_stop_t)) { 38 | return LIBSPDM_STATUS_INVALID_MSG_SIZE; 39 | } 40 | LIBSPDM_ASSERT (*response_size >= sizeof(cxl_ide_km_k_gostop_ack_t)); 41 | *response_size = sizeof(cxl_ide_km_k_gostop_ack_t); 42 | 43 | libspdm_zero_mem (response, *response_size); 44 | ide_km_response->header.object_id = CXL_IDE_KM_OBJECT_ID_K_SET_GOSTOP_ACK; 45 | 46 | ide_km_response->stream_id = ide_km_request->stream_id; 47 | ide_km_response->key_sub_stream = ide_km_request->key_sub_stream; 48 | ide_km_response->port_index = ide_km_request->port_index; 49 | 50 | status = cxl_ide_km_device_key_set_stop (pci_doe_context, spdm_context, session_id, 51 | ide_km_request->stream_id, 52 | ide_km_request->key_sub_stream, 53 | ide_km_request->port_index 54 | ); 55 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 56 | return status; 57 | } 58 | 59 | return LIBSPDM_STATUS_SUCCESS; 60 | } 61 | -------------------------------------------------------------------------------- /library/pci_ide_km_responder_lib/pci_ide_km_rsp_key_set_stop.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | #include "hal/base.h" 8 | #include "hal/library/memlib.h" 9 | #include "hal/library/debuglib.h" 10 | #include "library/spdm_requester_lib.h" 11 | #include "library/spdm_transport_pcidoe_lib.h" 12 | #include "library/pci_ide_km_device_lib.h" 13 | 14 | /** 15 | * Process the IDE_KM request and return the response. 16 | * 17 | * @param request the IDE_KM request message, start from pci_ide_km_header_t. 18 | * @param request_size size in bytes of request. 19 | * @param response the IDE_KM response message, start from pci_ide_km_header_t. 20 | * @param response_size size in bytes of response. 21 | * 22 | * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. 23 | * @return ERROR The request is not processed. 24 | **/ 25 | libspdm_return_t pci_ide_km_get_response_key_set_stop (const void *pci_doe_context, 26 | const void *spdm_context, 27 | const uint32_t *session_id, 28 | const void *request, size_t request_size, 29 | void *response, size_t *response_size) 30 | { 31 | const pci_ide_km_k_set_stop_t *ide_km_request; 32 | pci_ide_km_k_gostop_ack_t *ide_km_response; 33 | libspdm_return_t status; 34 | 35 | ide_km_request = request; 36 | ide_km_response = response; 37 | if (request_size != sizeof(pci_ide_km_k_set_stop_t)) { 38 | return LIBSPDM_STATUS_INVALID_MSG_SIZE; 39 | } 40 | LIBSPDM_ASSERT (*response_size >= sizeof(pci_ide_km_k_gostop_ack_t)); 41 | *response_size = sizeof(pci_ide_km_k_gostop_ack_t); 42 | 43 | libspdm_zero_mem (response, *response_size); 44 | ide_km_response->header.object_id = PCI_IDE_KM_OBJECT_ID_K_SET_GOSTOP_ACK; 45 | 46 | ide_km_response->stream_id = ide_km_request->stream_id; 47 | ide_km_response->key_sub_stream = ide_km_request->key_sub_stream; 48 | ide_km_response->port_index = ide_km_request->port_index; 49 | 50 | status = pci_ide_km_device_key_set_stop (pci_doe_context, spdm_context, session_id, 51 | ide_km_request->stream_id, 52 | ide_km_request->key_sub_stream, 53 | ide_km_request->port_index 54 | ); 55 | if (LIBSPDM_STATUS_IS_ERROR(status)) { 56 | return status; 57 | } 58 | 59 | return LIBSPDM_STATUS_SUCCESS; 60 | } 61 | -------------------------------------------------------------------------------- /spdm-device-sample/spdm_device_sample/library/spdm_device_secret_lib/sign.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright Notice: 3 | * Copyright 2021-2022 DMTF. All rights reserved. 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/spdm-emu/blob/main/LICENSE.md 5 | **/ 6 | 7 | /** @file 8 | * SPDM common library. 9 | * It follows the SPDM Specification. 10 | **/ 11 | #include 12 | #if defined(_MSC_VER) || (defined(__clang__) && (defined (LIBSPDM_CPU_AARCH64) || \ 13 | defined(LIBSPDM_CPU_ARM))) 14 | #else 15 | /* #include 16 | * #include 17 | * #include */ 18 | #endif 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "library/memlib.h" 29 | #include "spdm_device_secret_lib_internal.h" 30 | 31 | /** 32 | * Sign an SPDM message data. 33 | * 34 | * @param base_asym_algo Indicates the signing algorithm. 35 | * @param base_hash_algo Indicates the hash algorithm. 36 | * @param message A pointer to a message to be signed (before hash). 37 | * @param message_size The size in bytes of the message to be signed. 38 | * @param signature A pointer to a destination buffer to store the signature. 39 | * @param sig_size On input, indicates the size in bytes of the destination buffer to store the signature. 40 | * On output, indicates the size in bytes of the signature in the buffer. 41 | * 42 | * @retval true signing success. 43 | * @retval false signing fail. 44 | **/ 45 | bool libspdm_responder_data_sign( 46 | void *spdm_context, 47 | spdm_version_number_t spdm_version, 48 | uint8_t key_pair_id, uint8_t op_code, 49 | uint32_t base_asym_algo, uint32_t pqc_asym_algo, 50 | uint32_t base_hash_algo, bool is_data_hash, 51 | const uint8_t *message, size_t message_size, 52 | uint8_t *signature, size_t *sig_size) 53 | { 54 | void *context; 55 | bool result; 56 | 57 | result = libspdm_get_responder_private_key_from_raw_data(base_asym_algo, &context); 58 | if (!result) { 59 | return false; 60 | } 61 | 62 | if (is_data_hash) { 63 | result = libspdm_asym_sign_hash(spdm_version, op_code, base_asym_algo, base_hash_algo, 64 | context, 65 | message, message_size, signature, sig_size); 66 | } else { 67 | result = libspdm_asym_sign(spdm_version, op_code, base_asym_algo, base_hash_algo, context, 68 | message, message_size, signature, sig_size); 69 | } 70 | libspdm_asym_free(base_asym_algo, context); 71 | 72 | return result; 73 | } 74 | --------------------------------------------------------------------------------