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

Revision:
27:3881985097bb
Parent:
25:caa16fd0e50b
Child:
28:e0d4ffa90f8b
--- a/m24sr/m24sr_class.h	Wed Feb 03 09:01:05 2016 +0000
+++ b/m24sr/m24sr_class.h	Fri Sep 30 12:33:20 2016 +0000
@@ -2,8 +2,8 @@
  ******************************************************************************
  * @file    m24sr_class.h
  * @author  ST Central Labs
- * @version V1.0.0
- * @date    05 Nov 2015
+ * @version V1.1.0
+ * @date    30 Set 2016
  * @brief   This file provides a set of functions to interface with the M24SR
  *          device.
  ******************************************************************************
@@ -53,18 +53,82 @@
 #include "I2C.h"
 
 #include "m24sr.h"
-#include "Interfaces/Nfc_class.h"
-#include "NDefNfcTagM24SR.h"
+#include "Nfc.h"
+
+#include "NDefLib/NDefNfcTag.h"
+class NDefNfcTagM24SR;
 
 /* Classes -------------------------------------------------------------------*/
 
 /**
- * Class representing a M24SR component.
+* Class representing a M24SR component.
+* This component has two operation modes, sync or async.
+* In sync mode each function call returns only after the command has completed.
+* In async mode each function call returns immediately and the answer will be notified
+* through a callback.
+* The default behavior is sync mode.
+* To enable the async mode ManageI2CGPO(I2C_ANSWER_READY) function must be called.
+* When the component notifies an interrupt user must call  {@link ManageEvent} function.
+* Note that passing a parameter other than I2C_ANSWER_READY to ManageI2CGPO initialize the component in sync mode.
  */
 class M24SR: public Nfc {
 
 public:
 
+	typedef enum {
+		M24SR_SUCCESS=NFC_SUCCESS,
+		M24SR_ERROR=0x6F00,
+		M24SR_FILE_OVERFLOW_LE = 0x6280,
+		M24SR_EOF = 0x6282,
+		M24SR_PASSWORD_REQUIRED = 0x6300,
+		M24SR_PASSWORD_INCORRECT = 0x63C0,
+		M24SR_PASSWORD_INCORRECT1RETRY = 0x63C1,
+		M24SR_PASSWORD_INCORRECT2RETRY = 0x63C2,
+		M24SR_WRONG_LENGHT = 0x6700,
+		M24SR_UNSUCESSFUL_UPDATING = 0x6581,
+		M24SR_INCOPATIBLE_COMMAND= 0x6981,
+		M24SR_SECURITY_UNSATISFIED = 0x6982,
+		M24SR_REFERENCE_DATA_NOT_USABLE = 0x6984,
+
+		M24SR_INCORRECT_PARAMETER = 0x6a80,
+		M24SR_FILE_NOT_FOUND=0x6a82,
+		M24SR_FILE_OVERFLOW_LC = 0x6A84, //TODO difference with Le??
+
+		M24SR_INCORRECT_P1_OR_P2 = 0x6A86, //TODO better name?
+		M24SR_RF_SESSION_KILLED=0x6500,
+		M24SR_INS_NOT_SUPPORTED=0x6D00,
+		M24SR_CLASS_NOT_SUPPORTED=0x6E00,
+
+		//IOError
+		M24SR_IO_ERROR_I2CTIMEOUT=0x0011,
+		M24SR_IO_ERROR_CRC=0x0012,
+		M24SR_IO_ERROR_NACK=0x0013,
+		M24SR_IO_ERROR_PARAMETER=0x0014,
+		M24SR_IO_ERROR_NBATEMPT=0x0015,
+		M24SR_IO_NOACKNOWLEDGE=0x0016
+	} StatusTypeDef;
+
+	/**
+	 * @brief  GPO state structure
+	 */
+	typedef enum {
+		HIGH_IMPEDANCE = 0,
+		SESSION_OPENED =1,
+		WIP=2,
+		I2C_ANSWER_READY=3,
+		INTERRUPT=4,
+		STATE_CONTROL=5
+	} NFC_GPO_MGMT;
+
+	/**
+	 * Possible password to set.
+	 */
+	typedef enum{
+		ReadPwd,   //!< Password to use before reading the tag
+		WritePwd,  //!< Password to use before writing the tag
+		I2CPwd,    //!< Root password, used only through nfc
+	}PasswordType_t;
+
 	/**
 	 * Default password used to change the write/read permission
 	 */
@@ -75,6 +139,187 @@
 	 */
 	static const NFC_GPO_MGMT DEFAULT_GPO_STATUS=HIGH_IMPEDANCE;
 
+
+	/**
+	 * 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 callbacks fired by this class, each command has its own callback.
+	 * The callback default implementation is an empty function.
+	 */
+	class Callbacks{
+		public:
+
+			/** called when GetSession or ForceGetSession completes
+			 * @see M24SR#GetSession
+			 * @see M24SR#ForceGetSession */
+			virtual void onSessionOpen(M24SR *nfc,StatusTypeDef status){
+				(void)nfc; (void)status;
+			}
+
+			/** called when Deselect completes
+			 * @see M24SR#Deselect */
+			virtual void onDeselect(M24SR *nfc,StatusTypeDef status){
+				(void)nfc; (void)status;
+			}
+
+			/** called when SelectedApplication completes
+			 * @see M24SR#SelectedApplication */
+			virtual void onSelectedApplication(M24SR *nfc,StatusTypeDef status){
+				(void)nfc; (void)status;
+			}
+
+			/** called when SelectedCCFile completes
+			 * @see M24SR#SelectedCCFile */
+			virtual void onSelectedCCFile(M24SR *nfc,StatusTypeDef status){
+				(void)nfc; (void)status;
+			}
+
+			/** called when SelectedNDEFFile completes
+			 * @see M24SR#SelectedNDEFFile */
+			virtual void onSelectedNDEFFile(M24SR *nfc,StatusTypeDef status){
+				(void)nfc; (void)status;
+			}
+
+			/** called when SelectedSystemFile completes
+			 * @see M24SR#SelectedSystemFile */
+			virtual void onSelectedSystemFile(M24SR *nfc,StatusTypeDef status){
+				(void)nfc; (void)status;
+			}
+
+			/** called when ReadBinary or STReadBinary completes
+			 * @see M24SR#ReadBinary
+			 * @see M24SR#STReadBinary */
+			virtual void onReadByte(M24SR *nfc,StatusTypeDef status,
+					uint16_t offset,uint8_t *readByte, uint16_t nReadByte){
+				(void)nfc; (void)status;(void)offset; (void)readByte; (void)nReadByte;
+			}
+
+			/** called when UpdatedBinary completes
+			 * @see M24SR#UpdatedBinary */
+			virtual void onUpdatedBinary(M24SR *nfc,StatusTypeDef status,uint16_t offset,
+					uint8_t *writeByte,uint16_t nWriteByte){
+				(void)nfc; (void)status; (void)writeByte; (void)nWriteByte; (void)offset;
+			}
+
+			/** called when Verify completes
+			 * @see M24SR#Verify */
+			virtual void onVerified(M24SR *nfc,StatusTypeDef status,PasswordType_t uPwdId,
+					const uint8_t *pwd){
+				(void)nfc; (void)status;(void)uPwdId;(void)pwd;
+			}
+
+			/** called when ManageI2CGPO completes
+			 * @see M24SR#ManageI2CGPO */
+			virtual void onManageI2CGPO(M24SR *nfc,StatusTypeDef status,NFC_GPO_MGMT newStatus){
+				(void)nfc; (void)status;(void)newStatus;
+			}
+
+			/** called when ManageRFGPO completes
+			 * @see M24SR#ManageRFGPO */
+			virtual void onManageRFGPO(M24SR *nfc,StatusTypeDef status,NFC_GPO_MGMT newStatus){
+				(void)nfc; (void)status;(void)newStatus;
+			}
+
+			/** called when ChangeReferenceData completes
+			 * @see M24SR#ChangeReferenceData */
+			virtual void onChangeReferenceData(M24SR *nfc ,StatusTypeDef status,PasswordType_t type,
+					uint8_t *data){
+				(void)nfc; (void)status;(void)type;(void)data;
+			}
+
+			/** called when EnableVerificationRequirement completes
+			 * @see M24SR#EnableVerificationRequirement */
+			virtual void onEnableVerificationRequirement(M24SR *nfc ,StatusTypeDef status,PasswordType_t type){
+				(void)nfc; (void)status;(void)type;
+			}
+
+			/** called when DisableVerificationRequirement completes
+			 * @see M24SR#DisableVerificationRequirement */
+			virtual void onDisableVerificationRequirement(M24SR *nfc , StatusTypeDef status,PasswordType_t type){
+				(void)nfc; (void)status;(void)type;
+			}
+
+			/** called when EnablePermanentState completes
+			 * @see M24SR#EnablePermanentState */
+			virtual void onEnablePermanentState(M24SR *nfc, StatusTypeDef status, PasswordType_t type){
+				(void)nfc; (void)status;(void)type;
+			}
+
+			/** called when DisablePermanentState completes
+			 * @see M24SR#DisablePermanentState */
+			virtual void onDisablePermanentState(M24SR *nfc, StatusTypeDef status, PasswordType_t type){
+				(void)nfc; (void)status;(void)type;
+			}
+
+			/** called when ReadId completes
+			 * @see M24SR#ReadId */
+			virtual void onReadId(M24SR *nfc, StatusTypeDef status, uint8_t *id){
+						(void)nfc; (void)status;(void)id;
+			}
+
+			/** called when EnableReadPassword completes
+			 * @see M24SR#EnableReadPassword */
+			virtual void onEnableReadPassword(M24SR *nfc, StatusTypeDef status,const uint8_t *newPwd){
+				(void)nfc; (void)status;(void)newPwd;
+			}
+
+			/** called when EnableWritePassword completes
+			 * @see M24SR#EnableWritePassword */
+			virtual void onEnableWritePassword(M24SR *nfc, StatusTypeDef status,const uint8_t *newPwd){
+				(void)nfc; (void)status;(void)newPwd;
+			}
+
+			/** called when DisableReadPassword completes
+			 * @see M24SR#DisableReadPassword */
+			virtual void onDisableReadPassword(M24SR *nfc, StatusTypeDef status){
+				(void)nfc; (void)status;
+			}
+
+			/** called when DisableWritePassword completes
+			 * @see M24SR#DisableWritePassword */
+			virtual void onDisableWritePassword(M24SR *nfc, StatusTypeDef status){
+				(void)nfc; (void)status;
+			}
+
+			/** called when DisableAllPassword completes
+			 * @see M24SR#DisableAllPassword */
+			virtual void onDisableAllPassword(M24SR *nfc, StatusTypeDef status){
+				(void)nfc; (void)status;
+			}
+
+
+			/** called when EnableReadOnly completes
+			 * @see M24SR#EnableReadOnly */
+			virtual void onEnableReadOnly(M24SR *nfc,StatusTypeDef status){
+				(void)nfc; (void)status;
+			}
+
+			/** called when EnableWriteOnly completes
+			 * @see M24SR#EnableWriteOnly */
+			virtual void onEnableWriteOnly(M24SR *nfc,StatusTypeDef status){
+				(void)nfc; (void)status;
+			}
+
+
+			/** called when DisableReadOnly completes
+			 * @see M24SR#DisableReadOnly */
+			virtual void onDisableReadOnly(M24SR *nfc,StatusTypeDef status){
+				(void)nfc; (void)status;
+			}
+
+			/** called when DisableWriteOnly completes
+			 * @see M24SR#DisableWriteOnly */
+			virtual void onDisableWriteOnly(M24SR *nfc,StatusTypeDef status){
+				(void)nfc; (void)status;
+			}
+
+			virtual ~Callbacks(){};
+		};
+
 	/*** Constructor and Destructor Methods ***/
 
 	/**
@@ -86,263 +331,441 @@
 	 * @param RFDISPinName Pin used to disable the RF function.
 	 */
 	M24SR(const uint8_t address, I2C &I2C,gpoEventCallback eventCallback, const PinName& GPOPinName,
-			const PinName& RFDISPinName) :
-			Nfc(),
-			who_am_i(0),
-			type(0),
-			address(address),
-			dev_I2C(I2C),
-			GPOPin(GPOPinName),
-			RFDisablePin(RFDISPinName),
-			NDefTagUtil(*this),
-			mCommunicationType(SYNC),
-			mLastCommandSend(NONE),
-			mGpoEventInterrupt(GPOPinName),
-			mManageGPOCallback(*this),
-			mReadIDCallback(*this){
-
-		memset(uM24SRbuffer, 0, 0xFF * sizeof(int8_t));
-		uDIDbyte = 0;
-		RFDisablePin = 0;
-		if(eventCallback!=NULL)
-			mGpoEventInterrupt.fall(eventCallback);
-		mGpoEventInterrupt.mode(PullUp);
-		mGpoEventInterrupt.disable_irq();
-	}
+			const PinName& RFDISPinName);
 
 	/**
 	 * @brief Destructor.
 	 */
-	virtual ~M24SR(void) {
-	}
+	virtual ~M24SR(void);
 
 	/*** Public Component Related Methods ***/
 	
 	/**
 	 * @brief  This function initializes the M24SR device.
 	 * @param ptr Configure parameters, not used.
-     * @return NFC_SUCCESS if no errors
+     * @return M24SR_SUCCESS if no errors
 	 */
 	virtual int Init(void *ptr) {
-		return (NFC_StatusTypeDef) M24SR_Init((M24SR_InitTypeDef*)ptr);
+		return (StatusTypeDef) M24SR_Init((M24SR_InitTypeDef*)ptr);
 	}
 
 	virtual int ReadID(uint8_t *id) {
-		return (NFC_StatusTypeDef) M24SR_ReadID((uint8_t *) id);
+		return (StatusTypeDef) M24SR_ReadID((uint8_t *) id);
 	}
 
 	/** lock the tag channel */
-	virtual NFC_StatusTypeDef GetSession(void) {
-		return (NFC_StatusTypeDef) M24SR_GetSession();
+	virtual StatusTypeDef GetSession(void) {
+		return (StatusTypeDef) M24SR_GetSession();
 	}
 
-	virtual NFC_StatusTypeDef ForceGetSession(void) {
-		return (NFC_StatusTypeDef) M24SR_ForceSession();
+	/**
+	 * Force to open an I2C connection , abort the RF connection.
+	 * @return M24SR_SUCCESS if the session is acquired
+	 */
+	StatusTypeDef ForceGetSession(void) {
+		return (StatusTypeDef) M24SR_ForceSession();
 	}
 
-	virtual NFC_StatusTypeDef Deselect(void) {
-		return (NFC_StatusTypeDef) M24SR_Deselect();
+	virtual StatusTypeDef Deselect(void) {
+		return (StatusTypeDef) M24SR_Deselect();
 	}
 
 	////////// tag4 command ////////////////////
 	
-	virtual NFC_StatusTypeDef SelectApplication(void) {
+	/**
+	 * Select the application file.
+	 * @return M24SR_SUCCESS if the application is selected
+	 */
+	StatusTypeDef SelectApplication(void) {
 		return M24SR_SendSelectApplication();
 	}
 
-	virtual NFC_StatusTypeDef SelectCCfile(void) {
+	/**
+	 * Select the CC file.
+	 * @return M24SR_SUCCESS if the CC file is selected.
+	 */
+	StatusTypeDef SelectCCfile(void) {
 		return M24SR_SendSelectCCfile();
 	}
 
-	virtual NFC_StatusTypeDef SelectNDEFfile(uint16_t NDEFfileId) {
+	/**
+	 * Select the NDEF file.
+	 * @param NDEFfileId File id to open.
+	 * @return M24SR_SUCCESS if the file is selected
+	 */
+	StatusTypeDef SelectNDEFfile(uint16_t NDEFfileId) {
 		return M24SR_SendSelectNDEFfile(NDEFfileId);
 	}
 
-	virtual NFC_StatusTypeDef SelectSystemfile(void) {
+	/**
+	 * Select the system file.
+	 * @return M24SR_SUCCESS if the system file is selected
+	 */
+	StatusTypeDef SelectSystemfile(void) {
 		return M24SR_SendSelectSystemfile();
 	}
 
-	virtual NFC_StatusTypeDef ReadBinary(uint16_t Offset, uint8_t NbByteToRead,
+	virtual int ReadBinary(uint16_t Offset, uint8_t NbByteToRead,
 			uint8_t *pBufferRead) {
-		return (NFC_StatusTypeDef) M24SR_SendReadBinary((uint16_t) Offset,
+		return (StatusTypeDef) M24SR_SendReadBinary((uint16_t) Offset,
 				(uint8_t) NbByteToRead, (uint8_t *) pBufferRead);
 	}
 
-	virtual NFC_StatusTypeDef UpdateBinary(uint16_t Offset,
+	virtual int UpdateBinary(uint16_t Offset,
 			uint8_t NbByteToWrite,uint8_t *pDataToWrite) {
-		return (NFC_StatusTypeDef) M24SR_SendUpdateBinary((uint16_t) Offset,
+		return (StatusTypeDef) M24SR_SendUpdateBinary((uint16_t) Offset,
 				(uint8_t) NbByteToWrite, (uint8_t *) pDataToWrite);
 	}
 
 	/////////////////// iso 7816-4 commands //////////////////////////
 	
-	virtual NFC_StatusTypeDef Verify(PasswordType_t pwdId, uint8_t NbPwdByte,
+	virtual StatusTypeDef Verify(PasswordType_t pwdId, uint8_t NbPwdByte,
 			const uint8_t *pPwd) {
-		return (NFC_StatusTypeDef) M24SR_SendVerify(passwordTypeToConst(pwdId),
+		return (StatusTypeDef) M24SR_SendVerify(passwordTypeToConst(pwdId),
 				(uint8_t) NbPwdByte, pPwd);
 	}
 
-	virtual NFC_StatusTypeDef ChangeReferenceData(PasswordType_t pwdId,
+	virtual StatusTypeDef ChangeReferenceData(PasswordType_t pwdId,
 			const uint8_t *pPwd) {
-		return (NFC_StatusTypeDef) M24SR_SendChangeReferenceData(passwordTypeToConst(pwdId),
+		return (StatusTypeDef) M24SR_SendChangeReferenceData(passwordTypeToConst(pwdId),
 				(uint8_t *) pPwd);
 	}
 
-	virtual NFC_StatusTypeDef EnableVerificationRequirement(
+	virtual StatusTypeDef EnableVerificationRequirement(
 			PasswordType_t uReadOrWrite) {
-		return (NFC_StatusTypeDef) M24SR_SendEnableVerificationRequirement(
+		return (StatusTypeDef) M24SR_SendEnableVerificationRequirement(
 				passwordTypeToConst(uReadOrWrite));
 	}
 
-	virtual NFC_StatusTypeDef DisableVerificationRequirement(
+	virtual StatusTypeDef DisableVerificationRequirement(
 			PasswordType_t uReadOrWrite) {
-		return (NFC_StatusTypeDef) M24SR_SendDisableVerificationRequirement(
+		return (StatusTypeDef) M24SR_SendDisableVerificationRequirement(
 				passwordTypeToConst(uReadOrWrite));
 	}
 
     ////////////////////// ST proprietary //////////////////////////////////
 
-	virtual NFC_StatusTypeDef STReadBinary(uint16_t Offset,
+	/**
+	 * 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 M24SR_SUCCESS if no errors
+	 */
+	StatusTypeDef STReadBinary(uint16_t Offset,
 			uint8_t NbByteToRead, uint8_t *pBufferRead) {
-		return (NFC_StatusTypeDef) M24SR_SendSTReadBinary((uint16_t) Offset,
+		return (StatusTypeDef) M24SR_SendSTReadBinary((uint16_t) Offset,
 				(uint8_t) NbByteToRead, (uint8_t *) pBufferRead);
 	}
 
-	virtual NFC_StatusTypeDef EnablePermanentState(PasswordType_t uReadOrWrite) {
-		return (NFC_StatusTypeDef) M24SR_SendEnablePermanentState(
+	virtual StatusTypeDef EnablePermanentState(PasswordType_t uReadOrWrite) {
+		return (StatusTypeDef) M24SR_SendEnablePermanentState(
 				passwordTypeToConst(uReadOrWrite));
 	}
 
-	virtual NFC_StatusTypeDef DisablePermanentState(PasswordType_t uReadOrWrite) {
-		return (NFC_StatusTypeDef) M24SR_SendDisablePermanentState(
+	virtual StatusTypeDef DisablePermanentState(PasswordType_t uReadOrWrite) {
+		return (StatusTypeDef) M24SR_SendDisablePermanentState(
 				passwordTypeToConst(uReadOrWrite));
 	}
 
 	///////////////////// chip configuration /////////////////////////////////
-	virtual NFC_StatusTypeDef StateControl(uint8_t uSetOrReset) {
-		return (NFC_StatusTypeDef) M24SR_StateControl((uint8_t) uSetOrReset);
+	/**
+	 * Set the gpo output pin.
+	 * @param uSetOrReset New pin status.
+ 	 * @return M24SR_SUCCESS if no errors
+	 */
+	StatusTypeDef StateControl(uint8_t uSetOrReset) {
+		return (StatusTypeDef) M24SR_StateControl((uint8_t) uSetOrReset);
 	}
 
-	virtual NFC_StatusTypeDef ManageI2CGPO(NFC_GPO_MGMT GPO_I2Cconfig) {
-		return (NFC_StatusTypeDef) M24SR_ManageI2CGPO(GPO_I2Cconfig);
+	/**
+	 * @brief  This function configures GPO for I2C session.
+	 * @param  GPO_I2Cconfig GPO configuration to set.
+ 	 * @return M24SR_SUCCESS if no errors
+ 	 * @par if the configuration is I2C_ANSWER_READY, the component will start to work
+ 	 * in async mode.
+	 */
+	StatusTypeDef ManageI2CGPO(NFC_GPO_MGMT GPO_I2Cconfig) {
+		return (StatusTypeDef) M24SR_ManageI2CGPO(GPO_I2Cconfig);
 	}
 
-	virtual NFC_StatusTypeDef ManageRFGPO(uint8_t GPO_RFconfig) {
-		return (NFC_StatusTypeDef) M24SR_ManageRFGPO(
+
+	/**
+ 	* @brief  This function configures GPO for RF session.
+ 	* @param  GPO_RFconfig GPO configuration to set.
+  	* @return M24SR_SUCCESS if no errors
+ 	*/
+	StatusTypeDef ManageRFGPO(uint8_t GPO_RFconfig) {
+		return (StatusTypeDef) M24SR_ManageRFGPO(
 				(NFC_GPO_MGMT) GPO_RFconfig);
 	}
 
-	virtual NFC_StatusTypeDef RFConfig(uint8_t OnOffChoice) {
-		return (NFC_StatusTypeDef) M24SR_RFConfig((uint8_t) OnOffChoice);
+
+	/**
+	 * @brief  This function enables or disables the RF communication.
+	 * @param  OnOffChoice GPO configuration to set.
+  	 * @return M24SR_SUCCESS if no errors
+	 */
+
+	StatusTypeDef RFConfig(uint8_t OnOffChoice) {
+		return (StatusTypeDef) M24SR_RFConfig((uint8_t) OnOffChoice);
+	}
+
+
+	/**
+	 * 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 M24SR_SUCCESS if no errors
+	 */
+	StatusTypeDef SendInterrupt(void) {
+		return (StatusTypeDef) M24SR_SendInterrupt();
+	}
+
+
+	/**
+	 * Function to call when the component fire an interrupt.
+	 * @return last operation status
+	 */
+	StatusTypeDef ManageEvent();
+
+	/**
+	 * Change the function to call when a command ends.
+	 * @param commandCallback Object containing the callback, if NULL it will use empty callback
+	 */
+	void SetCallback(Callbacks *commandCallback){
+		if(commandCallback!=NULL)
+			mCallback = commandCallback;
+		else
+			mCallback = &defaultCallback;
 	}
 
 
-	virtual NFC_StatusTypeDef SendInterrupt(void) {
-		return (NFC_StatusTypeDef) M24SR_SendInterrupt();
+	/////////////////// 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 M24SR_SUCCESS if no errors
+	 * @par The password must have a length of 16 chars.
+	 */
+	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(M24SR::WritePwd, 0x10, pCurrentWritePassword);
+	}
+
+	/**
+	 * Disable the request of a password before reading the tag.
+	 * @param  pCurrentWritePassword Current password
+	 * @return return M24SR_SUCCESS if no errors
+	 * @par The password must have a length of 16 chars.
+	 */
+	StatusTypeDef DisableReadPassword(const uint8_t* pCurrentWritePassword) {
+		mComponentCallback = &mChangePasswordRequestStatusCallback;
+		mChangePasswordRequestStatusCallback.setTask(ReadPwd,NULL);
+
+		return Verify(M24SR::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 M24SR_SUCCESS if no errors
+	 * @par The password must have a length of 16 chars.
+	 */
+	StatusTypeDef EnableWritePassword(const uint8_t* pCurrentWritePassword,
+				uint8_t* pNewPassword) {
+		//enable the callback for change the gpo
+		mComponentCallback = &mChangePasswordRequestStatusCallback;
+		mChangePasswordRequestStatusCallback.setTask(WritePwd,pNewPassword);
+
+		return Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword);
+	}
+
+	/**
+	 * Disable the request of a password before writing the tag.
+	 * @param  pCurrentWritePassword Current password.
+	 * @return return M24SR_SUCCESS if no errors
+	 * @par The password must have a length of 16 chars.
+	 */
+	StatusTypeDef DisableWritePassword(const uint8_t* pCurrentWritePassword) {
+		mComponentCallback = &mChangePasswordRequestStatusCallback;
+		mChangePasswordRequestStatusCallback.setTask(WritePwd,NULL);
+
+		return Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword);
 	}
 
-	virtual NFC_StatusTypeDef ManageEvent();
+	/**
+	 * @brief   This function disables both read and write passwords.
+	 * @param	pSuperUserPassword I2C super user password.
+	 * @return  return M24SR_SUCCESS if no errors
+	 * @par The password must have a length of 16 chars.
+	 */
+	StatusTypeDef DisableAllPassword(const uint8_t* pSuperUserPassword){
+		mComponentCallback = &mRemoveAllPasswordCallback;
+		return Verify(M24SR::I2CPwd, 0x10, pSuperUserPassword);
+	}
+
+	/**
+	 * @brief   This function enables read only mode.
+	 * @param	pCurrentWritePassword Write password is needed to enable read only mode.
+	 * @return  return M24SR_SUCCESS if no errors
+	 * @par The password must have a length of 16 chars.
+	 */
+	StatusTypeDef EnableReadOnly(const uint8_t* pCurrentWritePassword){
+
+		mComponentCallback = &mChangeAccessStateCallback;
+		//disable write = read only
+		mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::WRITE,false);
+
+		return Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword);
+	}
 
-	/////////////////// hight level/utility function /////////////////////
+	/**
+	 * @brief   This function disables read only mode.
+	 * @param	pCurrentWritePassword Write password is needed to disable read only mode.
+	 * @return  return M24SR_SUCCESS if no errors
+	 * @par The password must have a length of 16 chars.
+	 */
+	StatusTypeDef DisableReadOnly(const uint8_t* pCurrentWritePassword) {
+		mComponentCallback = &mChangeAccessStateCallback;
+		mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::WRITE,true);
+		return Verify(M24SR::I2CPwd, 0x10,pCurrentWritePassword);
+	}
+
+
+	/**
+	 * @brief   This function enables write only mode.
+	 * @param	pCurrentWritePassword Write password is needed to enable write only mode.
+	 * @return  return M24SR_SUCCESS if no errors
+	 * @par The password must have a length of 16 chars.
+	 */
+	StatusTypeDef EnableWriteOnly(const uint8_t* pCurrentWritePassword) {
+
+		mComponentCallback = &mChangeAccessStateCallback;
+		//disable read = enable write only
+		mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::READ,false);
+
+		return Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword);
+
+	}
+
+	/**
+	 * @brief   This function disables write only mode.
+	 * @param	pCurrentWritePassword Write password is needed to disable write only mode.
+	 * @return  return M24SR_SUCCESS if no errors
+	 * @par The password must have a length of 16 chars.
+	 */
+	StatusTypeDef DisableWriteOnly(const uint8_t* pCurrentWritePassword) {
+		mComponentCallback = &mChangeAccessStateCallback;
+		mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::READ,true);
+		return Verify(M24SR::I2CPwd, 0x10, pCurrentWritePassword);
+	}
+
 
 	/**
 	 * Get an implementation of NDefNfcTag to use the library NDefLib.
 	 * @return an object of type NdefNfcTag 
 	 */
-	NDefLib::NDefNfcTag& getNDefTag(){
-		return NDefTagUtil;
-	}
+	NDefLib::NDefNfcTag& getNDefTag();
 
 
 protected:
 
 	/*** Protected Component Related Methods ***/
 
-	NFC_StatusTypeDef M24SR_Init(M24SR_InitTypeDef *);
-	NFC_StatusTypeDef M24SR_ReadID(uint8_t *nfc_id);
-	NFC_StatusTypeDef M24SR_GetSession(void);
-	NFC_StatusTypeDef M24SR_ForceSession(void);
+	StatusTypeDef M24SR_Init(M24SR_InitTypeDef *);
+	StatusTypeDef M24SR_ReadID(uint8_t *nfc_id);
+	StatusTypeDef M24SR_GetSession(void);
+	StatusTypeDef M24SR_ForceSession(void);
 
 
 
-	NFC_StatusTypeDef M24SR_Deselect(void);
-	NFC_StatusTypeDef M24SR_ReceiveDeselect(void);
+	StatusTypeDef M24SR_Deselect(void);
+	StatusTypeDef M24SR_ReceiveDeselect(void);
 
-	NFC_StatusTypeDef M24SR_SendSelectApplication(void);
-	NFC_StatusTypeDef M24SR_ReceiveSelectApplication(void);
+	StatusTypeDef M24SR_SendSelectApplication(void);
+	StatusTypeDef M24SR_ReceiveSelectApplication(void);
 
-	NFC_StatusTypeDef M24SR_SendSelectCCfile(void);
-	NFC_StatusTypeDef M24SR_ReceiveSelectCCfile(void);
+	StatusTypeDef M24SR_SendSelectCCfile(void);
+	StatusTypeDef M24SR_ReceiveSelectCCfile(void);
 
-	NFC_StatusTypeDef M24SR_SendSelectNDEFfile(uint16_t NDEFfileId);
-	NFC_StatusTypeDef M24SR_ReceiveSelectNDEFfile();
+	StatusTypeDef M24SR_SendSelectNDEFfile(uint16_t NDEFfileId);
+	StatusTypeDef M24SR_ReceiveSelectNDEFfile();
 
-	NFC_StatusTypeDef M24SR_SendSelectSystemfile(void);
-	NFC_StatusTypeDef M24SR_ReceiveSelectSystemfile(void);
+	StatusTypeDef M24SR_SendSelectSystemfile(void);
+	StatusTypeDef M24SR_ReceiveSelectSystemfile(void);
 
-	NFC_StatusTypeDef M24SR_SendReadBinary(uint16_t Offset, uint8_t NbByteToRead,
+	StatusTypeDef M24SR_SendReadBinary(uint16_t Offset, uint8_t NbByteToRead,
 			uint8_t *pBufferRead);
-	NFC_StatusTypeDef M24SR_SendSTReadBinary(uint16_t Offset, uint8_t NbByteToRead,
+	StatusTypeDef M24SR_SendSTReadBinary(uint16_t Offset, uint8_t NbByteToRead,
 				uint8_t *pBufferRead);
-	NFC_StatusTypeDef M24SR_ReceiveReadBinary(void);
+	StatusTypeDef M24SR_ReceiveReadBinary(void);
 
-	NFC_StatusTypeDef M24SR_SendUpdateBinary(uint16_t Offset, uint8_t NbByteToWrite,
+	StatusTypeDef M24SR_SendUpdateBinary(uint16_t Offset, uint8_t NbByteToWrite,
 			uint8_t *pDataToWrite);
-	NFC_StatusTypeDef M24SR_ReceiveUpdateBinary();
+	StatusTypeDef M24SR_ReceiveUpdateBinary();
 
-	NFC_StatusTypeDef M24SR_SendVerify(uint16_t uPwdId, uint8_t NbPwdByte,
+	StatusTypeDef M24SR_SendVerify(uint16_t uPwdId, uint8_t NbPwdByte,
 			const uint8_t *pPwd);
-	NFC_StatusTypeDef M24SR_ReceiveVerify();
+	StatusTypeDef M24SR_ReceiveVerify();
 
-	NFC_StatusTypeDef M24SR_SendChangeReferenceData(uint16_t uPwdId, uint8_t *pPwd);
-	NFC_StatusTypeDef M24SR_ReceiveChangeReferenceData();
+	StatusTypeDef M24SR_SendChangeReferenceData(uint16_t uPwdId, uint8_t *pPwd);
+	StatusTypeDef M24SR_ReceiveChangeReferenceData();
 
-	NFC_StatusTypeDef M24SR_SendEnableVerificationRequirement(
+	StatusTypeDef M24SR_SendEnableVerificationRequirement(
 			uint16_t uReadOrWrite);
-	NFC_StatusTypeDef M24SR_ReceiveEnableVerificationRequirement();
+	StatusTypeDef M24SR_ReceiveEnableVerificationRequirement();
 
-	NFC_StatusTypeDef M24SR_SendDisableVerificationRequirement(
+	StatusTypeDef M24SR_SendDisableVerificationRequirement(
 			uint16_t uReadOrWrite);
-	NFC_StatusTypeDef M24SR_ReceiveDisableVerificationRequirement();
+	StatusTypeDef M24SR_ReceiveDisableVerificationRequirement();
 
-	NFC_StatusTypeDef M24SR_SendEnablePermanentState(uint16_t uReadOrWrite);
-	NFC_StatusTypeDef M24SR_ReceiveEnablePermanentState();
+	StatusTypeDef M24SR_SendEnablePermanentState(uint16_t uReadOrWrite);
+	StatusTypeDef M24SR_ReceiveEnablePermanentState();
 
-	NFC_StatusTypeDef M24SR_SendDisablePermanentState(uint16_t uReadOrWrite);
-	NFC_StatusTypeDef M24SR_ReceiveDisablePermanentState();
+	StatusTypeDef M24SR_SendDisablePermanentState(uint16_t uReadOrWrite);
+	StatusTypeDef M24SR_ReceiveDisablePermanentState();
 
-	NFC_StatusTypeDef M24SR_SendInterrupt(void);
-	NFC_StatusTypeDef M24SR_StateControl(uint8_t uSetOrReset);
+	StatusTypeDef M24SR_SendInterrupt(void);
+	StatusTypeDef M24SR_StateControl(uint8_t uSetOrReset);
 
-	NFC_StatusTypeDef M24SR_ManageI2CGPO(NFC_GPO_MGMT GPO_I2Cconfig);
-	NFC_StatusTypeDef M24SR_ManageRFGPO(NFC_GPO_MGMT GPO_RFconfig);
+	StatusTypeDef M24SR_ManageI2CGPO(NFC_GPO_MGMT GPO_I2Cconfig);
+	StatusTypeDef M24SR_ManageRFGPO(NFC_GPO_MGMT GPO_RFconfig);
 
-	NFC_StatusTypeDef M24SR_RFConfig(uint8_t OnOffChoice);
-	NFC_StatusTypeDef M24SR_SendFWTExtension(uint8_t FWTbyte);
+	StatusTypeDef M24SR_RFConfig(uint8_t OnOffChoice);
+	StatusTypeDef M24SR_SendFWTExtension(uint8_t FWTbyte);
 
 	
 	/**
 	 * Send a command to the component.
 	 * @param NbByte Length of the command.
 	 * @param pBuffer Buffer containing the command.
-	 * @return NFC_SUCCESS if no errors
+	 * @return M24SR_SUCCESS if no errors
 	 */
-	NFC_StatusTypeDef M24SR_IO_SendI2Ccommand(uint8_t NbByte, uint8_t *pBuffer);
+	StatusTypeDef M24SR_IO_SendI2Ccommand(uint8_t NbByte, uint8_t *pBuffer);
 	
 	/**
 	 * Read a command response.
 	 * @param NbByte Number of bytes to read.
 	 * @param pBuffer Buffer to store the response into.
-	 * @return NFC_SUCCESS if no errors
+	 * @return M24SR_SUCCESS if no errors
 	 */
-	NFC_StatusTypeDef M24SR_IO_ReceiveI2Cresponse(uint8_t NbByte,
+	StatusTypeDef M24SR_IO_ReceiveI2Cresponse(uint8_t NbByte,
 			uint8_t *pBuffer);
 
 	/**
 	 * Do an active polling on the I2C bus until the answer is ready.
-	 * @return NFC_SUCCESS if no errors
+	 * @return M24SR_SUCCESS if no errors
 	 */
-	NFC_StatusTypeDef M24SR_IO_PollI2C(void);
+	StatusTypeDef M24SR_IO_PollI2C(void);
 
 	/**
 	 * Read the gpo pin.
@@ -395,10 +818,6 @@
 	 */
 	uint8_t uDIDbyte;
 
-	/**
-	 * Object implementing the interface to use the NDefLib.
-	 */
-	NDefNfcTagM24SR NDefTagUtil;
 
 	/**
 	 * Command that the component can accept
@@ -459,8 +878,334 @@
 	 * Interrupt object fired when the gpo status changes
 	 */
 	InterruptIn mGpoEventInterrupt;
+
+	/** object containing the callbacks to use*/
+	Callbacks *mCallback;
+
+	/**
+	 * Object with private callbacks used to hide high level commands each
+	 * calling multiple low level commands. This callbacks object has
+	 * higher priority comparing to the user callbacks.
+	 */
+	Callbacks *mComponentCallback;
+
+	/**
+	 * Object implementing the interface to use the NDefLib.
+	 */
+	NDefNfcTagM24SR *mNDefTagUtil;
+
+	/**
+	 * get the callback object to use
+	 * @return callback object to use
+	 */
+	Callbacks * getCallback(){
+		if(mComponentCallback!=NULL)
+			return mComponentCallback;
+		return mCallback;
+	}//getCallback
+
 private:
-	
+	/** object containing empty callback to use in the default case*/
+	Callbacks defaultCallback;
+
+
+	/**
+	 * This class permits to enable/disable the password request to read/write into the tag
+	 * This class is equivalent to calling the methods:
+	 * 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 Callbacks{
+
+		public:
+
+			/**
+			 * Build the chain of callbacks.
+			 */
+			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 onVerified(M24SR *nfc, StatusTypeDef status,PasswordType_t ,
+					const uint8_t *){
+				if(status!=M24SR_SUCCESS)
+					return onFinishCommand(nfc,status);
+				if(mEnable)
+					nfc->ChangeReferenceData(mType,mNewPwd);
+				else
+					nfc->DisableVerificationRequirement(mType);
+			}
+
+			virtual void onDisableVerificationRequirement(M24SR *nfc,
+					StatusTypeDef status, PasswordType_t ){
+				onFinishCommand(nfc,status);
+			}
+
+			virtual void onChangeReferenceData(M24SR *nfc, StatusTypeDef status,
+					PasswordType_t type,
+					uint8_t *){
+				if(status==M24SR_SUCCESS)
+					nfc->EnablePermanentState(type);
+				else
+					onFinishCommand(nfc,status);
+			}
+
+			virtual void onEnablePermanentState(M24SR *nfc, StatusTypeDef status,
+					PasswordType_t ){
+				onFinishCommand(nfc,status);
+			}
+
+
+		private:
+
+			/**
+			 * Remove the private callbacks and call the user callback.
+			 * @param nfc Object triggering the command.
+			 * @param status Command status.
+			 */
+			void onFinishCommand(M24SR *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;
+			PasswordType_t mType;
+			bool mEnable;
+
+		};
+
+
+		/**
+		 * Object containing the callback chain needed to change the password request
+		 */
+		ChangePasswordRequestStatusCallback mChangePasswordRequestStatusCallback;
+		friend class ChangePasswordRequestStatusCallback;
+
+		/**
+		 * This class permits to disable all the password requests to read/write into the tag
+		 * This class is equivalent to calling 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 Callbacks{
+
+			/**
+			 * 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 callbacks.
+				 */
+				RemoveAllPasswordCallback():mI2CPwd(NULL){}
+
+				virtual void onVerified(M24SR *nfc,StatusTypeDef status,
+						PasswordType_t,const uint8_t* data){
+					if(status!=M24SR_SUCCESS)
+						return onFinishCommand(nfc,status);
+					mI2CPwd = data;
+					nfc->DisablePermanentState(ReadPwd);
+				}
+
+				virtual void onDisablePermanentState(M24SR *nfc , StatusTypeDef status,
+						PasswordType_t type){
+					if(status!=M24SR_SUCCESS)
+						return onFinishCommand(nfc,status);
+					if(type==ReadPwd)
+						nfc->DisablePermanentState(WritePwd);
+					else
+						nfc->DisableVerificationRequirement(ReadPwd);
+				}
+
+				virtual void onDisableVerificationRequirement(M24SR *nfc ,
+						StatusTypeDef status,PasswordType_t type){
+					if(status!=M24SR_SUCCESS)
+						return onFinishCommand(nfc,status);
+					if(type==ReadPwd)
+						nfc->DisableVerificationRequirement(WritePwd);
+					else
+						nfc->ChangeReferenceData(ReadPwd,mI2CPwd);
+				}
+
+				virtual void onChangeReferenceData(M24SR *nfc ,StatusTypeDef status,PasswordType_t type,
+						uint8_t *data){
+					if(status!=M24SR_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 triggering the command.
+				 * @param status Command status.
+				 */
+				void onFinishCommand(M24SR *nfc,StatusTypeDef status){
+					nfc->mComponentCallback=NULL;
+					mI2CPwd=NULL;
+					nfc->getCallback()->onDisableAllPassword(nfc,status);
+				}//onFinish
+
+		};
+
+
+		/**
+		 * Object containing the callback chain needed to remove the password request
+		 */
+		RemoveAllPasswordCallback mRemoveAllPasswordCallback;
+		friend class RemoveAllPasswordCallback;
+
+		/**
+		 * This class permits to set the tag as read/write only
+		 * This class is equivalent to calling 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 Callbacks{
+
+			public:
+
+				typedef enum{
+					WRITE,
+					READ
+				}AccessType_t;
+
+				/**
+				 * Build the chain of callbacks.
+				 */
+				ChangeAccessStateCallback():mType(WRITE),mEnable(false){}
+
+				/**
+				 * Set the access to enable/disable an access type.
+				 * @param type Access type.
+				 * @param enable True to enable the state, False to disable it.
+				 */
+				void changeAccessState(AccessType_t type,bool enable){
+					mType=type;
+					mEnable=enable;
+				}
+
+				virtual void onVerified(M24SR *nfc,StatusTypeDef status,
+						PasswordType_t,const uint8_t*){
+					if(status!=M24SR_SUCCESS)
+						return onFinishCommand(nfc,status);
+
+					if(mEnable){
+						nfc->DisablePermanentState(mType==WRITE? WritePwd : ReadPwd);
+					}else
+						nfc->EnablePermanentState(mType==WRITE? WritePwd : ReadPwd);
+
+				}
+
+				virtual void onDisablePermanentState(M24SR *nfc, StatusTypeDef status,
+						PasswordType_t type ){
+					if(status!=M24SR_SUCCESS)
+						return onFinishCommand(nfc,status);
+
+					nfc->DisableVerificationRequirement(type);
+				}
+
+				virtual void onDisableVerificationRequirement(M24SR *nfc , StatusTypeDef status,
+						PasswordType_t ){
+					onFinishCommand(nfc,status);
+				}
+
+				virtual void onEnablePermanentState(M24SR *nfc ,StatusTypeDef status,PasswordType_t ){
+					onFinishCommand(nfc,status);
+				}
+
+
+			private:
+
+				/**
+				 * Remove the private callback and call the user callback.
+				 * @param nfc Object triggering the command.
+				 * @param status Command status.
+				 */
+				void onFinishCommand(M24SR *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;
+
 
 	/**
 	 * Object with the callback used to send a ManageGPO command.
@@ -473,7 +1218,7 @@
 	 *   <li> onUpdatedBinary: write the new value</li>
 	 * </ul>
 	 */
-	class ManageGPOCallback : public Nfc::Callbacks{
+	class ManageGPOCallback : public Callbacks{
 
 	public:
 
@@ -495,30 +1240,30 @@
 			mI2CGpo =i2cGpo;
 		}
 
-		virtual void onSelectedApplication(Nfc *nfc,NFC_StatusTypeDef status){
-			if(status==NFC_SUCCESS)
+		virtual void onSelectedApplication(M24SR *nfc,StatusTypeDef status){
+			if(status==M24SR_SUCCESS)
 				nfc->SelectSystemfile();
 			else
 				onFinishCommand(nfc,status);
 		}
 
-		virtual void onSelectedSystemFile(Nfc *nfc,NFC_StatusTypeDef status){
-			if(status==NFC_SUCCESS)
+		virtual void onSelectedSystemFile(M24SR *nfc,StatusTypeDef status){
+			if(status==M24SR_SUCCESS)
 				nfc->ReadBinary(0x0004, 0x01, &mReadGpoConfig);
 			else
 				onFinishCommand(nfc,status);
 		}
 
-		virtual void onReadByte(Nfc *nfc,NFC_StatusTypeDef status,
+		virtual void onReadByte(M24SR *nfc,StatusTypeDef status,
 				uint16_t,uint8_t*, uint16_t ){
-			if(status==NFC_SUCCESS)
+			if(status==M24SR_SUCCESS)
 				nfc->Verify(M24SR::I2CPwd, 0x10, M24SR::DEFAULT_PASSWORD);
 			else
 				onFinishCommand(nfc,status);
 		}
 
-		virtual void onVerified(Nfc *nfc,NFC_StatusTypeDef status,PasswordType_t, const uint8_t*){
-			if(status!=NFC_SUCCESS)
+		virtual void onVerified(M24SR *nfc,StatusTypeDef status,PasswordType_t, const uint8_t*){
+			if(status!=M24SR_SUCCESS)
 				return onFinishCommand(nfc,status);
 
 			if(mI2CGpo)
@@ -529,10 +1274,10 @@
 			nfc->UpdateBinary(0x0004, 0x01, &mReadGpoConfig);
 		}
 
-		virtual void onUpdatedBinary(Nfc *nfc,NFC_StatusTypeDef status,
+		virtual void onUpdatedBinary(M24SR *nfc,StatusTypeDef status,
 				uint16_t , uint8_t*, uint16_t ){
 
-			if(status==NFC_SUCCESS){
+			if(status==M24SR_SUCCESS){
 				if (mGpoConfig == I2C_ANSWER_READY){
 					mParent.mCommunicationType = ASYNC;
 				}else{
@@ -549,7 +1294,7 @@
 		 * @param nfc Object where the command was send to.
 		 * @param status Command status.
 		 */
-		void onFinishCommand(Nfc *nfc,NFC_StatusTypeDef status){
+		void onFinishCommand(M24SR *nfc,StatusTypeDef status){
 			mParent.mComponentCallback=NULL;
 			if(mI2CGpo){
 				mParent.mCallback->onManageI2CGPO(nfc,status,mGpoConfig);
@@ -593,7 +1338,7 @@
 	 *   <li> ReadBinary </li>
 	 * </ul>
 	 */
-	class ReadIDCallback : public Nfc::Callbacks{
+	class ReadIDCallback : public Callbacks{
 
 	public:
 
@@ -611,22 +1356,22 @@
 			mIdPtr=idPtr;
 		}
 
-		virtual void onSelectedApplication(Nfc *nfc,NFC_StatusTypeDef status){
-			if(status==NFC_SUCCESS){
+		virtual void onSelectedApplication(M24SR *nfc,StatusTypeDef status){
+			if(status==M24SR_SUCCESS){
 				nfc->SelectSystemfile();
 			}else
 				onFinishCommand(nfc,status);
 
 		}
 
-		virtual void onSelectedSystemFile(Nfc *nfc,NFC_StatusTypeDef status){
-			if(status==NFC_SUCCESS){
+		virtual void onSelectedSystemFile(M24SR *nfc,StatusTypeDef status){
+			if(status==M24SR_SUCCESS){
 				nfc->ReadBinary(0x0011, 0x01, mIdPtr);
 			}else
 				onFinishCommand(nfc,status);
 		}
 
-		virtual void onReadByte(Nfc *nfc,NFC_StatusTypeDef status,
+		virtual void onReadByte(M24SR *nfc,StatusTypeDef status,
 			uint16_t ,uint8_t *, uint16_t ){
 			onFinishCommand(nfc,status);
 		}
@@ -638,7 +1383,7 @@
 		 * @param nfc Object where the command was send.
 		 * @param status Command status.
 		 */
-		void onFinishCommand(Nfc *nfc,NFC_StatusTypeDef status){
+		void onFinishCommand(M24SR *nfc,StatusTypeDef status){
 			mParent.mComponentCallback=NULL;
 			mParent.getCallback()->onReadId(nfc,status,mIdPtr);
 		}