diff --git a/features/nfc/nfc/NFCController.h b/features/nfc/nfc/NFCController.h index 6a9eb6bb5a..2e82ba087f 100644 --- a/features/nfc/nfc/NFCController.h +++ b/features/nfc/nfc/NFCController.h @@ -86,7 +86,8 @@ namespace nfc { * * @param[in] driver a pointer to a NFCControllerDriver instance * @param[in] queue a pointer to the events queue to use - * @param[in] ndef_buffer_sz NDEF buffer size + * @param[in] ndef_buffer a bytes array used to store NDEF messages + * @param[in] ndef_buffer_sz the array size in bytes */ NFCController(NFCControllerDriver* driver, events::EventQueue* queue, uint8_t* ndef_buffer, size_t ndef_buffer_sz); @@ -167,6 +168,7 @@ namespace nfc { Timeout _timeout; Delegate* _delegate; bool _discovery_running; + uint8_t* _ndef_buffer; size_t _ndef_buffer_sz; }; diff --git a/features/nfc/nfc/NFCEEPROM.h b/features/nfc/nfc/NFCEEPROM.h index 17d028f65b..cb87e60a8e 100644 --- a/features/nfc/nfc/NFCEEPROM.h +++ b/features/nfc/nfc/NFCEEPROM.h @@ -119,8 +119,6 @@ namespace nfc { NFCEEPROMDriver* _driver; events::EventQueue* _queue; bool _initialized; - uint8_t* _ndef_buffer; - size_t _ndef_buffer_sz; nfc_eeprom_operation_t _current_op; buffer_t _ndef_buffer_reader; diff --git a/features/nfc/nfc/NFCRemoteInitiator.h b/features/nfc/nfc/NFCRemoteInitiator.h index 67c4208dd3..da02ff7ece 100644 --- a/features/nfc/nfc/NFCRemoteInitiator.h +++ b/features/nfc/nfc/NFCRemoteInitiator.h @@ -42,9 +42,10 @@ namespace nfc { public: /** * Create a NFCRemoteInitiator. - * + * @param[in] buffer a bytes array used to store NDEF messages + * @param[in] buffer_size the array size in bytes */ - NFCRemoteInitiator(); + NFCRemoteInitiator(uint8_t* buffer, size_t buffer_size); virtual ~NFCRemoteInitiator(); /** diff --git a/features/nfc/nfc/Type4RemoteInitiator.h b/features/nfc/nfc/Type4RemoteInitiator.h index 7c54adeb0f..7a0a34244c 100644 --- a/features/nfc/nfc/Type4RemoteInitiator.h +++ b/features/nfc/nfc/Type4RemoteInitiator.h @@ -37,14 +37,16 @@ namespace nfc { /** * This class is an implementation of the Type 4 tag application. */ - class Type4RemoteInitiator : public NFCRemoteInitiator, public NFCNDEFCapable { + class Type4RemoteInitiator : public NFCRemoteInitiator { private: /** * Create a Type4RemoteInitiator. * * @param[in] controller pointer to the NFCController instance that created this object + * @param[in] buffer a bytes array used to store NDEF messages + * @param[in] buffer_size the array size in bytes */ - Type4RemoteInitiator(NFCController* controller); + Type4RemoteInitiator(NFCController* controller, uint8_t* buffer, size_t buffer_size); // NFCRemoteEndpoint implementation virtual nfc_err_t connect(); diff --git a/features/nfc/source/nfc/NFCController.cpp b/features/nfc/source/nfc/NFCController.cpp index 81ac0e0528..2d748a6527 100644 --- a/features/nfc/source/nfc/NFCController.cpp +++ b/features/nfc/source/nfc/NFCController.cpp @@ -23,7 +23,7 @@ using namespace mbed; using namespace mbed::nfc; -NFCController::NFCController(NFCControllerDriver* driver, events::EventQueue* queue, size_t ndef_buffer_sz) : +NFCController::NFCController(NFCControllerDriver* driver, events::EventQueue* queue, uint8_t* ndef_buffer, size_t ndef_buffer_sz) : _driver(driver), _queue(queue), _transceiver(NULL), _scheduler(NULL), _delegate(NULL), _discovery_running(false), _ndef_buffer_sz(ndef_buffer_sz) { _driver->set_delegate(this); @@ -135,9 +135,13 @@ void NFCController::polling_callback(nfc_err_t ret) if( !transceiver_is_initiator_mode(_transceiver) ) { nfc_tech_t active_tech = transceiver_get_active_techs(_transceiver); if( active_tech.nfc_iso_dep_a || active_tech.nfc_iso_dep_b ) { - SharedPtr type4_remote_initiator( new Type4RemoteInitiator(_transceiver, _ndef_buffer_sz) ); - if( _delegate != NULL ) { - _delegate->on_nfc_initiator_discovered(type4_remote_initiator); + Type4RemoteInitiator type4_remote_initiator_ptr = new (std::nothrow) Type4RemoteInitiator(_transceiver, _ndef_buffer, _ndef_buffer_sz); + if( type4_remote_initiator_ptr == NULL ) { + // No memory :( + SharedPtr type4_remote_initiator( type4_remote_initiator_ptr ); + if( _delegate != NULL ) { + _delegate->on_nfc_initiator_discovered(type4_remote_initiator); + } } } } diff --git a/features/nfc/source/nfc/NFCRemoteInitiator.cpp b/features/nfc/source/nfc/NFCRemoteInitiator.cpp index a1373b5a04..a7a19172ae 100644 --- a/features/nfc/source/nfc/NFCRemoteInitiator.cpp +++ b/features/nfc/source/nfc/NFCRemoteInitiator.cpp @@ -16,18 +16,11 @@ #include "NFCRemoteInitiator.h" -#include "acore/buffer.h" -#include "acore/buffer_reader.h" -#include "acore/buffer_builder.h" - -#include "stack/transceiver/transceiver.h" -#include "stack/tech/iso7816/iso7816.h" -#include "stack/tech/iso7816/iso7816_app.h" - using namespace mbed; using namespace mbed::nfc; -NFCRemoteInitiator::NFCRemoteInitiator(NFCController* controller) : NFCRemoteEndpoint(controller) { +NFCRemoteInitiator::NFCRemoteInitiator(NFCController* controller, uint8_t* buffer, size_t buffer_size) : + NFCRemoteEndpoint(controller), NFCNDEFCapable(buffer, buffer_size) { } @@ -38,20 +31,6 @@ NFCRemoteInitiator::~NFCRemoteInitiator() { void NFCRemoteInitiator::set_remote_initiator_delegate(Delegate* delegate) { - + _delegate = delegate; } -nfc_tag_type_t NFCRemoteInitiator::nfc_tag_type() const -{ - -} - -bool NFCRemoteInitiator::is_iso7816_supported() const -{ - -} - -void NFCRemoteInitiator::add_iso7816_application(ISO7816App* application) -{ - -} diff --git a/features/nfc/source/nfc/NFCTarget.cpp b/features/nfc/source/nfc/NFCTarget.cpp new file mode 100644 index 0000000000..a21587a3c8 --- /dev/null +++ b/features/nfc/source/nfc/NFCTarget.cpp @@ -0,0 +1,29 @@ +/* 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. + */ + +#include "NFCTarget.h" + +using namespace mbed; +using namespace mbed::nfc; + +NFCTarget::NFCTarget(uint8_t* buffer, size_t buffer_size) : + NFCNDEFCapable(buffer, buffer_size) { + +} + +NFCTarget::~NFCTarget() { + +} diff --git a/features/nfc/source/nfc/Type4RemoteInitiator.cpp b/features/nfc/source/nfc/Type4RemoteInitiator.cpp index 560feebfcd..4fa5e22a83 100644 --- a/features/nfc/source/nfc/Type4RemoteInitiator.cpp +++ b/features/nfc/source/nfc/Type4RemoteInitiator.cpp @@ -28,7 +28,8 @@ using namespace mbed; using namespace mbed::nfc; -Type4RemoteInitiator::Type4RemoteInitiator(NFCController* controller) : +Type4RemoteInitiator::Type4RemoteInitiator(NFCController* controller, uint8_t* buffer, size_t buffer_size) : + NFCRemoteInitiator(ndef_buffer, ndef_buffer_sz), _controller(controller), _is_connected(false) , _is_disconnected(false), _apps(NULL) { // Init ISO7816 nfc_tech_iso7816_init(&_iso7816, _controller->transceiver(), &Type4RemoteInitiator::s_disconnected_callback, this);