From 92928eb01c93854ebcdcb156b01cb2b4a9f85027 Mon Sep 17 00:00:00 2001 From: levitte Date: Thu, 16 Oct 2008 14:46:45 +0000 Subject: [PATCH] Add functions to set more fields in the configuration structure. Implement the simple ones for now git-svn-id: https://yubikey-personalization.googlecode.com/svn/trunk@34 b62f149e-849f-11dd-9899-c7ba65f7c4c7 --- ykpers.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- ykpers.h | 17 +++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/ykpers.c b/ykpers.c index 1e56e15..8716c75 100644 --- a/ykpers.c +++ b/ykpers.c @@ -151,6 +151,49 @@ int ykp_set_access_code(CONFIG *cfg, unsigned char *access_code) return 0; } +#define def_set_tktflag(type) \ +int ykp_set_tktflag_ ## type(CONFIG *cfg, bool state) \ +{ \ + if (cfg) { \ + if (state) \ + cfg->tktFlags |= TKTFLAG_ ## type; \ + else \ + cfg->tktFlags &= ~TKTFLAG_ ## type; \ + return 1; \ + } \ + ykp_errno = YKP_ENOCFG; \ + return 0; \ +} + +#define def_set_cfgflag(type) \ +int ykp_set_cfgflag_ ## type(CONFIG *cfg, bool state) \ +{ \ + if (cfg) { \ + if (state) \ + cfg->cfgFlags |= CFGFLAG_ ## type; \ + else \ + cfg->cfgFlags &= ~CFGFLAG_ ## type; \ + return 1; \ + } \ + ykp_errno = YKP_ENOCFG; \ + return 0; \ +} + +def_set_tktflag(TAB_FIRST) +def_set_tktflag(APPEND_TAB1) +def_set_tktflag(APPEND_TAB2) +def_set_tktflag(APPEND_DELAY1) +def_set_tktflag(APPEND_DELAY2) +def_set_tktflag(APPEND_CR) + +def_set_cfgflag(SEND_REF) +def_set_cfgflag(TICKET_FIRST) +def_set_cfgflag(PACING_10MS) +def_set_cfgflag(PACING_20MS) +def_set_cfgflag(ALLOW_HIDTRIG) +def_set_cfgflag(STATIC_TICKET) + + const char str_key_value_separator[] = ":"; const char str_fixed[] = "fixed"; const char str_uid[] = "uid"; @@ -288,7 +331,8 @@ int * const _ykp_errno_location(void) static const char *errtext[] = { "", - "not yet implemented" + "not yet implemented", + "no configuration structure given" }; const char *ykp_strerror(int errnum) { diff --git a/ykpers.h b/ykpers.h index 6f90571..ff8e1df 100644 --- a/ykpers.h +++ b/ykpers.h @@ -39,6 +39,22 @@ int ykp_free_config(CONFIG *cfg); int ykp_AES_key_from_passphrase(CONFIG *cfg, const char *passphrase, const char *salt); int ykp_set_access_code(CONFIG *cfg, unsigned char *access_code); +int ykp_set_fixed(CONFIG *cfg, unsigned char *fixed); +int ykp_set_uid(CONFIG *cfg, unsigned char *uid); + +int ykp_set_tktflag_TAB_FIRST(CONFIG *cfg, bool state); +int ykp_set_tktflag_APPEND_TAB1(CONFIG *cfg, bool state); +int ykp_set_tktflag_APPEND_TAB2(CONFIG *cfg, bool state); +int ykp_set_tktflag_APPEND_DELAY1(CONFIG *cfg, bool state); +int ykp_set_tktflag_APPEND_DELAY2(CONFIG *cfg, bool state); +int ykp_set_tktflag_APPEND_CR(CONFIG *cfg, bool state); + +int ykp_set_cfgflag_SEND_REF(CONFIG *cfg, bool state); +int ykp_set_cfgflag_TICKET_FIRST(CONFIG *cfg, bool state); +int ykp_set_cfgflag_PACING_10MS(CONFIG *cfg, bool state); +int ykp_set_cfgflag_PACING_20MS(CONFIG *cfg, bool state); +int ykp_set_cfgflag_ALLOW_HIDTRIG(CONFIG *cfg, bool state); +int ykp_set_cfgflag_STATIC_TICKET(CONFIG *cfg, bool state); int ykp_write_config(const CONFIG *cfg, int (*writer)(const char *buf, size_t count, @@ -54,5 +70,6 @@ extern int * const _ykp_errno_location(void); const char *ykp_strerror(int errnum); #define YKP_ENOTYETIMPL 0x01 +#define YKP_ENOCFG 0x02 #endif // __YKPERS_H_INCLUDED__ -- 2.39.5