linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Cooper <alcooperx@gmail.com>
To: cjb@laptop.org, linux-mmc@vger.kernel.org
Cc: Al Cooper <alcooperx@gmail.com>
Subject: [PATCH V3 3/7] mmc: lock: Add function to unlock a password locked card
Date: Wed, 5 Mar 2014 18:44:48 -0500	[thread overview]
Message-ID: <1394063092-9048-4-git-send-email-alcooperx@gmail.com> (raw)
In-Reply-To: <1394063092-9048-1-git-send-email-alcooperx@gmail.com>

This function will try to get a password for the card and use the
password to unlock it. It will leave the card state flag set
appropriately.

Signed-off-by: Al Cooper <alcooperx@gmail.com>
---
 drivers/mmc/core/core.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 8fc8c11..978e4e5 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2793,6 +2793,27 @@ static inline void mmc_unregister_key_type(void)
 	unregister_key_type(&key_type_mmc);
 }
 
+int mmc_unlock_card(struct mmc_card *card)
+{
+	int stat;
+	struct mmc_password password;
+
+	mmc_card_set_locked(card);
+	stat = mmc_get_password(card, &password);
+	if (stat) {
+		pr_warn("%s: Cannot find matching key\n",
+			mmc_hostname(card->host));
+		return stat;
+	}
+	stat = mmc_lock_unlock(card, &password, MMC_LOCK_MODE_UNLOCK);
+	if (stat)
+		pr_warn("%s: Password failed to unlock card\n",
+			mmc_hostname(card->host));
+	else
+		mmc_card_clear_locked(card);
+	return stat;
+}
+
 #else /* CONFIG_MMC_LOCK */
 
 int mmc_get_password(struct mmc_card *card, struct mmc_password *password)
@@ -2809,6 +2830,11 @@ static inline void mmc_unregister_key_type(void)
 {
 }
 
+int mmc_unlock_card(struct mmc_card *card)
+{
+	return -ENOKEY;
+}
+
 #endif /* CONFIG_MMC_LOCK */
 
 static int __init mmc_init(void)
-- 
1.8.1.3


  parent reply	other threads:[~2014-03-05 23:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-05 23:44 [PATCH V3 0/7] Add password protected lock/unlock support for SD/MMC Al Cooper
2014-03-05 23:44 ` [PATCH V3 1/7] mmc: lock: Use the kernel "KEYS" subsystem to get a card's password Al Cooper
2014-03-05 23:44 ` [PATCH V3 2/7] mmc: lock: Add low level LOCK_UNLOCK command Al Cooper
2014-03-05 23:44 ` Al Cooper [this message]
2014-03-05 23:44 ` [PATCH V3 4/7] mmc: lock: Add card lock/unlock maintenance commands Al Cooper
2014-03-05 23:44 ` [PATCH V3 5/7] mmc: lock: Change SD init functionality to handle locked SD cards Al Cooper
2014-03-05 23:44 ` [PATCH V3 6/7] mmc: lock: Prevent block device from coming up for locked cards Al Cooper
2014-03-05 23:44 ` [PATCH V3 7/7] mmc: lock: Change MMC init to handle " Al Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1394063092-9048-4-git-send-email-alcooperx@gmail.com \
    --to=alcooperx@gmail.com \
    --cc=cjb@laptop.org \
    --cc=linux-mmc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).