Replace USB-CCID (smartcard) by USB-HID

Remove PCSC dependencies which is a bit hard (not user friendly) to install on linux and Mac

Split Ledger logic and device IO
This commit is contained in:
cslashm 2018-08-01 09:24:53 +02:00
parent 5c637c7910
commit bb6e3bbc0f
13 changed files with 645 additions and 253 deletions

View file

@ -33,13 +33,7 @@
#include <cstddef>
#include <string>
#include "device.hpp"
#ifdef WIN32
#include <winscard.h>
#define MAX_ATR_SIZE 33
#else
#include <PCSC/winscard.h>
#include <PCSC/wintypes.h>
#endif
#include "device_io_hid.hpp"
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
@ -89,22 +83,23 @@ namespace hw {
mutable boost::recursive_mutex device_locker;
mutable boost::mutex command_locker;
//PCSC management
std::string full_name;
SCARDCONTEXT hContext;
SCARDHANDLE hCard;
DWORD length_send;
BYTE buffer_send[BUFFER_SEND_SIZE];
DWORD length_recv;
BYTE buffer_recv[BUFFER_RECV_SIZE];
unsigned int id;
//IO
hw::io::device_io_hid hw_device;
std::string full_name;
unsigned int length_send;
unsigned char buffer_send[BUFFER_SEND_SIZE];
unsigned int length_recv;
unsigned char buffer_recv[BUFFER_RECV_SIZE];
unsigned int sw;
unsigned int id;
void logCMD(void);
void logRESP(void);
unsigned int exchange(unsigned int ok=0x9000, unsigned int mask=0xFFFF);
unsigned int exchange(unsigned int ok=0x9000, unsigned int mask=0xFFFF);
void reset_buffer(void);
int set_command_header(BYTE ins, BYTE p1 = 0x00, BYTE p2 = 0x00);
int set_command_header_noopt(BYTE ins, BYTE p1 = 0x00, BYTE p2 = 0x00);
void send_simple(BYTE ins, BYTE p1 = 0x00);
int set_command_header(unsigned char ins, unsigned char p1 = 0x00, unsigned char p2 = 0x00);
int set_command_header_noopt(unsigned char ins, unsigned char p1 = 0x00, unsigned char p2 = 0x00);
void send_simple(unsigned char ins, unsigned char p1 = 0x00);
// hw running mode
device_mode mode;
@ -127,7 +122,7 @@ namespace hw {
device_ledger(const device_ledger &device) = delete ;
device_ledger& operator=(const device_ledger &device) = delete;
explicit operator bool() const override {return this->hContext != 0;}
explicit operator bool() const override {return this->connected(); }
bool reset(void);
@ -141,6 +136,7 @@ namespace hw {
bool release() override;
bool connect(void) override;
bool disconnect() override;
bool connected(void) const;
bool set_mode(device_mode mode) override;