From 79170d3de5f95da038e73f7e91c96f508826023f Mon Sep 17 00:00:00 2001 From: Donatien Garnier Date: Fri, 24 Aug 2018 13:15:23 +0100 Subject: [PATCH] Use nfc_tech_iso7816_app_t directly to handle ISO7816 applications --- features/nfc/nfc/ISO7816App.h | 146 ------------------ features/nfc/nfc/NFC.h | 4 +- features/nfc/nfc/NFCRemoteInitiator.h | 6 +- features/nfc/nfc/Type4RemoteInitiator.h | 3 +- .../nfc/source/nfc/Type4RemoteInitiator.cpp | 4 +- 5 files changed, 8 insertions(+), 155 deletions(-) delete mode 100644 features/nfc/nfc/ISO7816App.h diff --git a/features/nfc/nfc/ISO7816App.h b/features/nfc/nfc/ISO7816App.h deleted file mode 100644 index c5a43a8840..0000000000 --- a/features/nfc/nfc/ISO7816App.h +++ /dev/null @@ -1,146 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2018 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MBED_ISO7816_APP_H -#define MBED_ISO7816_APP_H - -#include -#include - -#include "NFCDefinitions.h" - -#include "nfc/acore/acore/ac_buffer.h" -#include "nfc/acore/acore/ac_buffer_reader.h" -#include "nfc/acore/acore/ac_buffer_builder.h" -#include "nfc/stack/tech/iso7816/iso7816_app.h" - -namespace mbed { -namespace nfc { - -/** - * @addtogroup nfc - * @{ - */ - -class Type4RemoteInitiator; - -/** - * This base class represents an ISO7816-4 application. - */ -class ISO7816App { -public: - /** - * This class describes an ISO7816-4 exchange (Command/Response). - */ - class Exchange { - public: - /** - * A Command APDU (Application Protocol Data Unit) . - */ - struct CAPDU { - uint8_t cla; ///< CLA - Instruction class - uint8_t ins; ///< INS - Instruction code - uint8_t p1; ///< P1 - First parameter - uint8_t p2; ///< P2 - Second parameter - ac_buffer_t dataIn; ///< Command data - size_t maxRespLength; ///< Maximum response length - }; - - /** - * A Response APDU (Application Protocol Data Unit) - */ - struct RAPDU { - ac_buffer_t dataOut; ///< Response data - uint16_t sw; ///< Status word - }; - - /** - * Access Command APDU. - * - * @return a const reference to the Command ADPU - */ - const CAPDU &command() const; - - /** - * Access Response APDU. - * - * @return a mutable reference to the Command ADPU - */ - 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(); - - private: - CAPDU _command; - RAPDU _response; - ISO7816App *_iso7816_app; - }; - - /** - * Construct ISO7816 app instance - */ - ISO7816App() {} - - /** - * ISO7816App destructor - */ - virtual ~ISO7816App(); - -private: - friend class Type4RemoteInitiator; - - /** - * 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 = 0; - - /** - * Called when the application is selected and before any exchange is performed. - */ - virtual void on_selected() = 0; - - /** - * Called when the application is deselected (or link is lost). - */ - virtual void on_deselected() = 0; - - /** - * 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) = 0; - - nfc_tech_iso7816_app_t _iso7816_app; -}; - -/** - * @} - */ - -} // namespace nfc -} // namespace mbed - -#endif diff --git a/features/nfc/nfc/NFC.h b/features/nfc/nfc/NFC.h index 1c957b77ac..38cfe23aa1 100644 --- a/features/nfc/nfc/NFC.h +++ b/features/nfc/nfc/NFC.h @@ -25,7 +25,7 @@ // NFC EEPROM #include "NFCEEPROM.h" -// ISO7816 App -#include "ISO7816App.h" +// Type 4 Remote Initiator +#include "Type4RemoteInitiator.h" #endif diff --git a/features/nfc/nfc/NFCRemoteInitiator.h b/features/nfc/nfc/NFCRemoteInitiator.h index d225d427db..7058a9ae6e 100644 --- a/features/nfc/nfc/NFCRemoteInitiator.h +++ b/features/nfc/nfc/NFCRemoteInitiator.h @@ -22,7 +22,7 @@ #include "NFCDefinitions.h" #include "NFCRemoteEndpoint.h" #include "NFCNDEFCapable.h" -#include "ISO7816App.h" +#include "stack/tech/iso7816/iso7816_app.h" namespace mbed { namespace nfc { @@ -82,9 +82,9 @@ public: /** * Register an ISO7816 application to be used by the initiator. * - * @param[in] application a pointer to an ISO7816App instance + * @param[in] application a pointer to an nfc_tech_iso7816_app_t instance as defined by the MuNFC stack */ - virtual void add_iso7816_application(ISO7816App *application) = 0; + virtual void add_iso7816_application(nfc_tech_iso7816_app_t *application) = 0; protected: virtual void connected(); diff --git a/features/nfc/nfc/Type4RemoteInitiator.h b/features/nfc/nfc/Type4RemoteInitiator.h index 104a361af9..301b535359 100644 --- a/features/nfc/nfc/Type4RemoteInitiator.h +++ b/features/nfc/nfc/Type4RemoteInitiator.h @@ -20,7 +20,6 @@ #include #include -#include "ISO7816App.h" #include "NFCNDEFCapable.h" #include "NFCRemoteInitiator.h" @@ -66,7 +65,7 @@ public: // NFCRemoteInitiator implementation virtual nfc_tag_type_t nfc_tag_type() const; virtual bool is_iso7816_supported() const; - virtual void add_iso7816_application(ISO7816App *application); + virtual void add_iso7816_application(nfc_tech_iso7816_app_t *application); // NFCNDEFCapable implementation virtual bool is_ndef_supported() const; diff --git a/features/nfc/source/nfc/Type4RemoteInitiator.cpp b/features/nfc/source/nfc/Type4RemoteInitiator.cpp index 51fc83e5f6..5d28482108 100644 --- a/features/nfc/source/nfc/Type4RemoteInitiator.cpp +++ b/features/nfc/source/nfc/Type4RemoteInitiator.cpp @@ -117,9 +117,9 @@ bool Type4RemoteInitiator::is_iso7816_supported() const return true; } -void Type4RemoteInitiator::add_iso7816_application(ISO7816App *application) +void Type4RemoteInitiator::add_iso7816_application(nfc_tech_iso7816_app_t *application) { - nfc_tech_iso7816_add_app(&_iso7816, &application->_iso7816_app); + nfc_tech_iso7816_add_app(&_iso7816, application); } bool Type4RemoteInitiator::is_ndef_supported() const