# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
noinst_LTLIBRARIES = libykcore.la
-libykcore_la_SOURCES = ykdef.h ykcore.h ykcore_backend.h ykcore.c \
+libykcore_la_SOURCES = ykdef.h ykcore.h ykcore_lcl.h ykcore_backend.h ykcore.c \
ykstatus.h ykstatus.c
libykcore_la_LIBADD = $(LTLIBYUBIKEY) $(LTLIBUSB)
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ykcore.h"
-#include "ykdef.h"
+#include "ykcore_lcl.h"
#include "ykcore_backend.h"
+/* To get modhex and crc16 */
#include <yubikey.h>
#ifndef _WIN32
_ykusb_start();
}
-YUBIKEY *yk_open_first_key(void)
+YK_KEY *yk_open_first_key(void)
{
struct usb_bus *bus;
struct usb_device *dev;
- YUBIKEY *yk = _ykusb_open_device(YUBICO_VID, YUBIKEY_PID);
+ YK_KEY *yk = _ykusb_open_device(YUBICO_VID, YUBIKEY_PID);
int rc = yk_errno;
if (yk) {
- STATUS st;
+ YK_STATUS st;
if (!yk_get_status(yk, &st)) {
rc = yk_errno;
return yk;
}
-int yk_close_key(YUBIKEY *yk)
+int yk_close_key(YK_KEY *yk)
{
return _ykusb_close_device(yk);
}
-int yk_get_status(YUBIKEY *k, STATUS *status)
+int yk_get_status(YK_KEY *k, YK_STATUS *status)
{
unsigned int status_count = 0;
- if (!yk_read_from_key(k, 0, status, sizeof(STATUS), &status_count))
+ if (!yk_read_from_key(k, 0, status, sizeof(YK_STATUS), &status_count))
return 0;
- if (status_count != sizeof(STATUS)) {
+ if (status_count != sizeof(YK_STATUS)) {
yk_errno = YK_EWRONGSIZ;
return 0;
}
- status->touchLevel = endian_swap_16(status->touchLevel);
+ status->touchLevel = yk_endian_swap_16(status->touchLevel);
return 1;
}
-int yk_write_config(YUBIKEY *yk, CONFIG *cfg, unsigned char *acc_code)
+int yk_write_config(YK_KEY *yk, YK_CONFIG *cfg, unsigned char *acc_code)
{
- unsigned char buf[sizeof(CONFIG) + ACC_CODE_SIZE];
- STATUS stat;
+ unsigned char buf[sizeof(YK_CONFIG) + ACC_CODE_SIZE];
+ YK_STATUS stat;
int seq;
/* Get current seqence # from status block */
if (cfg) {
cfg->crc = ~yubikey_crc16 ((unsigned char *) cfg,
- sizeof(CONFIG) - sizeof(cfg->crc));
- cfg->crc = endian_swap_16(cfg->crc);
- memcpy(buf, cfg, sizeof(CONFIG));
+ sizeof(YK_CONFIG) - sizeof(cfg->crc));
+ cfg->crc = yk_endian_swap_16(cfg->crc);
+ memcpy(buf, cfg, sizeof(YK_CONFIG));
}
/* Append current access code if present */
if (acc_code)
- memcpy(buf + sizeof(CONFIG), acc_code, ACC_CODE_SIZE);
+ memcpy(buf + sizeof(YK_CONFIG), acc_code, ACC_CODE_SIZE);
/* Write to Yubikey */
/* Note: we currently have no idea whatsoever how to read things larger
than FEATURE_RPT_SIZE - 1. We also have no idea what to do with the
slot parameter, it currently is there for future purposes only. */
-int yk_read_from_key(YUBIKEY *yk, uint8_t slot,
+int yk_read_from_key(YK_KEY *yk, uint8_t slot,
void *buf, unsigned int bufsize, unsigned int *bufcount)
{
unsigned char data[FEATURE_RPT_SIZE];
return 1;
}
-int yk_write_to_key(YUBIKEY *yk, uint8_t slot, const void *buf, int bufcount)
+int yk_write_to_key(YK_KEY *yk, uint8_t slot, const void *buf, int bufcount)
{
unsigned char repbuf[FEATURE_RPT_SIZE];
unsigned char data[SLOT_DATA_SIZE + FEATURE_RPT_SIZE];
return 1;
}
-int yk_force_key_update(YUBIKEY *yk)
+int yk_force_key_update(YK_KEY *yk)
{
unsigned char buf[FEATURE_RPT_SIZE];
return 1;
}
-uint16_t endian_swap_16(uint16_t x)
+uint16_t yk_endian_swap_16(uint16_t x)
{
static int testflag = -1;
*
****/
-typedef struct yubikey_st YUBIKEY; /* Really a USB device handle. */
-typedef struct status_st STATUS; /* Status structure,
+typedef struct yk_key_st YK_KEY; /* Really a USB device handle. */
+typedef struct yk_status_st YK_STATUS; /* Status structure,
filled by yk_get_status(). */
-typedef struct ticket_st TICKET; /* Ticket structure... */
-typedef struct config_st CONFIG; /* Configuration structure.
+typedef struct yk_ticket_st YK_TICKET; /* Ticket structure... */
+typedef struct yk_config_st YK_CONFIG; /* Configuration structure.
Other libraries provide access. */
-typedef struct nav_st NAV; /* Navigation structure.
+typedef struct yk_nav_st YK_NAV; /* Navigation structure.
Other libraries provide access. */
/*************************************************************************
* Functions to get and release the key itself.
*
****/
-extern YUBIKEY *yk_open_first_key(void); /* opens the first key available */
-extern int yk_close_key(YUBIKEY *k); /* closes a previously opened key */
+extern YK_KEY *yk_open_first_key(void); /* opens the first key available */
+extern int yk_close_key(YK_KEY *k); /* closes a previously opened key */
/*************************************************************************
*
*
****/
/* fetches key status into the structure given by `status' */
-extern int yk_get_status(YUBIKEY *k, STATUS *status /*, int forceUpdate */);
+extern int yk_get_status(YK_KEY *k, YK_STATUS *status /*, int forceUpdate */);
/*************************************************************************
*
/* writes the given configuration to the key. If the configuration is NULL,
zap the key configuration.
acc_code has to be provided of the key has a protecting access code. */
-extern int yk_write_config(YUBIKEY *k, CONFIG *cfg, unsigned char *acc_code);
+extern int yk_write_config(YK_KEY *k, YK_CONFIG *cfg, unsigned char *acc_code);
/*************************************************************************
*
#define YK_ENOSTATUS 0x07
#define YK_ENOTYETIMPL 0x08
-/*=======================================================================*
-
-/*************************************************************************
- **
- ** = = = = = = = = = B I G F A T W A R N I N G = = = = = = = = =
- **
- ** DO NOT USE THE FOLLOWING FUCTIONS DIRECTLY UNLESS YOU WRITE CORE ROUTINES!
- **
- ** These functions are declared here only to make sure they get defined
- ** correctly internally.
- **
- ** YOU HAVE BEEN WARNED!
- **
- ****/
-
-/*************************************************************************
- *
- * Functions to send and receive data to/from the key.
- *
- ****/
-extern int yk_read_from_key(YUBIKEY *k, uint8_t slot,
- void *buf, unsigned int bufsize,
- unsigned int *bufcount);
-extern int yk_write_to_key(YUBIKEY *k, uint8_t slot,
- const void *buf, int bufcount);
-
-/*************************************************************************
- *
- * Internal helper functions
- *
- ****/
-
-/* Swaps the two bytes between little and big endian on big endian machines */
-extern uint16_t endian_swap_16(uint16_t x);
-
#endif /* __YKCORE_H_INCLUDED__ */
--- /dev/null
+/* -*- mode:C; c-file-style: "bsd" -*- */
+/*
+ * Copyright (c) 2008, 2009, Yubico AB
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __YKCORE_LCL_H_INCLUDED__
+#define __YKCORE_LCL_H_INCLUDED__
+
+/* This is a hack to map official structure names (in ykcore.h) to
+ internal ones (in ykdef.h) */
+#define yk_key_st yubikey_st
+#define yk_status_st status_st
+#define yk_ticket_st ticket_st
+#define yk_config_st config_st
+#define yk_nav_st nav_st
+
+#include "ykcore.h"
+#include "ykdef.h"
+
+/*************************************************************************
+ **
+ ** = = = = = = = = = B I G F A T W A R N I N G = = = = = = = = =
+ **
+ ** DO NOT USE THE FOLLOWING FUCTIONS DIRECTLY UNLESS YOU WRITE CORE ROUTINES!
+ **
+ ** These functions are declared here only to make sure they get defined
+ ** correctly internally.
+ **
+ ** YOU HAVE BEEN WARNED!
+ **
+ ****/
+
+/*************************************************************************
+ *
+ * Functions to send and receive data to/from the key.
+ *
+ ****/
+extern int yk_read_from_key(YK_KEY *k, uint8_t slot,
+ void *buf, unsigned int bufsize,
+ unsigned int *bufcount);
+extern int yk_write_to_key(YK_KEY *k, uint8_t slot,
+ const void *buf, int bufcount);
+
+/*************************************************************************
+ *
+ * Internal helper functions
+ *
+ ****/
+
+/* Swaps the two bytes between little and big endian on big endian machines */
+extern uint16_t yk_endian_swap_16(uint16_t x);
+
+#endif /* __YKCORE_LCL_H_INCLUDED__ */
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "ykcore_lcl.h"
#include "ykdef.h"
#include "ykstatus.h"
-STATUS *ykds_alloc(void)
+YK_STATUS *ykds_alloc(void)
{
- STATUS *st = malloc(sizeof(STATUS));
+ YK_STATUS *st = malloc(sizeof(YK_STATUS));
if (!st) {
yk_errno = YK_ENOMEM;
}
return st;
}
-void ykds_free(STATUS *st)
+void ykds_free(YK_STATUS *st)
{
free(st);
}
-STATUS *ykds_static(void)
+YK_STATUS *ykds_static(void)
{
- static STATUS st;
+ static YK_STATUS st;
return &st;
}
-extern int ykds_version_major(const STATUS *st)
+extern int ykds_version_major(const YK_STATUS *st)
{
if (st)
return st->versionMajor;
yk_errno = YK_ENOSTATUS;
return 0;
}
-extern int ykds_version_minor(const STATUS *st)
+extern int ykds_version_minor(const YK_STATUS *st)
{
if (st)
return st->versionMinor;
yk_errno = YK_ENOSTATUS;
return 0;
}
-extern int ykds_version_build(const STATUS *st)
+extern int ykds_version_build(const YK_STATUS *st)
{
if (st)
return st->versionBuild;
yk_errno = YK_ENOSTATUS;
return 0;
}
-extern int ykds_pgm_seq(const STATUS *st)
+extern int ykds_pgm_seq(const YK_STATUS *st)
{
if (st)
return st->pgmSeq;
yk_errno = YK_ENOSTATUS;
return 0;
}
-extern int ykds_touch_level(const STATUS *st)
+extern int ykds_touch_level(const YK_STATUS *st)
{
if (st)
return st->touchLevel;
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef __YKDATA_H_INCLUDED__
-#define __YKDATA_H_INCLUDED__
+#ifndef __YKSTATUS_H_INCLUDED__
+#define __YKSTATUS_H_INCLUDED__
-#include "ykcore.h"
+#include <ykcore.h>
/* Allocate and free status structures */
-extern STATUS *ykds_alloc(void);
-extern void ykds_free(STATUS *st);
+extern YK_STATUS *ykds_alloc(void);
+extern void ykds_free(YK_STATUS *st);
/* Return static status structure, to be used for quick checks.
USE WITH CAUTION, as this is a SHARED OBJECT. */
-extern STATUS *ykds_static(void);
+extern YK_STATUS *ykds_static(void);
/* Accessor functions */
-extern int ykds_version_major(const STATUS *st);
-extern int ykds_version_minor(const STATUS *st);
-extern int ykds_version_build(const STATUS *st);
-extern int ykds_pgm_seq(const STATUS *st);
-extern int ykds_touch_level(const STATUS *st);
+extern int ykds_version_major(const YK_STATUS *st);
+extern int ykds_version_minor(const YK_STATUS *st);
+extern int ykds_version_build(const YK_STATUS *st);
+extern int ykds_pgm_seq(const YK_STATUS *st);
+extern int ykds_touch_level(const YK_STATUS *st);
-#endif /* __YKDATA_H_INCLUDED__ */
+#endif /* __YKSTATUS_H_INCLUDED__ */