From patchwork Wed Sep 5 18:28:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 181909 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id B59CB2C007E for ; Thu, 6 Sep 2012 04:28:43 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T9KK2-0000nK-62; Wed, 05 Sep 2012 18:27:30 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T9KJy-0000mc-Rt for fwts-devel@lists.ubuntu.com; Wed, 05 Sep 2012 18:27:26 +0000 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginmedia.com ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1T9KL9-0004Yl-5E for fwts-devel@lists.ubuntu.com; Wed, 05 Sep 2012 18:28:39 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH 1/2] lib: fwts_guid: Add fwts_guid_str_to_buf to convert string back to a GUID Date: Wed, 5 Sep 2012 19:28:36 +0100 Message-Id: <1346869717-16964-2-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1346869717-16964-1-git-send-email-colin.king@canonical.com> References: <1346869717-16964-1-git-send-email-colin.king@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King We need to convert GUIDs in ASCII strings back to a 16 byte GUID for some of the UEFI variable GUID string handling. Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Keng-Yu Lin --- src/lib/include/fwts_guid.h | 1 + src/lib/src/fwts_guid.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/lib/include/fwts_guid.h b/src/lib/include/fwts_guid.h index d836948..ba5ee6c 100644 --- a/src/lib/include/fwts_guid.h +++ b/src/lib/include/fwts_guid.h @@ -24,5 +24,6 @@ #include void fwts_guid_buf_to_str(uint8_t *guid, char *guid_str, size_t guid_str_len); +void fwts_guid_str_to_buf(const char *guid_str, uint8_t *guid, size_t guid_len); #endif diff --git a/src/lib/src/fwts_guid.c b/src/lib/src/fwts_guid.c index 510cb25..b4e9b07 100644 --- a/src/lib/src/fwts_guid.c +++ b/src/lib/src/fwts_guid.c @@ -33,3 +33,17 @@ void fwts_guid_buf_to_str(uint8_t *guid, char *guid_str, size_t guid_str_len) guid[3], guid[2], guid[1], guid[0], guid[5], guid[4], guid[7], guid[6], guid[8], guid[9], guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]); } + +/* + * fwts_guid_str_to_buf() + * convert a GUID string back to a 16 byte GUID + * guid needs to be at least 16 chars long + */ +void fwts_guid_str_to_buf(const char *guid_str, uint8_t *guid, size_t guid_len) +{ + if (guid && guid_len >= 16) { + sscanf(guid_str, "%2hhx%2hhx%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx", + &guid[3], &guid[2], &guid[1], &guid[0], &guid[5], &guid[4], &guid[7], &guid[6], + &guid[8], &guid[9], &guid[10], &guid[11], &guid[12], &guid[13], &guid[14], &guid[15]); + } +}