summaryrefslogtreecommitdiffstats
path: root/plugins/sed/sedopal_cmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/sed/sedopal_cmd.c')
-rw-r--r--plugins/sed/sedopal_cmd.c59
1 files changed, 43 insertions, 16 deletions
diff --git a/plugins/sed/sedopal_cmd.c b/plugins/sed/sedopal_cmd.c
index 649e0b2..d9a789c 100644
--- a/plugins/sed/sedopal_cmd.c
+++ b/plugins/sed/sedopal_cmd.c
@@ -169,8 +169,10 @@ int sedopal_cmd_initialize(int fd)
struct opal_key key;
struct opal_lr_act lr_act = {};
struct opal_user_lr_setup lr_setup = {};
+ struct opal_new_pw new_pw = {};
sedopal_ask_key = true;
+ sedopal_ask_new_key = true;
rc = sedopal_set_key(&key);
if (rc != 0)
return rc;
@@ -217,6 +219,21 @@ int sedopal_cmd_initialize(int fd)
return rc;
}
+ /*
+ * set password
+ */
+ new_pw.new_user_pw.who = OPAL_ADMIN1;
+ new_pw.new_user_pw.opal_key.lr = 0;
+ new_pw.session.who = OPAL_ADMIN1;
+ new_pw.session.sum = 0;
+ new_pw.session.opal_key.lr = 0;
+ new_pw.session.opal_key = key;
+ new_pw.new_user_pw.opal_key = key;
+
+ rc = ioctl(fd, IOC_OPAL_SET_PW, &new_pw);
+ if (rc != 0)
+ fprintf(stderr, "Error: failed setting password - %d\n", rc);
+
return rc;
}
@@ -234,8 +251,21 @@ int sedopal_cmd_lock(int fd)
*/
int sedopal_cmd_unlock(int fd)
{
+ int rc;
+
+ rc = sedopal_lock_unlock(fd, OPAL_RW);
- return sedopal_lock_unlock(fd, OPAL_RW);
+ /*
+ * If the unlock was successful, force a re-read of the
+ * partition table. Return rc of unlock operation.
+ */
+ if (rc == 0) {
+ if (ioctl(fd, BLKRRPART, 0) != 0)
+ fprintf(stderr,
+ "Warning: failed re-reading partition\n");
+ }
+
+ return rc;
}
/*
@@ -258,18 +288,6 @@ int sedopal_lock_unlock(int fd, int lock_state)
if (rc != 0)
fprintf(stderr,
"Error: failed locking or unlocking - %d\n", rc);
-
- /*
- * If the unlock was successful, force a re-read of the
- * partition table.
- */
- if (rc == 0) {
- rc = ioctl(fd, BLKRRPART, 0);
- if (rc != 0)
- fprintf(stderr,
- "Error: failed re-reading partition\n");
- }
-
return rc;
}
@@ -380,6 +398,14 @@ int sedopal_cmd_revert(int fd)
revert_lsp.__pad = 0;
rc = ioctl(fd, IOC_OPAL_REVERT_LSP, &revert_lsp);
+ if (rc == 0) {
+ /*
+ * TPER must also be reverted.
+ */
+ rc = ioctl(fd, IOC_OPAL_REVERT_TPR, &revert_lsp.key);
+ if (rc != 0)
+ fprintf(stderr, "Error: revert TPR - %d\n", rc);
+ }
#else
rc = -EOPNOTSUPP;
#endif
@@ -448,14 +474,14 @@ void sedopal_print_locking_features(uint8_t features)
int sedopal_cmd_discover(int fd)
{
#ifdef IOC_OPAL_DISCOVERY
- int rc;
+ int rc, feat_length;
bool sedopal_locking_supported = false;
struct opal_discovery discover;
struct level_0_discovery_header *dh;
struct level_0_discovery_features *feat;
struct level_0_discovery_features *feat_end;
uint16_t code;
- uint8_t locking_flags;
+ uint8_t locking_flags = 0;
char buf[4096];
discover.data = (__u64)buf;
@@ -483,6 +509,7 @@ int sedopal_cmd_discover(int fd)
*/
while (feat < feat_end) {
code = be16toh(feat->code);
+ feat_length = feat->length + 4 /* hdr */;
switch (code) {
case OPAL_FEATURE_CODE_LOCKING:
locking_flags = feat->feature;
@@ -494,7 +521,7 @@ int sedopal_cmd_discover(int fd)
break;
}
- feat++;
+ feat = (struct level_0_discovery_features *)((char *)feat + feat_length);
}
rc = 0;