diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-05 08:38:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-05 08:38:36 +0000 |
commit | 3c0f1ed2ea093dd0d3e8ba70f3c9963e66321f87 (patch) | |
tree | 2020852fabf5e530c687d41e36ddc5c453b0c9ed /nvme-rpmb.c | |
parent | Adding upstream version 2.9.1. (diff) | |
download | nvme-cli-3c0f1ed2ea093dd0d3e8ba70f3c9963e66321f87.tar.xz nvme-cli-3c0f1ed2ea093dd0d3e8ba70f3c9963e66321f87.zip |
Adding upstream version 2.10.upstream/2.10
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | nvme-rpmb.c | 28 |
1 files changed, 23 insertions, 5 deletions
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; } |