Blame SOURCES/opencryptoki-3.11.0-d6ba9ff61743ce869a5a677f6f77339642efef.patch

299615
commit d6ba9ff61743ce869a5a677f6f77339642efef4b
299615
Author: Ingo Franzki <ifranzki@linux.ibm.com>
299615
Date:   Tue Sep 24 14:35:59 2019 +0200
299615
299615
    EP11: Support tolerated new crypto cards
299615
    
299615
    With just toleration support of new crypt cards, new crypto
299615
    cards are reported as the last known crypto card version.
299615
    E.g. a CEX7 card is reported as CEX6, when CEX6 is the last
299615
    known crypto card version.
299615
    
299615
    The EP11 token checks the card versions and needs to distinguish
299615
    tolerated cards from supported cards. New (tolerated) crypto cards
299615
    may have different API and firmware versions, and thus need to be
299615
    handled differently.
299615
    
299615
    Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
299615
299615
diff --git a/usr/lib/ep11_stdll/ep11_specific.c b/usr/lib/ep11_stdll/ep11_specific.c
299615
index e22dad5d..a65accea 100644
299615
--- a/usr/lib/ep11_stdll/ep11_specific.c
299615
+++ b/usr/lib/ep11_stdll/ep11_specific.c
299615
@@ -8253,6 +8253,7 @@ static CK_RV get_card_type(uint_32 adapter, CK_ULONG *type)
299615
     char fname[PATH_MAX];
299615
     char buf[250];
299615
     CK_RV rc;
299615
+    CK_ULONG hwtype, rawtype;
299615
 
299615
     sprintf(fname, "%scard%02x/type", SYSFS_DEVICES_AP, adapter);
299615
     rc = file_fgets(fname, buf, sizeof(buf));
299615
@@ -8260,6 +8261,28 @@ static CK_RV get_card_type(uint_32 adapter, CK_ULONG *type)
299615
         return rc;
299615
     if (sscanf(buf, "CEX%luP", type) != 1)
299615
         return CKR_FUNCTION_FAILED;
299615
+
299615
+    sprintf(fname, "%scard%02x/hwtype", SYSFS_DEVICES_AP, adapter);
299615
+    rc = file_fgets(fname, buf, sizeof(buf));
299615
+    if (rc != CKR_OK)
299615
+        return rc;
299615
+    if (sscanf(buf, "%lu", &hwtype) != 1)
299615
+        return CKR_FUNCTION_FAILED;
299615
+
299615
+    sprintf(fname, "%scard%02x/raw_hwtype", SYSFS_DEVICES_AP, adapter);
299615
+    rc = file_fgets(fname, buf, sizeof(buf));
299615
+    if (rc != CKR_OK)
299615
+        return rc;
299615
+    if (sscanf(buf, "%lu", &rawtype) != 1)
299615
+        return CKR_FUNCTION_FAILED;
299615
+
299615
+    if (rawtype > hwtype) {
299615
+        TRACE_DEVEL("%s adapter: %u hwtype: %lu raw_hwtype: %lu\n",
299615
+                    __func__, adapter, hwtype, rawtype);
299615
+        /* Tolerated new card level: report calculated type */
299615
+        *type += (rawtype - hwtype);
299615
+    }
299615
+
299615
     return CKR_OK;
299615
 }
299615