Skip to content

Commit

Permalink
Adding missing libcaliptra dpe command structs
Browse files Browse the repository at this point in the history
  • Loading branch information
nquarton committed Jul 27, 2024
1 parent 51ff0a8 commit fecc0f3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
16 changes: 9 additions & 7 deletions libcaliptra/examples/generic/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,18 +445,20 @@ int rt_test_all_commands()
}

// INVOKE_DPE_COMMAND
// Using GET_PROFILE as an example command
// TODO: Coverage of other DPE commands should be added
struct caliptra_invoke_dpe_req dpe_req = {};
struct caliptra_invoke_dpe_resp dpe_resp = {};

dpe_req.data_size = sizeof(struct dpe_get_profile_cmd);
dpe_req.get_profile_cmd.cmd_hdr.magic = DPE_MAGIC;
dpe_req.get_profile_cmd.cmd_hdr.cmd_id = DPE_GET_PROFILE;
dpe_req.get_profile_cmd.cmd_hdr.profile = 0x2;

status = caliptra_invoke_dpe_command(&dpe_req, &dpe_resp, false);

// Not testing for full success
// Instead, just want to see it give the right DPE-specific error
// This still proves the FW recognizes the message and request data and got to the right DPE code
uint32_t RUNTIME_DPE_COMMAND_DESERIALIZATION_FAILED = 0xe0027;
non_fatal_error = caliptra_read_fw_non_fatal_error();
if (status != MBX_STATUS_FAILED || non_fatal_error != RUNTIME_DPE_COMMAND_DESERIALIZATION_FAILED) {
printf("DPE Command unexpected result/failure: 0x%x\n", status);
if (status) {
printf("DPE Command failed: 0x%x\n", status);
dump_caliptra_error_codes();
failure = 1;
} else {
Expand Down
22 changes: 15 additions & 7 deletions libcaliptra/inc/caliptra_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,8 @@ struct caliptra_capabilities_resp {
uint8_t capabilities[16];
};

// The below fields are placeholders to set up the baseline
// required for communication of DPE commands to Caliptra
// firmware.
// DPE commands

#define DPE_DATA_MAX 512
#define DPE_MAGIC 0x44504543 // "DPEC"

struct dpe_cmd_hdr {
Expand Down Expand Up @@ -254,6 +251,10 @@ struct dpe_resp_hdr {
#endif

// GET_PROFILE
struct dpe_get_profile_cmd {
struct dpe_cmd_hdr cmd_hdr;
};

struct dpe_get_profile_response {
struct dpe_resp_hdr resp_hdr;
uint16_t profile_major_version;
Expand Down Expand Up @@ -344,7 +345,10 @@ struct dpe_rotate_context_handle_response {
struct dpe_destroy_context_cmd {
struct dpe_cmd_hdr cmd_hdr;
uint8_t context_handle[DPE_HANDLE_SIZE];
uint32_t flags;
};

struct dpe_destroy_context_response {
struct dpe_resp_hdr resp_hdr;
};

// GET_CERTIFICATE_CHAIN
Expand All @@ -365,28 +369,32 @@ struct caliptra_invoke_dpe_req {
struct caliptra_req_header hdr;
uint32_t data_size;
union {
struct dpe_cmd_hdr cmd_hdr;
struct dpe_get_profile_cmd get_profile_cmd;
struct dpe_initialize_context_cmd initialize_context_cmd;
struct dpe_derive_context_cmd derive_context_cmd;
struct dpe_certify_key_cmd certify_key_cmd;
struct dpe_sign_cmd sign_cmd;
struct dpe_rotate_context_handle_cmd rotate_context_handle_cmd;
struct dpe_destroy_context_cmd destroy_context_cmd;
struct dpe_get_certificate_chain_cmd get_certificate_chain_cmd;
uint8_t data[DPE_DATA_MAX];
uint8_t data[0];
};
};

struct caliptra_invoke_dpe_resp {
struct caliptra_resp_header cpl;
uint32_t data_size;
union {
struct dpe_resp_hdr resp_hdr;
struct dpe_get_profile_response get_profile_resp;
struct dpe_initialize_context_response initialize_context_resp;
struct dpe_derive_context_response derive_context_resp;
struct dpe_certify_key_response certify_key_resp;
struct dpe_sign_response sign_resp;
struct dpe_rotate_context_handle_response rotate_context_handle_resp;
struct dpe_destroy_context_response destroy_context_resp;
struct dpe_get_certificate_chain_response get_certificate_chain_resp;
uint8_t data[sizeof(struct dpe_certify_key_response)];
uint8_t data[0];
};
};
2 changes: 2 additions & 0 deletions libcaliptra/src/caliptra_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ static int pack_and_execute_command(struct parcel *parcel, bool async)
};

// Calculate and populate the checksum field
// Clear the checksum field before calculating
*((caliptra_checksum*)tx_buf.data) = 0x0;
*((caliptra_checksum*)tx_buf.data) = calculate_caliptra_checksum(parcel->command, tx_buf.data, tx_buf.len);

return caliptra_mailbox_execute(parcel->command, &tx_buf, &rx_buf, async);
Expand Down

0 comments on commit fecc0f3

Please sign in to comment.