From f3eb303f6b1c6192b50a05f1877665da0e009d53 Mon Sep 17 00:00:00 2001 From: itycodes Date: Fri, 14 Jun 2024 01:02:12 +0200 Subject: [PATCH 4/4] Add ATA command Security Disable --- smartmontools/atacmds.h | 1 + smartmontools/ataprint.cpp | 15 +++++++++++++-- smartmontools/ataprint.h | 1 + smartmontools/smartctl.cpp | 3 +++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/smartmontools/atacmds.h b/smartmontools/atacmds.h index 77a1522d..32b57f77 100644 --- a/smartmontools/atacmds.h +++ b/smartmontools/atacmds.h @@ -56,6 +56,7 @@ typedef enum { #define ATA_SMART_CMD 0xb0 #define ATA_SECURITY_FREEZE_LOCK 0xf5 #define ATA_SECURITY_UNLOCK 0xf2 +#define ATA_SECURITY_DISABLE 0xf6 #ifndef ATA_SET_FEATURES #define ATA_SET_FEATURES 0xef #endif diff --git a/smartmontools/ataprint.cpp b/smartmontools/ataprint.cpp index 00ff8878..2fe97903 100644 --- a/smartmontools/ataprint.cpp +++ b/smartmontools/ataprint.cpp @@ -3755,7 +3755,7 @@ int ataPrintMain (ata_device * device, const ata_print_options & options) || options.smart_auto_save_disable || options.smart_auto_save_enable || options.smart_auto_offl_disable || options.smart_auto_offl_enable || options.set_aam || options.set_apm || options.set_lookahead || options.set_security_unlock - || options.set_wcache || options.set_security_freeze || options.set_standby + || options.set_security_disable || options.set_wcache || options.set_security_freeze || options.set_standby || options.sct_wcache_reorder_set || options.sct_wcache_sct_set || options.set_dsn) pout("=== START OF ENABLE/DISABLE COMMANDS SECTION ===\n"); @@ -3888,6 +3888,17 @@ int ataPrintMain (ata_device * device, const ata_print_options & options) pout("ATA Security set to unlocked\n"); } + + // Disable ATA security + if (options.set_security_disable) { + if (!ata_password_command(device, ATA_SECURITY_DISABLE, 0, options.security_password)) { + pout("ATA SECURITY DISABLE failed: %s\n", device->get_errmsg()); + returnval |= FAILSMART; + } + else + pout("ATA Security set to disabled\n"); + } + // Set standby timer unless immediate standby is also requested if (options.set_standby && !options.set_standby_now) { if (!ata_nodata_command(device, ATA_IDLE, options.set_standby-1)) { @@ -4011,7 +4022,7 @@ int ataPrintMain (ata_device * device, const ata_print_options & options) || options.smart_auto_offl_disable || options.smart_auto_offl_enable || options.set_aam || options.set_apm || options.set_lookahead || options.set_wcache || options.set_security_freeze || options.set_security_unlock - || options.set_standby || options.sct_wcache_reorder_set || options.set_dsn) + || options.set_security_disable || options.set_standby || options.sct_wcache_reorder_set || options.set_dsn) pout("\n"); // START OF READ-ONLY OPTIONS APART FROM -V and -i diff --git a/smartmontools/ataprint.h b/smartmontools/ataprint.h index dcf96dfb..4725fe41 100644 --- a/smartmontools/ataprint.h +++ b/smartmontools/ataprint.h @@ -94,6 +94,7 @@ struct ata_print_options bool get_security = false; // print ATA security status bool set_security_freeze = false; // Freeze ATA security bool set_security_unlock = false; // Unlock ATA security + bool set_security_disable = false; // Disable ATA security unsigned short* security_password; // ATA security password bool get_wcache = false; // print write cache status int set_wcache = 0; // disable(-1), enable(1) write cache diff --git a/smartmontools/smartctl.cpp b/smartmontools/smartctl.cpp index 25b3d09e..034b7c2a 100644 --- a/smartmontools/smartctl.cpp +++ b/smartmontools/smartctl.cpp @@ -1094,6 +1094,9 @@ static int parse_options(int argc, char** argv, const char * & type, else if(!get && !strcmp(optarg, "security-unlock")) { ataopts.set_security_unlock = true; } + else if(!get && !strcmp(optarg, "security-disable")) { + ataopts.set_security_disable = true; + } else if (!get && !strcmp(optarg, "standby,now")) { ataopts.set_standby_now = true; scsiopts.set_standby_now = true; -- 2.45.1