Keyple C++  0.9.0
Keyple, an Open Source SDK for Ticketing
Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
keyple::core::seproxy::plugin::AbstractLocalReader Class Referenceabstract

#include <AbstractLocalReader.h>

Inherits keyple::core::seproxy::plugin::AbstractReader.

Inherited by keyple::core::seproxy::plugin::AbstractObservableLocalReader.

Public Member Functions

 AbstractLocalReader (const std::string &pluginName, const std::string &readerName)
 
virtual ~AbstractLocalReader ()=default
 
bool isSePresent () override
 
virtual bool isLogicalChannelOpen () const final
 
void addSeProtocolSetting (std::shared_ptr< SeProtocol > seProtocol, const std::string &protocolRule) override
 
virtual void setSeProtocolSetting (const std::map< std::shared_ptr< SeProtocol >, std::string > &protocolSetting) override
 
virtual std::shared_ptr< SelectionStatusopenLogicalChannel (std::shared_ptr< SeSelector > seSelector)
 
std::shared_ptr< SelectionStatusopenLogicalChannelAndSelect (std::shared_ptr< SeSelector > seSelector)
 
virtual std::vector< std::shared_ptr< SeResponse > > processSeRequests (const std::vector< std::shared_ptr< SeRequest >> &seRequests, const MultiSeRequestProcessing &multiSeRequestProcessing, const ChannelControl &channelControl) override
 
virtual std::shared_ptr< SeResponseprocessSeRequest (const std::shared_ptr< SeRequest > seRequest, const ChannelControl &channelControl) override
 
virtual void terminateSeCommunication ()=0
 
- Public Member Functions inherited from keyple::core::seproxy::plugin::AbstractReader
std::vector< std::shared_ptr< SeResponse > > transmitSeRequests (const std::vector< std::shared_ptr< SeRequest >> &seRequests, const MultiSeRequestProcessing &multiSeRequestProcessing, const ChannelControl &channelControl) override
 
std::shared_ptr< SeResponsetransmitSeRequest (std::shared_ptr< SeRequest > seRequest, const ChannelControl &channelControl) override
 
const std::string & getPluginName () const
 
const std::string & getName () const override
 
- Public Member Functions inherited from keyple::core::seproxy::plugin::AbstractSeProxyComponent
 AbstractSeProxyComponent (const std::string &name)
 
virtual ~AbstractSeProxyComponent ()=default
 
const std::string & getName () const
 
void setParameters (const std::map< const std::string, const std::string > &parameters)
 
virtual void setParameter (const std::string &key, const std::string &value)=0
 
- Public Member Functions inherited from keyple::core::seproxy::message::ProxyReader
virtual ~ProxyReader ()
 
- Public Member Functions inherited from keyple::core::seproxy::SeReader
virtual ~SeReader ()
 
virtual const TransmissionModegetTransmissionMode () const =0
 
virtual bool operator== (const SeReader &o) const
 
- Public Member Functions inherited from keyple::core::seproxy::ProxyElement
virtual ~ProxyElement ()=default
 
virtual const std::map< const std::string, const std::string > & getParameters () const =0
 
virtual void setParameter (const std::string &key, const std::string &value)=0
 
virtual void setParameters (const std::map< const std::string, const std::string > &parameters)
 

Protected Member Functions

virtual bool checkSePresence ()=0
 
void closeLogicalAndPhysicalChannels ()
 
virtual const std::vector< uint8_t > & getATR ()=0
 
virtual void setForceGetDataFlag (bool forceGetDataFlag)
 
virtual void openPhysicalChannel ()=0
 
virtual void closePhysicalChannel ()=0
 
virtual bool isPhysicalChannelOpen ()=0
 
void closeLogicalChannel ()
 
virtual bool protocolFlagMatches (const std::shared_ptr< SeProtocol > protocolFlag)=0
 
std::shared_ptr< ApduResponseprocessApduRequest (std::shared_ptr< ApduRequest > apduRequest)
 
virtual std::vector< uint8_t > transmitApdu (const std::vector< uint8_t > &apduIn)=0
 
const std::map< std::shared_ptr< SeProtocol >, std::string > & getProtocolsMap () const
 
- Protected Member Functions inherited from keyple::core::seproxy::plugin::AbstractReader
 AbstractReader (const std::string &pluginName, const std::string &name)
 
virtual ~AbstractReader ()=default
 

Static Protected Member Functions

static bool startsWith (const std::vector< uint8_t > &source, const std::vector< uint8_t > &match)
 

Additional Inherited Members

- Protected Attributes inherited from keyple::core::seproxy::plugin::AbstractReader
std::shared_ptr< DefaultSelectionsRequestmDefaultSelectionsRequest
 
ObservableReader::NotificationMode mNotificationMode
 

Detailed Description

Manage the loop processing for SeRequest transmission in a set and for SeResponse reception in a set

Constructor & Destructor Documentation

◆ AbstractLocalReader()

keyple::core::seproxy::plugin::AbstractLocalReader::AbstractLocalReader ( const std::string &  pluginName,
const std::string &  readerName 
)

Reader constructor

Force the definition of a name through the use of super method.

Initialize the time measurement

Parameters
pluginNamethe name of the plugin that instantiated the reader
readerNamethe name of the reader

◆ ~AbstractLocalReader()

virtual keyple::core::seproxy::plugin::AbstractLocalReader::~AbstractLocalReader ( )
virtualdefault

Member Function Documentation

◆ addSeProtocolSetting()

void keyple::core::seproxy::plugin::AbstractLocalReader::addSeProtocolSetting ( std::shared_ptr< SeProtocol seProtocol,
const std::string &  protocolRule 
)
overridevirtual

Defines the protocol setting Map to allow SE to be differentiated according to their communication protocol.

Parameters
seProtocolthe protocol key identifier to be added to the plugin internal list
protocolRulea string use to define how to identify the protocol

Implements keyple::core::seproxy::SeReader.

◆ checkSePresence()

virtual bool keyple::core::seproxy::plugin::AbstractLocalReader::checkSePresence ( )
protectedpure virtual

Wrapper for the native method of the plugin specific local reader to verify the presence of the SE.

This method must be implemented by the ProxyReader plugin (e.g. Pcsc reader plugin).

This method is invoked by isSePresent.

Returns
true if the SE is present
Exceptions
KeypleReaderIOExceptionif the communication with the reader or the SE has failed

Implemented in keyple::plugin::stub::StubReaderImpl, and keyple::plugin::pcsc::PcscReaderImpl.

◆ closeLogicalAndPhysicalChannels()

void keyple::core::seproxy::plugin::AbstractLocalReader::closeLogicalAndPhysicalChannels ( )
protected

Close both logical and physical channels

◆ closeLogicalChannel()

void keyple::core::seproxy::plugin::AbstractLocalReader::closeLogicalChannel ( )
protected

Close the logical channel.

◆ closePhysicalChannel()

virtual void keyple::core::seproxy::plugin::AbstractLocalReader::closePhysicalChannel ( )
protectedpure virtual

Closes the current physical channel.

This method must be implemented by the ProxyReader plugin (e.g. Pcsc/Nfc/Omapi Reader).

Exceptions
KeypleReaderIOExceptionif the communication with the reader or the SE has failed

Implemented in keyple::plugin::stub::StubReaderImpl, and keyple::plugin::pcsc::PcscReaderImpl.

◆ getATR()

virtual const std::vector<uint8_t>& keyple::core::seproxy::plugin::AbstractLocalReader::getATR ( )
protectedpure virtual

This abstract method must be implemented by the derived class in order to provide the SE ATR when available.

Gets the SE Answer to reset

Returns
ATR returned by the SE or reconstructed by the reader (contactless)

Implemented in keyple::plugin::stub::StubReaderImpl, and keyple::plugin::pcsc::PcscReaderImpl.

◆ getProtocolsMap()

const std::map< std::shared_ptr< SeProtocol >, std::string > & keyple::core::seproxy::plugin::AbstractLocalReader::getProtocolsMap ( ) const
protected
Returns
the Map containing the protocol definitions set by addSeProtocolSetting and setSeProtocolSetting

◆ isLogicalChannelOpen()

bool keyple::core::seproxy::plugin::AbstractLocalReader::isLogicalChannelOpen ( ) const
finalvirtual

Tells if a logical channel is open

Returns
true if the logical channel is open

◆ isPhysicalChannelOpen()

virtual bool keyple::core::seproxy::plugin::AbstractLocalReader::isPhysicalChannelOpen ( )
protectedpure virtual

Tells if the physical channel is open or not

This method must be implemented by the ProxyReader plugin (e.g. Pcsc/Nfc/Omapi Reader).

Returns
true is the channel is open

Implemented in keyple::plugin::stub::StubReaderImpl, and keyple::plugin::pcsc::PcscReaderImpl.

◆ isSePresent()

bool keyple::core::seproxy::plugin::AbstractLocalReader::isSePresent ( )
overridevirtual

Check the presence of a SE

This method is recommended for non-observable readers.

When the card is not present the logical and physical channels status may be refreshed through a call to the cardRemoved method.

Returns
true if the SE is present
Exceptions
KeypleReaderIOExceptionif the communication with the reader or the SE has failed

Implements keyple::core::seproxy::SeReader.

Reimplemented in keyple::core::seproxy::plugin::AbstractObservableLocalReader.

◆ openLogicalChannel()

std::shared_ptr< SelectionStatus > keyple::core::seproxy::plugin::AbstractLocalReader::openLogicalChannel ( std::shared_ptr< SeSelector seSelector)
virtual

Build a select application command, transmit it to the SE and deduct the SelectionStatus.

Parameters
seSelectorthe targeted application SE selector
Returns
the SelectionStatus containing the actual selection result (ATR and/or FCI and the matching status flag).
Exceptions
KeypleReaderIOExceptionif the communication with the reader or the SE has failed

◆ openLogicalChannelAndSelect()

std::shared_ptr< SelectionStatus > keyple::core::seproxy::plugin::AbstractLocalReader::openLogicalChannelAndSelect ( std::shared_ptr< SeSelector seSelector)

Open (if needed) a physical channel and try to establish a logical channel.

The logical opening is done either by sending a Select Application command (AID based selection) or by checking the current ATR received from the SE (ATR based selection).

If the selection is successful, the logical channel is considered open. On the contrary, if the selection fails, the logical channel remains closed.

Parameters
seSelectorthe SE Selector: either the AID of the application to select or an ATR selection regular expression
Returns
a keyple::core::seproxy::message::SelectionStatus object containing the SE ATR, the SE FCI and a flag giving the selection process result. When ATR or FCI are not available, they are set to null but they can't be both null at the same time.
Exceptions
KeypleReaderIOExceptionif the communication with the reader or the SE has failed

◆ openPhysicalChannel()

virtual void keyple::core::seproxy::plugin::AbstractLocalReader::openPhysicalChannel ( )
protectedpure virtual

This abstract method must be implemented by the derived class in order to provide a selection and ATR filtering mechanism.

The Selector provided in argument holds all the needed data to handle the Application Selection and ATR matching process and build the resulting SelectionStatus.

Parameters
seSelectorthe SE selector
Returns
the SelectionStatus Attempts to open the physical channel
Exceptions
KeypleReaderIOExceptionif the communication with the reader or the SE has failed

Implemented in keyple::plugin::stub::StubReaderImpl, and keyple::plugin::pcsc::PcscReaderImpl.

◆ processApduRequest()

std::shared_ptr< ApduResponse > keyple::core::seproxy::plugin::AbstractLocalReader::processApduRequest ( std::shared_ptr< ApduRequest apduRequest)
protected

Transmits an ApduRequest and receives the ApduResponse

The time measurement is carried out and logged with the detailed information of the exchanges (TRACE level).

Parameters
apduRequestAPDU request
Returns
APDU response
Exceptions
KeypleReaderIOExceptionif the communication with the reader or the SE has failed

◆ processSeRequest()

std::shared_ptr< SeResponse > keyple::core::seproxy::plugin::AbstractLocalReader::processSeRequest ( const std::shared_ptr< SeRequest seRequest,
const ChannelControl channelControl 
)
overridevirtual

Executes a request made of one or more Apdus and receives their answers. The selection of the application is handled.

The physical channel is closed if requested.

Parameters
seRequestthe SeRequest
channelControlindicates if the channel has to be closed at the end of the processing
Returns
the SeResponse to the SeRequest
Exceptions
KeypleReaderIOExceptionif the communication with the reader or the SE has failed

/!\ C++ vs. Java: this function is protected in Java

Implements keyple::core::seproxy::plugin::AbstractReader.

◆ processSeRequests()

std::vector< std::shared_ptr< SeResponse > > keyple::core::seproxy::plugin::AbstractLocalReader::processSeRequests ( const std::vector< std::shared_ptr< SeRequest >> &  seRequests,
const MultiSeRequestProcessing multiSeRequestProcessing,
const ChannelControl channelControl 
)
overridevirtual

Do the transmission of all requests according to the protocol flag selection logic.

The received responses are returned as list of keyple::core::seproxy::message::SeResponse The requests are ordered at application level and the responses match this order.
When a request is not matching the current PO, the response responses pushed in the response List object is set to null.

Parameters
seRequeststhe request list
multiSeRequestProcessingthe multi se processing mode
channelControlindicates if the channel has to be closed at the end of the processing
Returns
the response list
Exceptions
KeypleReaderIOExceptionif the communication with the reader or the SE has failed

/!\ C++ vs. Java: this function is protected in Java

Implements keyple::core::seproxy::plugin::AbstractReader.

◆ protocolFlagMatches()

virtual bool keyple::core::seproxy::plugin::AbstractLocalReader::protocolFlagMatches ( const std::shared_ptr< SeProtocol protocolFlag)
protectedpure virtual

Test if the current protocol matches the provided protocol flag.

The method must be implemented by the ProxyReader plugin.

The protocol flag is used to retrieve from the protocolsMap the String used to differentiate this particular protocol. (e.g. in PC/SC the only way to identify the SE protocol is to analyse the ATR returned by the reader [ISO SE and memory card SE have specific ATR], in Android Nfc the SE protocol can be deduced with the TagTechnology interface).

Parameters
protocolFlagthe protocol flag
Returns
true if the current protocol matches the provided protocol flag
Exceptions
KeypleReaderIOExceptionif the communication with the reader or the SE has failed

Implemented in keyple::plugin::stub::StubReaderImpl, and keyple::plugin::pcsc::PcscReaderImpl.

◆ setForceGetDataFlag()

void keyple::core::seproxy::plugin::AbstractLocalReader::setForceGetDataFlag ( bool  forceGetDataFlag)
protectedvirtual

Set the flag that enables the execution of the Get Data hack to get the FCI

This method should called by the reader plugins that need this specific behavior (ex. OMAPI)

The default value for the forceGetDataFlag is false, thus only specific readers plugins should call this method.

Parameters
forceGetDataFlagtrue or false

◆ setSeProtocolSetting()

void keyple::core::seproxy::plugin::AbstractLocalReader::setSeProtocolSetting ( const std::map< std::shared_ptr< SeProtocol >, std::string > &  protocolSetting)
overridevirtual

Complete the current setting map with the provided map

Parameters
protocolSettingAlex: removed that function to avoid using a shared_ptr to SeProtocol (astract class, therefore cannot be used in a set/map)

Implements keyple::core::seproxy::SeReader.

◆ startsWith()

bool keyple::core::seproxy::plugin::AbstractLocalReader::startsWith ( const std::vector< uint8_t > &  source,
const std::vector< uint8_t > &  match 
)
staticprotected

Indicates whether this array of bytes starts with this other one

Parameters
sourcethe byte array to examine
matchthe byte array to compare in source
Returns
true if the starting bytes of source equal match

◆ terminateSeCommunication()

virtual void keyple::core::seproxy::plugin::AbstractLocalReader::terminateSeCommunication ( )
pure virtual

Method to be implemented by child classes in order to handle the needed actions when terminating the communication with a SE (closing of the physical channel, initiating a removal sequence, etc.)

Implemented in keyple::core::seproxy::plugin::AbstractObservableLocalReader.

◆ transmitApdu()

virtual std::vector<uint8_t> keyple::core::seproxy::plugin::AbstractLocalReader::transmitApdu ( const std::vector< uint8_t > &  apduIn)
protectedpure virtual

Transmits a single APDU and receives its response.

This abstract method must be implemented by the ProxyReader plugin (e.g. Pcsc, Nfc). The implementation must handle the case where the SE response is 61xy and execute the appropriate get response command.

Parameters
apduInbyte buffer containing the ingoing data
Returns
apduResponse byte buffer containing the outgoing data.
Exceptions
KeypleReaderIOExceptionif the communication with the reader or the SE has failed

Implemented in keyple::plugin::stub::StubReaderImpl, and keyple::plugin::pcsc::PcscReaderImpl.


The documentation for this class was generated from the following files: