Firmware library for the X-NUCLEO-NFC01A1 Dynamic NFC Tag board.

Dependencies:   M24SR

Dependents:   NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more

Fork of X_NUCLEO_NFC01A1 by ST Expansion SW Team

X-NUCLEO-NFC01A1 Dynamic NFC Tag Expansion Board Firmware Package

Introduction

This firmware package includes Components Device Drivers, Board Support Package and example applications for STMicroelectronics X-NUCLEO-NFC01A1 Dynamic NFC Tag Expansion Board based on M24SR.

Firmware Library

Class X_NUCLEO_NFC01A1 is intended to represent the Dynamic NFC Tag Expansion Board with the same name.
It provides an API to access to the M24SR component and to the three onboard LEDs.
It is intentionally implemented as a singleton because only one X_NUCLEO_NFC01A1 at a time might be deployed in a HW component stack.
The library also provides an implementation of the NDEF library API for M24SR, providing an simple way to read/write NDEF formatted messages from/to the M24SR dynamic NFC tag.

Example applications

1. Hello World
2. Asynchronous Hello World

Interfaces/Nfc_class.h

Committer:
giovannivisentini
Date:
2016-02-01
Revision:
23:d07138541feb
Parent:
21:ccc4f3fed4b3
Child:
24:9f98eafa2d39

File content as of revision 23:d07138541feb:

/**
 ******************************************************************************
 * @file    Nfc_class.h
 * @author  ST Central Labs
 * @version V1.0.0
 * @date    13-April-2015
 * @brief   This file contains the abstract class describing the interface of a
 *          nfc component.
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *   1. Redistributions of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright notice,
 *      this list of conditions and the following disclaimer in the documentation
 *      and/or other materials provided with the distribution.
 *   3. Neither the name of STMicroelectronics nor the names of its contributors
 *      may be used to endorse or promote products derived from this software
 *      without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 ******************************************************************************
 */


/* Generated with Stm32CubeTOO -----------------------------------------------*/

/* Define to prevent from recursive inclusion --------------------------------*/

#ifndef __NFC_CLASS_H
#define __NFC_CLASS_H


/* Includes ------------------------------------------------------------------*/

#include "Component_class.h"
#include "../Common/nfc.h"

/* Classes  ------------------------------------------------------------------*/

/**
 * An abstract class for Nfc components.
 * This component has two operation mode, sync or async.
 * In the sync mode each function will return only when the command is complete.
 * In the async mode the function will only send the command and the answer will be notify
 * thought a callback.
 * The default behavior is sync mode.
 * For enable the async mode you have to call the ManageI2CGPO(I2C_ANSWER_READY) function.
 * When the component notify an interrupt you have to call the  {@link ManageInterrupt} function.
 * Note that when you call ManageI2CGPO with other parameters the component will return in sync mode.
 */
class Nfc : public Component
{
public:

	/**
	 * Possible password to set.
	 */
	typedef enum{
		ReadPwd,   //!< Password to use before read the tag
		WritePwd,  //!< Password to use before write the tag
		I2CPwd,    //!< Root password, used only thought nfc
	}PasswordType_t;

	/**
	 * Function that will be called when an interrupt is fired,
	 * this function must be set if you want use the component in async mode.
	 */
	typedef void(*gpoEventCallback)(void);

	/**
	 * Object that contains all the callback fired by this class, each command has its own callback.
	 * The callback default implementation is an empty function.
	 */
	class Callback{
	public:

		/** call when GetSession or KillSession finish */
		virtual void onSessionOpen(Nfc *nfc,NFC_StatusTypeDef status){
			(void)nfc; (void)status;
		}

		virtual void onDeselect(Nfc *nfc,NFC_StatusTypeDef status){
			(void)nfc; (void)status;
		}

		virtual void onSelectedApplication(Nfc *nfc,NFC_StatusTypeDef status){
			(void)nfc; (void)status;
		}

		virtual void onSelectedCCFile(Nfc *nfc,NFC_StatusTypeDef status){
			(void)nfc; (void)status;
		}

		virtual void onSelectedNDEFFile(Nfc *nfc,NFC_StatusTypeDef status){
			(void)nfc; (void)status;
		}

		virtual void onSelectedSystemFile(Nfc *nfc,NFC_StatusTypeDef status){
			(void)nfc; (void)status;
		}

		virtual void onReadByte(Nfc *nfc,NFC_StatusTypeDef status,
				uint16_t offset,uint8_t *readByte, uint16_t nReadByte){
			(void)nfc; (void)status;(void)offset; (void)readByte; (void)nReadByte;
		}

		virtual void onUpdatedBinary(Nfc *nfc,NFC_StatusTypeDef status,uint16_t offset,
				uint8_t *writeByte,uint16_t nWriteByte){
			(void)nfc; (void)status; (void)writeByte; (void)nWriteByte; (void)offset;
		}

		virtual void onVerifyed(Nfc *nfc,NFC_StatusTypeDef status,PasswordType_t uPwdId,
				const uint8_t *pwd){
			(void)nfc; (void)status;(void)uPwdId;(void)pwd;
		}

		virtual void onManageI2CGPO(Nfc *nfc,NFC_StatusTypeDef status,NFC_GPO_MGMT newStatus){
			(void)nfc; (void)status;(void)newStatus;
		}

		virtual void onManageRFGPO(Nfc *nfc,NFC_StatusTypeDef status,NFC_GPO_MGMT newStatus){
			(void)nfc; (void)status;(void)newStatus;
		}

		virtual void onChangeReferenceData(Nfc *nfc ,NFC_StatusTypeDef status,PasswordType_t type,
				uint8_t *data){
			(void)nfc; (void)status;(void)type;(void)data;
		}

		virtual void onEnableVerificationRequirement(Nfc *nfc ,NFC_StatusTypeDef status,PasswordType_t type){
			(void)nfc; (void)status;(void)type;
		}

		virtual void onDisableVerificationRequirement(Nfc *nfc , NFC_StatusTypeDef status,PasswordType_t type){
			(void)nfc; (void)status;(void)type;
		}

		virtual void onEnablePermanentState(Nfc *nfc, NFC_StatusTypeDef status, PasswordType_t type){
			(void)nfc; (void)status;(void)type;
		}

		virtual void onDisablePermanentState(Nfc *nfc, NFC_StatusTypeDef status, PasswordType_t type){
			(void)nfc; (void)status;(void)type;
		}

		virtual void onReadId(Nfc *nfc, NFC_StatusTypeDef status, uint8_t *id){
					(void)nfc; (void)status;(void)id;
		}

		virtual void onEnableReadPassword(Nfc *nfc, NFC_StatusTypeDef status,const uint8_t *newPwd){
			(void)nfc; (void)status;(void)newPwd;
		}

		virtual void onEnableWritePassword(Nfc *nfc, NFC_StatusTypeDef status,const uint8_t *newPwd){
			(void)nfc; (void)status;(void)newPwd;
		}

		virtual void onDisableReadPassword(Nfc *nfc, NFC_StatusTypeDef status){
			(void)nfc; (void)status;
		}

		virtual void onDisableWritePassword(Nfc *nfc, NFC_StatusTypeDef status){
			(void)nfc; (void)status;
		}

		virtual void onDisableAllPassword(Nfc *nfc, NFC_StatusTypeDef status){
			(void)nfc; (void)status;
		}

		virtual void onEnableReadOnly(Nfc *nfc,NFC_StatusTypeDef status){
			(void)nfc; (void)status;
		}

		virtual void onEnableWriteOnly(Nfc *nfc,NFC_StatusTypeDef status){
			(void)nfc; (void)status;
		}

		virtual void onDisableReadOnly(Nfc *nfc,NFC_StatusTypeDef status){
			(void)nfc; (void)status;
		}

		virtual void onDisableWriteOnly(Nfc *nfc,NFC_StatusTypeDef status){
			(void)nfc; (void)status;
		}

		virtual ~Callback(){};
	};

	Nfc():mCallback(&defaultCallback),
			mComponentCallback(NULL){ }

	/**
	 * Open a I2C connection with the tag if an RF connection isn't already open.
	 * @return operation status
	 */
	virtual NFC_StatusTypeDef GetSession(void) = 0;
	
	/**
	 * Force to open an I2C connection , abort the RF connection.
	 * @return NFC_SUCCESS if the session is acquired
	 */
	virtual NFC_StatusTypeDef ForceGetSession(void) = 0;

	/**
	 * Close an I2C connection.
	 * @return NFC_SUCCESS if the session is release
	 */
	virtual NFC_StatusTypeDef Deselect(void) = 0;

	/**
	 * Select the application file.
	 * @return NFC_SUCCESS if the application is selected
	 */
	virtual NFC_StatusTypeDef SelectApplication(void) = 0;

	/**
	 * Select the CC file.
	 * @return NFC_SUCCESS if the CC file is selected.
	 */
	virtual NFC_StatusTypeDef SelectCCfile(void) = 0;

	/**
	 * Select the NDEF file.
	 * @param NDEFfileId File id to open.
	 * @return NFC_SUCCESS if the file is selected
	 */
	virtual NFC_StatusTypeDef SelectNDEFfile(uint16_t NDEFfileId) = 0;

	/**
	 * Select the system file.
	 * @return NFC_SUCCESS if the system file is selected
	 */
	virtual NFC_StatusTypeDef SelectSystemfile(void) = 0;

	/**
	 * Read data from the tag.
	 * @param Offset Read offset.
	 * @param NbByteToRead Number of bytes to read.
	 * @param[out] pBufferRead Buffer to store the read data into.
	 * @return NFC_SUCCESS if no errors 
	 */
	virtual NFC_StatusTypeDef ReadBinary(uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead) = 0;

	/**
	 * Write data to the tag.
	 * @param Offset Write offset.
	 * @param NbByteToWrite Number of bytes to write.
	 * @param pDataToWrite Buffer to write.
	 * @return NFC_SUCCESS if no errors
	 */
	virtual NFC_StatusTypeDef UpdateBinary(uint16_t Offset, uint8_t NbByteToWrite, uint8_t *pDataToWrite) = 0;

	/**
	 * Check that the password is correct.
	 * @param uPwdId Password type.
	 * @param NbPwdByte Password size ( must be 0x10).
	 * @param pPwd Password buffer.
	 * @return NFC_SUCCESS if no errors and write/read permission granted
	 */
	virtual NFC_StatusTypeDef Verify(PasswordType_t uPwdId, uint8_t NbPwdByte,const uint8_t *pPwd) = 0;

	/**
	 * Replace the read or write password.
	 * @param uPwdId Password to change.
	 * @param pPwd New password.
	 * @return NFC_SUCCESS if no errors
	 */
	virtual NFC_StatusTypeDef ChangeReferenceData(PasswordType_t uPwdId,const uint8_t *pPwd) = 0;
	
	/**
	 *	Activate NDEF file password protection.
	 *  When this command is successful, read or write access to the NDEF file is protected by a 128-bit password.
	 *  @param uReadOrWrite Read or write password.
	 *  @return NFC_SUCCESS if no errors
	 */
	virtual NFC_StatusTypeDef EnableVerificationRequirement(PasswordType_t uReadOrWrite) = 0;
	
	/**
     * Deactivate NDEF file password protection.
     * When this command is successful, read or write access to the NDEF file is granted.
     * with no security enforcement.
	 * @param uReadOrWrite Read or write password.
	 * @return NFC_SUCCESS if no errors
	 */     
	virtual NFC_StatusTypeDef DisableVerificationRequirement(PasswordType_t uReadOrWrite) = 0;
	
	/**
	 * Same as {@link NFC#ReadBinary}, however permitting to read more bytes than available.
	 * @param Offset read offset.
	 * @param NbByteToRead Number of bytes to read.
	 * @param[out] pBufferRead Buffer to store the read data into.
	 * @return NFC_SUCCESS if no errors
	 */
	virtual NFC_StatusTypeDef STReadBinary(uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead) = 0;
	
	/**
	 * Set the tag as read/write only, stored in the eeprom.
	 * @param  uReadOrWrite ReadPwd if write only, WritePwd if read only.
	 * @return NFC_SUCCESS if no errors
	 */
	virtual NFC_StatusTypeDef EnablePermanentState(PasswordType_t uReadOrWrite) = 0;
	
	/**
	 * Unset the tag as read/write only, stored in the eeprom.
	 * @param  uReadOrWrite ReadPwd if write only, WritePwd if read only.
	 * @return NFC_SUCCESS if no errors
	 * @par Caller must have I2Csuper user permissions to call this function.
	 */
	virtual NFC_StatusTypeDef DisablePermanentState(PasswordType_t uReadOrWrite) = 0;
	
	/**
	 * Set the gpo output pin.
	 * @param uSetOrReset New pin status.
 	 * @return NFC_SUCCESS if no errors
	 */
	virtual NFC_StatusTypeDef StateControl(uint8_t uSetOrReset) = 0;
	
	/**
	 * @brief  This function configures GPO for I2C session.
	 * @param  GPO_I2Cconfig GPO configuration to set.
 	 * @return NFC_SUCCESS if no errors
 	 * @par if the configuration is I2C_ANSWER_READY, the component will start to work
 	 * in async mode.
	 */
	virtual NFC_StatusTypeDef ManageI2CGPO(NFC_GPO_MGMT GPO_I2Cconfig) = 0;
	
	/**
 	* @brief  This function configures GPO for RF session.
 	* @param  GPO_RFconfig GPO configuration to set.
  	* @return NFC_SUCCESS if no errors
 	*/
	virtual NFC_StatusTypeDef ManageRFGPO(uint8_t GPO_RFconfig) = 0;
	
	/**
	 * @brief  This function enables or disables the RF communication.
	 * @param  OnOffChoice GPO configuration to set.
  	 * @return NFC_SUCCESS if no errors
	 */
	virtual NFC_StatusTypeDef RFConfig(uint8_t OnOffChoice) = 0;

	/**
	 * Generates a negative pulse on the GPO pin.
	 * Pulse starts immediately after the command is issued and ends at the end of the RF response.
  	 * @return NFC_SUCCESS if no errors
	 */
	virtual NFC_StatusTypeDef SendInterrupt(void)=0;

	/**
	 * Change the function to call when a command ends.
	 * @param commandCallback Object containing the callback, if NULL it will use empty callback
	 */
	void SetCallback(Callback *commandCallback){
		if(commandCallback!=NULL)
			mCallback = commandCallback;
		else
			mCallback = &defaultCallback;
	}

	/**
	 * Function to call when the component fire an interrupt.
	 * @return last operation status
	 */
	virtual NFC_StatusTypeDef ManageEvent()=0;


	///////////////////////HIGHT LEVEL /UTILITY FUNCTION ////////////////////////////////////

	/**
	 * Enable the request of a password before reading the tag.
	 * @param  pCurrentWritePassword Current password
	 * @param  pNewPassword Password to request before reading the tag.
	 * @return return NFC_SUCCESS if no errors
	 * @par The password must have a length of 16 chars.
	 */
	NFC_StatusTypeDef EnableReadPassword(const uint8_t* pCurrentWritePassword,
				const uint8_t* pNewPassword) {

		//enable the callback for change the gpo
		mComponentCallback = &mChangePasswordRequestStatusCallback;
		mChangePasswordRequestStatusCallback.setTask(ReadPwd,pNewPassword);

		return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword);
	}

	/**
	 * Disable the request of a password before reading the tag.
	 * @param  pCurrentWritePassword Current password
	 * @return return NFC_SUCCESS if no errors
	 * @par The password must have a length of 16 chars.
	 */
	NFC_StatusTypeDef DisableReadPassword(const uint8_t* pCurrentWritePassword) {
		mComponentCallback = &mChangePasswordRequestStatusCallback;
		mChangePasswordRequestStatusCallback.setTask(ReadPwd,NULL);

		return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword);
	}

	/**
	 * Enable the request of a password before writing to the tag.
	 * @param  pCurrentWritePassword Current password
	 * @param  pNewPassword Password to request before reading the tag.
	 * @return return NFC_SUCCESS if no errors
	 * @par The password must have a length of 16 chars.
	 */
	NFC_StatusTypeDef EnableWritePassword(const uint8_t* pCurrentWritePassword,
				uint8_t* pNewPassword) {
		//enable the callback for change the gpo
		mComponentCallback = &mChangePasswordRequestStatusCallback;
		mChangePasswordRequestStatusCallback.setTask(WritePwd,pNewPassword);

		return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword);
	}

	/**
	 * Disable the request of a password before writing the tag.
	 * @param  pCurrentWritePassword Current password.
	 * @return return NFC_SUCCESS if no errors
	 * @par The password must have a length of 16 chars.
	 */
	NFC_StatusTypeDef DisableWritePassword(const uint8_t* pCurrentWritePassword) {
		mComponentCallback = &mChangePasswordRequestStatusCallback;
		mChangePasswordRequestStatusCallback.setTask(WritePwd,NULL);

		return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword);
	}

	/**
	 * @brief   This function disables both read and write passwords.
	 * @param	pSuperUserPassword I2C super user password.
	 * @return  return NFC_SUCCESS if no errors
	 * @par The password must have a length of 16 chars.
	 */
	NFC_StatusTypeDef DisableAllPassword(const uint8_t* pSuperUserPassword){
		mComponentCallback = &mRemoveAllPasswordCallback;
		return Verify(Nfc::I2CPwd, 0x10, pSuperUserPassword);
	}

	/**
	 * @brief   This function enables read only mode.
	 * @param	pCurrentWritePassword Write password is needed to enable read only mode.
	 * @return  return NFC_SUCCESS if no errors
	 * @par The password must have a length of 16 chars.
	 */
	NFC_StatusTypeDef EnableReadOnly(const uint8_t* pCurrentWritePassword){

		mComponentCallback = &mChangeAccessStateCallback;
		//disable write = read only
		mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::WRITE,false);

		return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword);
	}

	/**
	 * @brief   This function disables read only mode.
	 * @param	pCurrentWritePassword Write password is needed to disable read only mode.
	 * @return  return NFC_SUCCESS if no errors
	 * @par The password must have a length of 16 chars.
	 */
	NFC_StatusTypeDef DisableReadOnly(const uint8_t* pCurrentWritePassword) {
		mComponentCallback = &mChangeAccessStateCallback;
		mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::WRITE,true);
		return Verify(Nfc::I2CPwd, 0x10,pCurrentWritePassword);
	}


	/**
	 * @brief   This function enables write only mode.
	 * @param	pCurrentWritePassword Write password is needed to enable write only mode.
	 * @return  return NFC_SUCCESS if no errors
	 * @par The password must have a length of 16 chars.
	 */
	NFC_StatusTypeDef EnableWriteOnly(const uint8_t* pCurrentWritePassword) {

		mComponentCallback = &mChangeAccessStateCallback;
		//disable read = enable write only
		mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::READ,false);

		return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword);

	}

	/**
	 * @brief   This function disables write only mode.
	 * @param	pCurrentWritePassword Write password is needed to disable write only mode.
	 * @return  return NFC_SUCCESS if no errors
	 * @par The password must have a length of 16 chars.
	 */
	NFC_StatusTypeDef DisableWriteOnly(const uint8_t* pCurrentWritePassword) {
		mComponentCallback = &mChangeAccessStateCallback;
		mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::READ,true);
		return Verify(Nfc::I2CPwd, 0x10, pCurrentWritePassword);
	}

	virtual ~Nfc(){};

protected:
		/** object containing the callback to use*/
		Callback *mCallback;

		/**
		 * Object with private callback used for hide height level commands
		 * that require more than one low level command.
		 * This object has an height priority comparing the user callback
		 */
		Nfc::Callback *mComponentCallback;

		/**
		 * get the callback object to use
		 * @return callback object to use
		 */
		Nfc::Callback * getCallback(){
			if(mComponentCallback!=NULL)
				return mComponentCallback;
			return mCallback;
		}//getCallback

private:
	/** object containing empty callback to use in the default case*/
	Callback defaultCallback;


	/**
	 * This class permit to enable/disable the password request to read/write into the tag
	 * This class is equivalent to call the method:
	 * To enable the request:
	 * <ul>
	 *   <li> Verify </li>
	 *   <li> ChangeReferenceData </li>
	 *   <li> EnablePermanentState </li>
	 * </ul>
	 * To disable the request:
	 * <ul>
	 *   <li> Verify </li>
	 *   <li> DisableVerificationRequirement </li>
	 * </ul>
	 */
	class ChangePasswordRequestStatusCallback : public Nfc::Callback{

		public:

			/**
			 * Build the chain of callback.
			 * @param parent object where send the command
			 */
			ChangePasswordRequestStatusCallback():
				mNewPwd(NULL),mType(I2CPwd),mEnable(false){}

			/**
			 * Set the password to enable/disable.
			 * @param type Type of password to enable/disable.
			 * @param newPwd Array of 16bytes with the new password, if null the request will be disabled.
			 */
			void setTask(PasswordType_t type, const uint8_t *newPwd){
				mNewPwd=newPwd;
				mType=type;
				mEnable=newPwd!=NULL;
			}//setTask

			virtual void onVerifyed(Nfc *nfc, NFC_StatusTypeDef status,PasswordType_t ,
					const uint8_t *){
				if(status!=NFC_SUCCESS)
					return onFinishCommand(nfc,status);
				if(mEnable)
					nfc->ChangeReferenceData(mType,mNewPwd);
				else
					nfc->DisableVerificationRequirement(mType);
			}

			virtual void onDisableVerificationRequirement(Nfc *nfc,
					NFC_StatusTypeDef status, PasswordType_t ){
				onFinishCommand(nfc,status);
			}

			virtual void onChangeReferenceData(Nfc *nfc, NFC_StatusTypeDef status,
					PasswordType_t type,
					uint8_t *){
				if(status==NFC_SUCCESS)
					nfc->EnablePermanentState(type);
				else
					onFinishCommand(nfc,status);
			}

			virtual void onEnablePermanentState(Nfc *nfc, NFC_StatusTypeDef status,
					PasswordType_t ){
				onFinishCommand(nfc,status);
			}


		private:

			/**
			 * Remove the private callback and call the user callback.
			 * @param nfc Object where the command is run.
			 * @param status Command status.
			 */
			void onFinishCommand(Nfc *nfc,NFC_StatusTypeDef status){
				nfc->mComponentCallback=NULL;

				if(mEnable){
					if(mType==ReadPwd){
						nfc->getCallback()->onEnableReadPassword(nfc,status,mNewPwd);
					}else
						nfc->getCallback()->onEnableWritePassword(nfc,status,mNewPwd);
				}else{
					if(mType==ReadPwd){
						nfc->getCallback()->onDisableReadPassword(nfc,status);
					}else
						nfc->getCallback()->onDisableWritePassword(nfc,status);
				}//if-else enable
			}//onFinish

			const uint8_t *mNewPwd;
			Nfc::PasswordType_t mType;
			bool mEnable;

		};


		/**
		 * Object containing the callback chain needed to change the password request
		 */
		ChangePasswordRequestStatusCallback mChangePasswordRequestStatusCallback;
		friend class ChangePasswordRequestStatusCallback;

		/**
		 * This class permit to disable all the password request to read/write into the tag
		 * This class is equivalent to call the methods:
		 * <ul>
		 *   <li> Verify(i2c) </li>
		 *   <li> DisablePermanentState(Read) </li>
		 *   <li> DisablePermanentState(write) </li>
		 *   <li> DisableVerificationRequirement(Read) </li>
		 *   <li> DisableVerificationRequirement(write) </li>
		 *   <li> ChangeReferenceData(Read) </li>
		 *   <li> ChangeReferenceData(write) </li>
		 * </ul>
		 */
		class RemoveAllPasswordCallback : public Nfc::Callback{

			/**
			 * Store the default password used for open a super user session
			 * it will be set as default read/write password
			 */
			const uint8_t *mI2CPwd;

			public:

				/**
				 * Build the chain of callback.
				 * @param parent object where send the command
				 */
				RemoveAllPasswordCallback():mI2CPwd(NULL){}

				virtual void onVerifyed(Nfc *nfc,NFC_StatusTypeDef status,
						PasswordType_t,const uint8_t* data){
					if(status!=NFC_SUCCESS)
						return onFinishCommand(nfc,status);
					mI2CPwd = data;
					nfc->DisablePermanentState(ReadPwd);
				}

				virtual void onDisablePermanentState(Nfc *nfc , NFC_StatusTypeDef status,
						PasswordType_t type){
					if(status!=NFC_SUCCESS)
						return onFinishCommand(nfc,status);
					if(type==ReadPwd)
						nfc->DisablePermanentState(WritePwd);
					else
						nfc->DisableVerificationRequirement(ReadPwd);
				}

				virtual void onDisableVerificationRequirement(Nfc *nfc ,
						NFC_StatusTypeDef status,PasswordType_t type){
					if(status!=NFC_SUCCESS)
						return onFinishCommand(nfc,status);
					if(type==ReadPwd)
						nfc->DisableVerificationRequirement(WritePwd);
					else
						nfc->ChangeReferenceData(ReadPwd,mI2CPwd);
				}

				virtual void onChangeReferenceData(Nfc *nfc ,NFC_StatusTypeDef status,PasswordType_t type,
						uint8_t *data){
					if(status!=NFC_SUCCESS)
						return onFinishCommand(nfc,status);
					if(type==ReadPwd)
						nfc->ChangeReferenceData(WritePwd,data);
					else
						onFinishCommand(nfc,status);
				}

			private:

				/**
				 * Remove the private callback and call the onDisableAllPassword callback.
				 * @param nfc Object where the command is run.
				 * @param status Command status.
				 */
				void onFinishCommand(Nfc *nfc,NFC_StatusTypeDef status){
					nfc->mComponentCallback=NULL;
					mI2CPwd=NULL;
					nfc->getCallback()->onDisableAllPassword(nfc,status);
				}//onFinish

		};


		/**
		 * Object containing the callback chain needed remove the password request
		 */
		RemoveAllPasswordCallback mRemoveAllPasswordCallback;
		friend class RemoveAllPasswordCallback;

		/**
		 * This class permit set the tag as read/write only
		 * This class is equivalent to call the methods:
		 * <ul>
		 *   <li> Verify(i2c) </li>
		 *   <li> EnablePermanentState(Read/write) </li>
		 * </ul>
		 * or:
		 * <ul>
		 *   <li> Verify(i2c) </li>
		 *   <li> DisablePermanentState</li>
		 *   <li> DisableVerificationRequirement(Read/write) </li>
		 * </ul>
		 */
		class ChangeAccessStateCallback : public Nfc::Callback{

			public:

				typedef enum{
					WRITE,
					READ
				}AccessType_t;

				/**
				 * Build the chain of callback.
				 * @param parent object where send the command
				 */
				ChangeAccessStateCallback():mType(WRITE),mEnable(false){}

				/**
				 * Set the access to enable/disable.
				 * @param type Type to enable or disable.
				 * @param enable true for enable the state, false for disable it.
				 */
				void changeAccessState(AccessType_t type,bool enable){
					mType=type;
					mEnable=enable;
				}

				virtual void onVerifyed(Nfc *nfc,NFC_StatusTypeDef status,
						PasswordType_t,const uint8_t*){
					if(status!=NFC_SUCCESS)
						return onFinishCommand(nfc,status);

					if(mEnable){
						nfc->DisablePermanentState(mType==WRITE? WritePwd : ReadPwd);
					}else
						nfc->EnablePermanentState(mType==WRITE? WritePwd : ReadPwd);

				}

				virtual void onDisablePermanentState(Nfc *nfc, NFC_StatusTypeDef status,
						PasswordType_t type ){
					if(status!=NFC_SUCCESS)
						return onFinishCommand(nfc,status);

					nfc->DisableVerificationRequirement(type);
				}

				virtual void onDisableVerificationRequirement(Nfc *nfc , NFC_StatusTypeDef status,
						PasswordType_t ){
					onFinishCommand(nfc,status);
				}

				virtual void onEnablePermanentState(Nfc *nfc ,NFC_StatusTypeDef status,PasswordType_t ){
					onFinishCommand(nfc,status);
				}


			private:

				/**
				 * Remove the private callback and call the user callback.
				 * @param nfc Object where the command is run.
				 * @param status Command status.
				 */
				void onFinishCommand(Nfc *nfc,NFC_StatusTypeDef status){
					nfc->mComponentCallback=NULL;
					if(mEnable){
						if(mType==READ){
							//enable read = disable write only
							nfc->getCallback()->onDisableWriteOnly(nfc,status);
						}else
							//enable write = disable read only
							nfc->getCallback()->onDisableReadOnly(nfc,status);
					}else{
						if(mType==WRITE){
							//disable write = enable read only
							nfc->getCallback()->onEnableReadOnly(nfc,status);
						}else{
							//
							nfc->getCallback()->onEnableWriteOnly(nfc,status);
						}
					}//if-else enable
				}//onFinish

				AccessType_t mType;
				bool mEnable;

		};


		/**
		 * Object containing the callback chain needed to change the access state
		 */
		ChangeAccessStateCallback mChangeAccessStateCallback;
		friend class ChangeAccessStateCallback;

};

#endif /* __NFC_CLASS_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/