Skip to content

Commit

Permalink
Replace USB-CCID (smartcard) by USB-HID
Browse files Browse the repository at this point in the history
Remove PCSC dependencies which is a bit hard (not user friendly) to install on linux and Mac

Split Ledger logic and device IO
  • Loading branch information
cslashm committed Sep 10, 2018
1 parent 91c7d68 commit c926461
Show file tree
Hide file tree
Showing 13 changed files with 624 additions and 252 deletions.
30 changes: 21 additions & 9 deletions CMakeLists.txt
Expand Up @@ -427,7 +427,7 @@ if(STATIC AND NOT IOS)
endif()
endif()

find_package(PCSC)
find_package(HIDAPI)

add_definition_if_library_exists(c memset_s "string.h" HAVE_MEMSET_S)
add_definition_if_library_exists(c explicit_bzero "strings.h" HAVE_EXPLICIT_BZERO)
Expand Down Expand Up @@ -465,14 +465,14 @@ endif()
include_directories(${LIBUNWIND_INCLUDE})
link_directories(${LIBUNWIND_LIBRARY_DIRS})

# Final setup for libpcsc
if (PCSC_FOUND)
message(STATUS "Using PCSC include dir at ${PCSC_INCLUDE_DIR}")
add_definitions(-DHAVE_PCSC)
include_directories(${PCSC_INCLUDE_DIR})
link_directories(${LIBPCSC_LIBRARY_DIRS})
else (PCSC_FOUND)
message(STATUS "Could not find PCSC")
# Final setup for hid
if (HIDAPI_FOUND)
message(STATUS "Using HIDAPI include dir at ${HIDAPI_INCLUDE_DIR}")
add_definitions(-DHAVE_HIDAPI)
include_directories(${HIDAPI_INCLUDE_DIR})
link_directories(${LIBHIDAPI_LIBRARY_DIRS})
else (HIDAPI_FOUND)
message(STATUS "Could not find HIDAPI")
endif()

if(MSVC)
Expand Down Expand Up @@ -832,6 +832,18 @@ endif()

list(APPEND EXTRA_LIBRARIES ${CMAKE_DL_LIBS})

if (HIDAPI_FOUND)
if (APPLE)
find_library(COREFOUNDATION CoreFoundation)
find_library(IOKIT IOKit)
list(APPEND EXTRA_LIBRARIES ${IOKIT})
list(APPEND EXTRA_LIBRARIES ${COREFOUNDATION})
endif()
if (WIN32)
list(APPEND EXTRA_LIBRARIES setupapi)
endif()
endif()

option(USE_READLINE "Build with GNU readline support." ON)
if(USE_READLINE)
find_package(Readline)
Expand Down
46 changes: 46 additions & 0 deletions cmake/FindHIDAPI.cmake
@@ -0,0 +1,46 @@
# - try to find HIDAPI library
# from http://www.signal11.us/oss/hidapi/
#
# Cache Variables: (probably not for direct use in your scripts)
# HIDAPI_INCLUDE_DIR
# HIDAPI_LIBRARY
#
# Non-cache variables you might use in your CMakeLists.txt:
# HIDAPI_FOUND
# HIDAPI_INCLUDE_DIRS
# HIDAPI_LIBRARIES
#
# Requires these CMake modules:
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

find_library(HIDAPI_LIBRARY
NAMES hidapi hidapi-libusb)

find_path(HIDAPI_INCLUDE_DIR
NAMES hidapi.h
PATH_SUFFIXES
hidapi)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(HIDAPI
DEFAULT_MSG
HIDAPI_LIBRARY
HIDAPI_INCLUDE_DIR)

if(HIDAPI_FOUND)
set(HIDAPI_LIBRARIES "${HIDAPI_LIBRARY}")

set(HIDAPI_INCLUDE_DIRS "${HIDAPI_INCLUDE_DIR}")
endif()

mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_LIBRARY)
53 changes: 0 additions & 53 deletions cmake/FindPCSC.cmake

This file was deleted.

19 changes: 14 additions & 5 deletions src/device/CMakeLists.txt
Expand Up @@ -32,18 +32,27 @@ set(device_sources
log.cpp
)

if(PCSC_FOUND)
set(device_sources ${device_sources} device_ledger.cpp)
if(HIDAPI_FOUND)
set(device_sources
${device_sources}
device_ledger.cpp
device_io_hid.cpp
)
endif()

set(device_headers
device.hpp
device_io.hpp
device_default.hpp
log.hpp
)

if(PCSC_FOUND)
set(device_headers ${device_headers} device_ledger.hpp)
if(HIDAPI_FOUND)
set(device_headers
${device_headers}
device_ledger.hpp
device_io_hid.hpp
)
endif()

set(device_private_headers)
Expand All @@ -65,7 +74,7 @@ monero_add_library(device

target_link_libraries(device
PUBLIC
${PCSC_LIBRARIES}
${HIDAPI_LIBRARIES}
cncrypto
ringct_basic
${OPENSSL_CRYPTO_LIBRARIES}
Expand Down
4 changes: 2 additions & 2 deletions src/device/device.cpp
Expand Up @@ -29,7 +29,7 @@

#include "device.hpp"
#include "device_default.hpp"
#ifdef HAVE_PCSC
#ifdef WITH_DEVICE_LEDGER
#include "device_ledger.hpp"
#endif
#include "misc_log_ex.h"
Expand All @@ -46,7 +46,7 @@ namespace hw {
std::map<std::string, std::unique_ptr<device>> registry;
s_devices() : registry() {
hw::core::register_all(registry);
#ifdef HAVE_PCSC
#ifdef WITH_DEVICE_LEDGER
hw::ledger::register_all(registry);
#endif
};
Expand Down
3 changes: 2 additions & 1 deletion src/device/device.hpp
Expand Up @@ -48,11 +48,12 @@
#include "crypto/chacha.h"
#include "ringct/rctTypes.h"


#ifndef USE_DEVICE_LEDGER
#define USE_DEVICE_LEDGER 1
#endif

#if !defined(HAVE_PCSC)
#if !defined(HAVE_HIDAPI)
#undef USE_DEVICE_LEDGER
#define USE_DEVICE_LEDGER 0
#endif
Expand Down
56 changes: 56 additions & 0 deletions src/device/device_io.hpp
@@ -0,0 +1,56 @@
// Copyright (c) 2017-2018, The Monero Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. 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.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// 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 HOLDER 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.
//




#pragma once


namespace hw {
namespace io {

class device_io {

public:

device_io() {};
~device_io() {};

virtual void init() = 0;
virtual void release() = 0;

virtual void connect(void *parms) = 0;
virtual void disconnect() = 0;
virtual bool connected() const = 0;

virtual int exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len) = 0;
};
};
};

0 comments on commit c926461

Please sign in to comment.