From 3c0f1ed2ea093dd0d3e8ba70f3c9963e66321f87 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 5 Aug 2024 10:38:36 +0200 Subject: Adding upstream version 2.10. Signed-off-by: Daniel Baumann --- nvme-rpmb.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'nvme-rpmb.c') diff --git a/nvme-rpmb.c b/nvme-rpmb.c index 345e6ea..692b062 100644 --- a/nvme-rpmb.c +++ b/nvme-rpmb.c @@ -207,7 +207,7 @@ static void write_file(unsigned char *data, size_t len, const char *dir, const char *file, const char *msg) { char temp_folder[PATH_MAX] = { 0 }; - FILE *fp = NULL; + _cleanup_file_ FILE *fp = NULL; if (dir != NULL) sprintf(temp_folder, "%s/%s", dir, file); @@ -219,7 +219,6 @@ static void write_file(unsigned char *data, size_t len, const char *dir, fprintf(stderr, "Failed to write %s data to %s\n", msg ? msg : "", temp_folder); } - fclose(fp); } else { fprintf(stderr, "Failed to open %s file to write %s\n", temp_folder, msg ? msg : ""); @@ -602,9 +601,28 @@ static int rpmb_program_auth_key(int fd, unsigned char target, goto out; } - /* send request and read the result first */ - rsp = rpmb_read_request(fd, req, req_size, rsp_size); - if (rsp == NULL || rsp->result != 0) { + /* send the request and get response */ + err = send_rpmb_req(fd, req->target, req_size, req); + if (err) { + fprintf(stderr, "RPMB request 0x%04x for 0x%x, err: %d\n", req->type, req->target, + err); + goto out; + } + + /* send the request to get the result and then request to get the response */ + rsp = (struct rpmb_data_frame_t *)calloc(rsp_size, 1); + if (!rsp) { + fprintf(stderr, "failed to allocate response buffer memory\n"); + err = -ENOMEM; + goto out; + } + + rsp->target = req->target; + rsp->type = RPMB_REQ_READ_RESULT; + err = send_rpmb_req(fd, req->target, rsp_size, rsp); + if (err || rsp->result) { + fprintf(stderr, "Program auth key read result 0x%x, error = 0x%x\n", rsp->result, + err); goto out; } -- cgit v1.2.3