Add documemtation for ISO7816App

pull/7822/head
Donatien Garnier 2018-08-08 14:41:37 +01:00
parent f6a0cb3ae2
commit b14e18d170
1 changed files with 72 additions and 18 deletions

View File

@ -25,47 +25,101 @@
namespace mbed { namespace mbed {
namespace nfc { namespace nfc {
/**
* @addtogroup nfc
* @{
*/
/**
* This base class represents an ISO7816-4 application.
*/
class ISO7816App { class ISO7816App {
/**
* This class describes an ISO7816-4 exchange (Command/Response).
*/
class Exchange { class Exchange {
public: public:
/**
* A Command APDU (Application Protocol Data Unit) .
*/
struct CAPDU struct CAPDU
{ {
uint8_t cla; uint8_t cla; ///< CLA - Instruction class
uint8_t ins; uint8_t ins; ///< INS - Instruction code
uint8_t p1; uint8_t p1; ///< P1 - First parameter
uint8_t p2; uint8_t p2; ///< P2 - Second parameter
ac_buffer_t dataIn; ac_buffer_t dataIn; ///< Command data
size_t maxRespLength; size_t maxRespLength; ///< Maximum response length
}; };
/**
* A Response APDU (Application Protocol Data Unit)
*/
struct RAPDU struct RAPDU
{ {
ac_buffer_t dataOut; ac_buffer_t dataOut; ///< Response data
uint16_t sw; uint16_t sw; ///< Status word
}; };
/**
* Access Command APDU.
*
* @return a const reference to the Command ADPU
*/
const CAPDU& command() const; const CAPDU& command() const;
/**
* Access Response APDU.
*
* @return a mutable reference to the Command ADPU
*/
RAPDU& response(); RAPDU& response();
/**
* Respond to command.
*
* @return NFC_OK if the response could be sent back successfully, or an error code otherwise
*/
nfc_err_t respond(); nfc_err_t respond();
private: private:
Command _command; CAPDU _command;
Response _response; RAPDU _response;
ISO7816Application* _app; ISO7816App* _app;
}; };
struct Delegate { private:
virtual void on_selected() {} /**
* Retrieve the application's identifier (AID).
* AIDs are composed of a RID (Registered Application Provider Identifier) that needs to be registered and a custom suffix.
*
* @return a pointer to a const buffer containing the application's identifier (AID).
*/
virtual const ac_buffer_t* get_aid() const;
virtual void on_deselected() {} /**
* Called when the application is selected and before any exchange is performed.
*/
virtual void on_selected();
virtual void on_exchange(Exchange* exchange) {} /**
}; * Called when the application is deselected (or link is lost).
*/
void set_delegate(Delegate* delegate); virtual void on_deselected();
/**
* Called when an exchange is performed.
* The application must respond using the respond() method of the Exchange class.
*
* @param[in] exchange an instance of the Exchange class populated with the C-APDU which was received
*/
virtual void on_exchange(Exchange* exchange);
}; };
/**
* @}
*/
} // namespace nfc } // namespace nfc
} // namespace mbed } // namespace mbed