LibLogicalAccess  2.5.0
An Open Source RFID Library
Loading...
Searching...
No Matches
pcscreaderunit.hpp
Go to the documentation of this file.
1
7#ifndef LOGICALACCESS_PCSCREADERUNIT_HPP
8#define LOGICALACCESS_PCSCREADERUNIT_HPP
9
16
17namespace logicalaccess
18{
22class LLA_READERS_PCSC_API PCSCReaderUnit : public ISO7816ReaderUnit
23{
24 public:
28 explicit PCSCReaderUnit(const std::string &name);
29
33 virtual ~PCSCReaderUnit();
34
39 std::string getName() const override;
40
45 void setName(const std::string &name);
46
51 std::string getConnectedName() override;
52
57 virtual PCSCReaderUnitType getPCSCType() const;
58
63 void setCardType(std::string cardType) override
64 {
65 d_card_type = cardType;
66 }
67
77 bool waitInsertion(unsigned int maxwait) override;
78
87 bool waitRemoval(unsigned int maxwait) override;
88
96 bool connect() override;
97
108 virtual bool connect(PCSCShareMode share_mode);
109
113 void disconnect() override;
114
119 bool isConnected() override;
120
125 bool connectToReader() override;
126
130 void disconnectFromReader() override;
131
136 const SCARDHANDLE &getHandle() const;
137
142 unsigned long getActiveProtocol() const;
143
150 PCSCShareMode getShareMode() const;
151
157 std::shared_ptr<Chip> createChip(std::string type) override;
158
163 std::shared_ptr<Chip> getSingleChip() override;
164
169 std::vector<std::shared_ptr<Chip>> getChipList() override;
170
177 virtual ByteVector getCardSerialNumber();
178
183 std::string getReaderSerialNumber() override;
184
191 const ByteVector &getATR() const;
192
197 virtual std::shared_ptr<PCSCReaderCardAdapter> getDefaultPCSCReaderCardAdapter();
198
204 virtual std::shared_ptr<ReaderCardAdapter> getReaderCardAdapter(std::string type);
205
210 void serialize(boost::property_tree::ptree &parentNode) override;
211
216 void unSerialize(boost::property_tree::ptree &node) override;
217
222 std::shared_ptr<ReaderUnitConfiguration> getConfiguration() override;
223
228 void setConfiguration(std::shared_ptr<ReaderUnitConfiguration> config) override;
229
235 virtual void changeReaderKey(std::shared_ptr<ReaderMemoryKeyStorage> keystorage,
236 const ByteVector &key);
237
242 std::shared_ptr<PCSCReaderUnitConfiguration> getPCSCConfiguration()
243 {
244 return std::dynamic_pointer_cast<PCSCReaderUnitConfiguration>(getConfiguration());
245 }
246
247 std::shared_ptr<PCSCReaderProvider> getPCSCReaderProvider() const;
248
249 static std::shared_ptr<PCSCReaderUnit>
250 createPCSCReaderUnit(const std::string &readerName);
251
258 void makeProxy(std::shared_ptr<PCSCReaderUnit> readerUnit,
259 std::shared_ptr<PCSCReaderUnitConfiguration> readerUnitConfig);
260
268 virtual void getT_CL_ISOType(bool &isTypeA, bool &isTypeB);
269
274 virtual void cardConnected()
275 {
276 }
277
281 std::shared_ptr<PCSCReaderUnit> getProxyReaderUnit() const;
282
283
284 void setCardTechnologies(const TechnoBitset &bitset) override;
285
286 TechnoBitset getCardTechnologies() override;
287
288 std::shared_ptr<LCDDisplay> getLCDDisplay() override;
289
290 void setLCDDisplay(std::shared_ptr<LCDDisplay> d) override;
291
292 std::shared_ptr<LEDBuzzerDisplay> getLEDBuzzerDisplay() override;
293
294 void setLEDBuzzerDisplay(std::shared_ptr<LEDBuzzerDisplay> lbd) override;
295
296 ReaderServicePtr getService(const ReaderServiceType &type) override;
297
298 void beginTransaction();
299
300 void endTransaction(DWORD dwDisposition = SCARD_LEAVE_CARD);
301
306 void reset(int action = 0);
307
308 protected:
315 bool reconnect(int action = 0) override;
316
326 std::shared_ptr<Chip> adjustChip(std::shared_ptr<Chip> c);
327
328 std::shared_ptr<ResultChecker> createDefaultResultChecker() const override;
329
330 std::shared_ptr<CardProbe> createCardProbe() override;
331
332 void configure_mifareplus_chip(std::shared_ptr<Chip> c,
333 std::shared_ptr<Commands> &commands,
334 std::shared_ptr<ResultChecker> &resultChecker) const;
335
343 void detect_mifareplus_security_level(std::shared_ptr<Chip> c);
344
348 std::string d_name;
349
353 std::string d_connectedName;
354
359 void setSingleChip(std::shared_ptr<Chip> chip);
360
364 std::shared_ptr<SAMChip> getSAMChip() override;
365
369 void setSAMChip(std::shared_ptr<SAMChip> t) override;
370
374 std::shared_ptr<ISO7816ReaderUnit> getSAMReaderUnit() override;
375
379 void setSAMReaderUnit(std::shared_ptr<ISO7816ReaderUnit> t) override;
380
381 // Internal helper for waitInsertion
382 using SPtrStringVector = std::vector<std::shared_ptr<std::string>>;
383 using ReaderStateVector = std::vector<SCARD_READERSTATE>;
384
389 std::tuple<SPtrStringVector, ReaderStateVector> prepare_poll_parameters();
390
395 void waitInsertion_create_proxy(const std::string &reader_name);
396
404 virtual bool process_insertion(const std::string &cardType, unsigned int maxwait,
405 const ElapsedTimeCounter &elapsed);
406
407 public:
412 void setup_pcsc_connection(PCSCShareMode share_mode);
413
418 void teardown_pcsc_connection();
419
420 protected:
424 std::unique_ptr<PCSCConnection> connection_;
425
430
434 std::shared_ptr<PCSCReaderUnit> d_proxyReaderUnit;
435};
436}
437
438#endif
Definition: utils.hpp:26
The ISO7816 reader unit class.
Definition: iso7816readerunit.hpp:25
The PC/SC reader unit class.
Definition: pcscreaderunit.hpp:23
std::string d_name
The reader unit name.
Definition: pcscreaderunit.hpp:348
std::shared_ptr< PCSCReaderUnit > d_proxyReaderUnit
The proxy reader unit.
Definition: pcscreaderunit.hpp:434
std::string d_connectedName
The reader unit connected name.
Definition: pcscreaderunit.hpp:353
virtual void cardConnected()
Definition: pcscreaderunit.hpp:274
std::shared_ptr< PCSCReaderUnitConfiguration > getPCSCConfiguration()
Get the PC/SC reader unit configuration.
Definition: pcscreaderunit.hpp:242
std::vector< std::shared_ptr< std::string > > SPtrStringVector
Definition: pcscreaderunit.hpp:382
std::unique_ptr< PCSCConnection > connection_
Definition: pcscreaderunit.hpp:424
void setCardType(std::string cardType) override
Set the card type.
Definition: pcscreaderunit.hpp:63
std::vector< SCARD_READERSTATE > ReaderStateVector
Definition: pcscreaderunit.hpp:383
ByteVector atr_
Definition: pcscreaderunit.hpp:429
std::vector< uint8_t > ByteVector
Definition: lla_fwd.hpp:80
Definition: asn1.hpp:9
PCSCReaderUnitType
The reader unit types.
Definition: pcscreaderunitconfiguration.hpp:54
ReaderServiceType
Definition: reader_service.hpp:10
uint32_t TechnoBitset
Definition: techno.hpp:25
std::shared_ptr< ReaderService > ReaderServicePtr
Definition: lla_fwd.hpp:67
PCSCShareMode
Share mode enumeration.
Definition: pcscreaderunitconfiguration.hpp:35
PC/SC Reader unit configuration.