]> err.no Git - yubikey-personalization/commitdiff
add ykp_command and ykp_configure_command
authorKlas Lindfors <klas@yubico.com>
Tue, 27 Mar 2012 08:17:08 +0000 (10:17 +0200)
committerKlas Lindfors <klas@yubico.com>
Tue, 27 Mar 2012 08:17:08 +0000 (10:17 +0200)
work with commands instead of slots. let the slots functions wrap these.

libykpers-1.map
ykpers.c

index ea3b55acb7ad908c209ecdfe982740f216f2a8fc..325cf83097f50fb165adf96d2ce88d25948c4ca8 100644 (file)
@@ -126,3 +126,11 @@ LIBYKPERS_1.6 {
   ykp_get_oath_imf;
 # Variables:
 } LIBYKPERS_1.5;
+
+LIBYKPERS_1.7 {
+  global:
+# Functions:
+  ykp_command;
+  ykp_configure_command;
+# Variables:
+} LIBYKPERS_1.6;
index aea48183e934b4cb3ee704404634d94c819a22e1..d8a209ad339a7554ff6c04195f7c945f76f3bb6c 100644 (file)
--- a/ykpers.c
+++ b/ykpers.c
@@ -45,7 +45,7 @@
 struct ykp_config_t {
        unsigned int yk_major_version;
        unsigned int yk_minor_version;
-       unsigned int configuration_number;
+       unsigned int command;
 
        YK_CONFIG ykcore_config;
 };
@@ -85,7 +85,7 @@ YKP_CONFIG *ykp_create_config(void)
                       sizeof(default_config1));
                cfg->yk_major_version = 1;
                cfg->yk_minor_version = 3;
-               cfg->configuration_number = 1;
+               cfg->command = SLOT_CONFIG;
                return cfg;
        }
        return 0;
@@ -100,31 +100,50 @@ int ykp_free_config(YKP_CONFIG *cfg)
        return 0;
 }
 
-int ykp_configure_for(YKP_CONFIG *cfg, int confnum, YK_STATUS *st)
+int ykp_configure_command(YKP_CONFIG *cfg, uint8_t command, YK_STATUS *st)
 {
        cfg->yk_major_version = st->versionMajor;
        cfg->yk_minor_version = st->versionMinor;
 
-       switch(confnum) {
-       case 1:
+       switch(command) {
+       case SLOT_CONFIG:
                memcpy(&cfg->ykcore_config, &default_config1,
-                      sizeof(default_config1));
-               cfg->configuration_number = 1;
-               return 1;
-       case 2:
+                       sizeof(default_config1));
+               break;
+       case SLOT_CONFIG2:
                if (cfg->yk_major_version >= 2) {
-                       memcpy(&cfg->ykcore_config, &default_config2,
-                              sizeof(default_config2));
-                       cfg->configuration_number = 2;
-                       return 1;
+                 memcpy(&cfg->ykcore_config, &default_config2,
+                         sizeof(default_config2));
+               } else {
+                 ykp_errno = YKP_EOLDYUBIKEY;
+                 return 0;
+               }
+               break;
+       case SLOT_SWAP:
+               if (!((cfg->yk_major_version == 2 && cfg->yk_minor_version >= 3)
+                         || cfg->yk_major_version > 2)) {
+                       ykp_errno = YKP_EOLDYUBIKEY;
+                       return 0;
                }
-               ykp_errno = YKP_EOLDYUBIKEY;
                break;
        default:
                ykp_errno = YKP_EINVCONFNUM;
-               break;
+               return 0;
+  }
+  cfg->command = command;
+}
+
+int ykp_configure_for(YKP_CONFIG *cfg, int confnum, YK_STATUS *st)
+{
+       switch(confnum) {
+       case 1:
+               return ykp_configure_command(cfg, SLOT_CONFIG, st);
+       case 2:
+               return ykp_configure_command(cfg, SLOT_CONFIG2, st);
+       default:
+               ykp_errno = YKP_EINVCONFNUM;
+               return 0;
        }
-       return 0;
 }
 
 /* Return number of bytes of key data for this configuration.
@@ -712,10 +731,23 @@ YK_CONFIG *ykp_core_config(YKP_CONFIG *cfg)
        return 0;
 }
 
+int ykp_command(YKP_CONFIG *cfg) {
+       if (cfg) {
+               return cfg->command;
+       }
+       ykp_errno = YKP_ENOCFG;
+       return 0;
+}
+
 int ykp_config_num(YKP_CONFIG *cfg)
 {
-       if (cfg)
-               return cfg->configuration_number;
+       if (cfg) {
+               if (cfg->command == SLOT_CONFIG) {
+                       return 1;
+               } else if (cfg->command == SLOT_CONFIG2) {
+                       return 2;
+               }
+       }
        ykp_errno = YKP_ENOCFG;
        return 0;
 }