LibLogicalAccess  2.5.0
An Open Source RFID Library
Loading...
Searching...
No Matches
libusbreaderunit.hpp
Go to the documentation of this file.
1
7#ifndef LOGICALACCESS_LIBUSBREADERUNIT_HPP
8#define LOGICALACCESS_LIBUSBREADERUNIT_HPP
9
12#include <logicalaccess/plugins/readers/libusb/lla_readers_libusb_api.hpp>
15
16#include <libusb.h>
17#include <map>
18
19namespace logicalaccess
20{
21#define READER_LIBUSB "LibUSB"
22#define LIBUSB_DEVICE_YUBIKEY_VENDORID 0x1050
23#define LIBUSB_DEVICE_ONLYKEY_VENDORID 0x1D50
24#define HID_SET_REPORT 0x09
25
26class LibUSBReaderCardAdapter;
27class LibUSBReaderProvider;
28
32class LLA_READERS_LIBUSB_API LibUSBReaderUnit : public ReaderUnit
33{
34 public:
38 LibUSBReaderUnit(struct libusb_device* device);
39
43 virtual ~LibUSBReaderUnit();
44
49 std::string getName() const override;
50
51 void setName(const std::string& name);
52
57 std::string getConnectedName() override;
58
63 void setCardType(std::string cardType) override;
64
74 bool waitInsertion(unsigned int maxwait) override;
75
84 bool waitRemoval(unsigned int maxwait) override;
85
91 std::shared_ptr<Chip> createChip(std::string type) override;
92
93 std::vector<unsigned char> getNumber(std::shared_ptr<Chip> chip) override;
94
99 std::shared_ptr<Chip> getSingleChip() override;
100
105 std::vector<std::shared_ptr<Chip>> getChipList() override;
106
114 bool connect() override;
115
122 void disconnect() override;
123
128 bool isConnected() override;
129
134 bool connectToReader() override;
135
139 void disconnectFromReader() override;
140
145 std::string getReaderSerialNumber() override;
146
151 virtual std::shared_ptr<LibUSBReaderCardAdapter> getDefaultLibUSBReaderCardAdapter();
152
157 void serialize(boost::property_tree::ptree &parentNode) override;
158
163 void unSerialize(boost::property_tree::ptree &node) override;
164
169 std::shared_ptr<LibUSBReaderUnitConfiguration> getLibUSBConfiguration()
170 {
171 return std::dynamic_pointer_cast<LibUSBReaderUnitConfiguration>(getConfiguration());
172 }
173
178 std::shared_ptr<LibUSBReaderProvider> getLibUSBReaderProvider() const;
179
184 struct libusb_device *getDevice() const
185 {
186 return d_device;
187 }
188
189 struct libusb_device_handle *getHandle() const
190 {
191 return d_device_handle;
192 }
193
194 void setVendorID(uint16_t vendor_id);
195
196 protected:
200 struct libusb_device *d_device;
201
202 struct libusb_device *d_tmp_device;
203
204 struct libusb_device_handle* d_device_handle;
205
206 uint16_t d_vendor_id;
207
208 uint16_t d_product_id;
209
210 std::string d_serial_number;
211
212 std::string d_product;
213
214 std::string d_name;
215
216 libusb_device* look_for_device(uint16_t vendor_id, uint16_t product_id);
217
218 private:
222 template <typename TargetFunction, typename... Args>
223 int libusb_safe_call(TargetFunction fct, Args... arg)
224 {
225 int ret = fct(arg...);
226 if (ret < 0)
227 {
229 "LibUSB error: " + std::string(libusb_strerror(d_device)));
230 }
231 return ret;
232 }
233};
234}
235
236#endif
A liblogicalaccess exception class.
Definition: myexception.hpp:22
The LibUSB reader unit class.
Definition: libusbreaderunit.hpp:33
std::string d_serial_number
Definition: libusbreaderunit.hpp:210
uint16_t d_vendor_id
Definition: libusbreaderunit.hpp:206
struct libusb_device_handle * getHandle() const
Definition: libusbreaderunit.hpp:189
struct libusb_device * getDevice() const
Get the LibUSB device.
Definition: libusbreaderunit.hpp:184
std::shared_ptr< LibUSBReaderUnitConfiguration > getLibUSBConfiguration()
Get the LibUSB reader unit configuration.
Definition: libusbreaderunit.hpp:169
struct libusb_device * d_device
The LibUSB device.
Definition: libusbreaderunit.hpp:200
uint16_t d_product_id
Definition: libusbreaderunit.hpp:208
int libusb_safe_call(TargetFunction fct, Args... arg)
Definition: libusbreaderunit.hpp:223
std::string d_product
Definition: libusbreaderunit.hpp:212
struct libusb_device_handle * d_device_handle
Definition: libusbreaderunit.hpp:204
std::string d_name
Definition: libusbreaderunit.hpp:214
struct libusb_device * d_tmp_device
Definition: libusbreaderunit.hpp:202
The card types.
Definition: readerunit.hpp:42
LibUSB Reader unit configuration.
Logging header.
#define THROW_EXCEPTION_WITH_LOG(type, msg,...)
Definition: logs.hpp:237
Definition: asn1.hpp:9
Reader unit.