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
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, committed 2016-09-30
- Comitter:
- giovannivisentini
- Date:
- Fri Sep 30 12:33:20 2016 +0000
- Parent:
- 26:2090378b0b51
- Child:
- 28:e0d4ffa90f8b
- Commit message:
- use ST_INTERFACES instead of internal Nfc_class.h
Changed in this revision
--- a/Common/nfc.h Wed Feb 03 09:01:05 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,189 +0,0 @@
-/**
- ******************************************************************************
- * @file nfc.h
- * @author ST Central Labs
- * @version V1.0.0
- * @date 14-October-2015
- * @brief This header file contains the functions prototypes for the
- * NFC device driver.
- ******************************************************************************
- * @attention
- *
- * <h2><center>© 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.
- *
- ******************************************************************************
- */
-#ifndef __NFC_H_
-#define __NFC_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Includes ------------------------------------------------------------------*/
-#include <stdint.h>
-#include "component.h"
-/** @addtogroup BSP
- * @{
- */
-
-/** @addtogroup Components
- * @{
- */
-
-/** @addtogroup NFC
- * @{
- */
-
-/** @defgroup NFC_Exported_Types
- * @{
- */
-
-/**
- * @brief NFC status enumerator definition
- */
-typedef enum {
- NFC_SUCCESS=0x9000,
- NFC_ERROR=0x6F00,
- NFC_FILE_OVERFLOW_LE = 0x6280,
- NFC_EOF = 0x6282,
- NFC_PASSWORD_REQUIRED = 0x6300,
- NFC_PASSWORD_INCORRECT = 0x63C0,
- NFC_PASSWORD_INCORRECT1RETRY = 0x63C1,
- NFC_PASSWORD_INCORRECT2RETRY = 0x63C2,
- NFC_WRONG_LENGHT = 0x6700,
- NFC_UNSUCESSFUL_UPDATING = 0x6581,
- NFC_INCOPATIBLE_COMMAND= 0x6981,
- NFC_SECURITY_UNSATISFIED = 0x6982,
- NFC_REFERENCE_DATA_NOT_USABLE = 0x6984,
-
- NFC_INCORRECT_PARAMETER = 0x6a80,
- NFC_FILE_NOT_FOUND=0x6a82,
- NFC_FILE_OVERFLOW_LC = 0x6A84, //TODO difference with Le??
-
- NFC_INCORRECT_P1_OR_P2 = 0x6A86, //TODO better name?
- NFC_RF_SESSION_KILLED=0x6500,
- NFC_INS_NOT_SUPPORTED=0x6D00,
- NFC_CLASS_NOT_SUPPORTED=0x6E00,
-
- //IOError
- NFC_IO_ERROR_I2CTIMEOUT=0x0011,
- NFC_IO_ERROR_CRC=0x0012,
- NFC_IO_ERROR_NACK=0x0013,
- NFC_IO_ERROR_PARAMETER=0x0014,
- NFC_IO_ERROR_NBATEMPT=0x0015,
- NFC_IO_NOACKNOWLEDGE=0x0016
-} NFC_StatusTypeDef;
-
-/**
- * @brief NFC component identifier enumerator definition.
- */
-typedef enum
-{
- NFC_NONE_COMPONENT = 0,
- NFC_M24SR_COMPONENT = 1
-} NFC_ComponentTypeDef;
-
-/**
- * @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;
-
-
-/**
- * @brief NFC driver structure definition
- */
-typedef struct {
- /* Generic */
- NFC_StatusTypeDef (*Init) (void *handle, void *init);
- NFC_StatusTypeDef (*ReadID) (void *handle, uint8_t *id);
-
- /* Interrupts */
- NFC_StatusTypeDef (*SendInterrupt)(void *handle);
-
- /* Specific */
- //I2C session Commands:
- NFC_StatusTypeDef (*GetSession)(void *handle);
- NFC_StatusTypeDef (*KillSession)(void *handle);
- NFC_StatusTypeDef (*Deselect)(void *handle);
-
- //NFC forum type 4 commands:
- NFC_StatusTypeDef (*SelectApplication)(void *handle);
- NFC_StatusTypeDef (*SelectCCfile)(void *handle);
- NFC_StatusTypeDef (*SelectNDEFfile)(void *handle, uint16_t NDEFfileId);
- NFC_StatusTypeDef (*SelectSystemfile)(void *handle);
- NFC_StatusTypeDef (*ReadBinary)(void *handle, uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead);
- NFC_StatusTypeDef (*UpdateBinary)(void *handle, uint16_t Offset, uint8_t NbByteToWrite, uint8_t *pDataToWrite);
-
- //ISO/IEC 7816-4 commands:
- NFC_StatusTypeDef (*Verify)(void *handle, uint16_t uPwdId, uint8_t NbPwdByte, uint8_t *pPwd);
- NFC_StatusTypeDef (*ChangeReferenceData)(void *handle, uint16_t uPwdId, uint8_t *pPwd);
- NFC_StatusTypeDef (*EnableVerificationRequirement)(void *handle, uint16_t uReadOrWrite);
- NFC_StatusTypeDef (*DisableVerificationRequirement)(void *handle, uint16_t uReadOrWrite);
-
- //ST Specific
- NFC_StatusTypeDef (*STReadBinary)(void *handle, uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead);
- NFC_StatusTypeDef (*EnablePermanentState)(void *handle, uint16_t uReadOrWrite);
- NFC_StatusTypeDef (*DisablePermanentState)(void *handle, uint16_t uReadOrWrite);
-
- //??
-
- NFC_StatusTypeDef (*StateControl)(void *handle, uint8_t uSetOrReset);
- NFC_StatusTypeDef (*ManageI2CGPO)(void *handle, uint8_t GPO_I2Cconfig);
- NFC_StatusTypeDef (*ManageRFGPO)(void *handle, uint8_t GPO_RFconfig);
- NFC_StatusTypeDef (*RFConfig)(void *handle, uint8_t OnOffChoice);
-
-} NFC_DrvVTableTypeDef;
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __NFC_H_ */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/Interfaces/Component_class.h Wed Feb 03 09:01:05 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-/**
- ******************************************************************************
- * @file Component_class.h
- * @author AST / EST
- * @version V0.0.1
- * @date 13-April-2015
- * @brief This file contains the abstract class describing the interface of a
- * generic component.
- ******************************************************************************
- * @attention
- *
- * <h2><center>© 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.
- *
- ******************************************************************************
- */
-
-
-/* Define to prevent from recursive inclusion --------------------------------*/
-
-#ifndef __COMPONENT_CLASS_H
-#define __COMPONENT_CLASS_H
-
-
-/* Includes ------------------------------------------------------------------*/
-
-#include <stdint.h>
-
-
-/* Classes ------------------------------------------------------------------*/
-
-/** An abstract class for Generic components.
- */
-class Component
-{
-public:
- /**
- * @brief Initializing the component.
- * @param init pointer to device specific initalization structure.
- * @retval "0" in case of success, an error code otherwise.
- */
- virtual int Init(void *init) = 0;
-
- /**
- * @brief Getting the ID of the component.
- * @param[out] id pointer to an allocated variable to store the ID into.
- * @retval "0" in case of success, an error code otherwise.
- */
- virtual int ReadID(uint8_t *id) = 0;
-};
-
-#endif /* __COMPONENT_CLASS_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/Interfaces/Nfc_class.h Wed Feb 03 09:01:05 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,893 +0,0 @@
-/**
- ******************************************************************************
- * @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>© 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 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 Nfc : public Component
-{
-public:
-
- /**
- * 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;
-
- /**
- * 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 Nfc#GetSession
- * @see Nfc#ForceGetSession */
- virtual void onSessionOpen(Nfc *nfc,NFC_StatusTypeDef status){
- (void)nfc; (void)status;
- }
-
- /** called when Deselect completes
- * @see Nfc#Deselect */
- virtual void onDeselect(Nfc *nfc,NFC_StatusTypeDef status){
- (void)nfc; (void)status;
- }
-
- /** called when SelectedApplication completes
- * @see Nfc#SelectedApplication */
- virtual void onSelectedApplication(Nfc *nfc,NFC_StatusTypeDef status){
- (void)nfc; (void)status;
- }
-
- /** called when SelectedCCFile completes
- * @see Nfc#SelectedCCFile */
- virtual void onSelectedCCFile(Nfc *nfc,NFC_StatusTypeDef status){
- (void)nfc; (void)status;
- }
-
- /** called when SelectedNDEFFile completes
- * @see Nfc#SelectedNDEFFile */
- virtual void onSelectedNDEFFile(Nfc *nfc,NFC_StatusTypeDef status){
- (void)nfc; (void)status;
- }
-
- /** called when SelectedSystemFile completes
- * @see Nfc#SelectedSystemFile */
- virtual void onSelectedSystemFile(Nfc *nfc,NFC_StatusTypeDef status){
- (void)nfc; (void)status;
- }
-
- /** called when ReadBinary or STReadBinary completes
- * @see Nfc#ReadBinary
- * @see Nfc#STReadBinary */
- 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;
- }
-
- /** called when UpdatedBinary completes
- * @see Nfc#UpdatedBinary */
- 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;
- }
-
- /** called when Verify completes
- * @see Nfc#Verify */
- virtual void onVerified(Nfc *nfc,NFC_StatusTypeDef status,PasswordType_t uPwdId,
- const uint8_t *pwd){
- (void)nfc; (void)status;(void)uPwdId;(void)pwd;
- }
-
- /** called when ManageI2CGPO completes
- * @see Nfc#ManageI2CGPO */
- virtual void onManageI2CGPO(Nfc *nfc,NFC_StatusTypeDef status,NFC_GPO_MGMT newStatus){
- (void)nfc; (void)status;(void)newStatus;
- }
-
- /** called when ManageRFGPO completes
- * @see Nfc#ManageRFGPO */
- virtual void onManageRFGPO(Nfc *nfc,NFC_StatusTypeDef status,NFC_GPO_MGMT newStatus){
- (void)nfc; (void)status;(void)newStatus;
- }
-
- /** called when ChangeReferenceData completes
- * @see Nfc#ChangeReferenceData */
- virtual void onChangeReferenceData(Nfc *nfc ,NFC_StatusTypeDef status,PasswordType_t type,
- uint8_t *data){
- (void)nfc; (void)status;(void)type;(void)data;
- }
-
- /** called when EnableVerificationRequirement completes
- * @see Nfc#EnableVerificationRequirement */
- virtual void onEnableVerificationRequirement(Nfc *nfc ,NFC_StatusTypeDef status,PasswordType_t type){
- (void)nfc; (void)status;(void)type;
- }
-
- /** called when DisableVerificationRequirement completes
- * @see Nfc#DisableVerificationRequirement */
- virtual void onDisableVerificationRequirement(Nfc *nfc , NFC_StatusTypeDef status,PasswordType_t type){
- (void)nfc; (void)status;(void)type;
- }
-
- /** called when EnablePermanentState completes
- * @see Nfc#EnablePermanentState */
- virtual void onEnablePermanentState(Nfc *nfc, NFC_StatusTypeDef status, PasswordType_t type){
- (void)nfc; (void)status;(void)type;
- }
-
- /** called when DisablePermanentState completes
- * @see Nfc#DisablePermanentState */
- virtual void onDisablePermanentState(Nfc *nfc, NFC_StatusTypeDef status, PasswordType_t type){
- (void)nfc; (void)status;(void)type;
- }
-
- /** called when ReadId completes
- * @see Nfc#ReadId */
- virtual void onReadId(Nfc *nfc, NFC_StatusTypeDef status, uint8_t *id){
- (void)nfc; (void)status;(void)id;
- }
-
- /** called when EnableReadPassword completes
- * @see Nfc#EnableReadPassword */
- virtual void onEnableReadPassword(Nfc *nfc, NFC_StatusTypeDef status,const uint8_t *newPwd){
- (void)nfc; (void)status;(void)newPwd;
- }
-
- /** called when EnableWritePassword completes
- * @see Nfc#EnableWritePassword */
- virtual void onEnableWritePassword(Nfc *nfc, NFC_StatusTypeDef status,const uint8_t *newPwd){
- (void)nfc; (void)status;(void)newPwd;
- }
-
- /** called when DisableReadPassword completes
- * @see Nfc#DisableReadPassword */
- virtual void onDisableReadPassword(Nfc *nfc, NFC_StatusTypeDef status){
- (void)nfc; (void)status;
- }
-
- /** called when DisableWritePassword completes
- * @see Nfc#DisableWritePassword */
- virtual void onDisableWritePassword(Nfc *nfc, NFC_StatusTypeDef status){
- (void)nfc; (void)status;
- }
-
- /** called when DisableAllPassword completes
- * @see Nfc#DisableAllPassword */
- virtual void onDisableAllPassword(Nfc *nfc, NFC_StatusTypeDef status){
- (void)nfc; (void)status;
- }
-
-
- /** called when EnableReadOnly completes
- * @see Nfc#EnableReadOnly */
- virtual void onEnableReadOnly(Nfc *nfc,NFC_StatusTypeDef status){
- (void)nfc; (void)status;
- }
-
- /** called when EnableWriteOnly completes
- * @see Nfc#EnableWriteOnly */
- virtual void onEnableWriteOnly(Nfc *nfc,NFC_StatusTypeDef status){
- (void)nfc; (void)status;
- }
-
-
- /** called when DisableReadOnly completes
- * @see Nfc#DisableReadOnly */
- virtual void onDisableReadOnly(Nfc *nfc,NFC_StatusTypeDef status){
- (void)nfc; (void)status;
- }
-
- /** called when DisableWriteOnly completes
- * @see Nfc#DisableWriteOnly */
- virtual void onDisableWriteOnly(Nfc *nfc,NFC_StatusTypeDef status){
- (void)nfc; (void)status;
- }
-
- virtual ~Callbacks(){};
- };
-
- 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(Callbacks *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;
-
-
- ///////////////////////HIGH LEVEL / UTILITY FUNCTIONS ////////////////////////////////////
-
- /**
- * 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 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.
- */
- Nfc::Callbacks *mComponentCallback;
-
- /**
- * get the callback object to use
- * @return callback object to use
- */
- Nfc::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 Nfc::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(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 callbacks and call the user callback.
- * @param nfc Object triggering the command.
- * @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 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 Nfc::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(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 triggering the command.
- * @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 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 Nfc::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(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 triggering the command.
- * @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****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES.lib Fri Sep 30 12:33:20 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#a7810e7acf8d
--- a/X_NUCLEO_NFC01A1.cpp Wed Feb 03 09:01:05 2016 +0000
+++ b/X_NUCLEO_NFC01A1.cpp Fri Sep 30 12:33:20 2016 +0000
@@ -2,7 +2,7 @@
******************************************************************************
* @file X_NUCLEO_NFC01A1.h
* @author ST Central Labs
- * @date 05 Nov 2015
+ * @date 30 Set 2016
* @brief Singleton class that controls all the electronics inside the
* X_NUCLEO_NFC01A1 expansion board
******************************************************************************
@@ -50,7 +50,7 @@
X_NUCLEO_NFC01A1 *X_NUCLEO_NFC01A1::mInstance = NULL;
X_NUCLEO_NFC01A1* X_NUCLEO_NFC01A1::Instance(I2C &devI2C,
- Nfc::gpoEventCallback gpoEventCallback,
+ M24SR::gpoEventCallback gpoEventCallback,
const PinName &gpoName,
const PinName &RFDisableName, const PinName &led1Name,
const PinName &led2Name, const PinName &led3Name) {
--- a/X_NUCLEO_NFC01A1.h Wed Feb 03 09:01:05 2016 +0000 +++ b/X_NUCLEO_NFC01A1.h Fri Sep 30 12:33:20 2016 +0000 @@ -2,8 +2,8 @@ ****************************************************************************** * @file X_NUCLEO_NFC01A1.h * @author ST Central Labs - * @version V1.0.0 - * @date 05 Nov 2015 + * @version V1.1.0 + * @date 30 Set 2016 * @brief Singleton class that controls all the electronics inside the * X_NUCLEO_NFC01A1 expansion board. ****************************************************************************** @@ -71,7 +71,7 @@ * @param led2Name Pin to control the led1 status. * @param led3Name Pin to control the led1 status. */ - X_NUCLEO_NFC01A1(I2C &devI2C,Nfc::gpoEventCallback eventCallback, + X_NUCLEO_NFC01A1(I2C &devI2C,M24SR::gpoEventCallback eventCallback, const PinName &gpoName, const PinName &RFDisableName, const PinName &led1Name, const PinName &led2Name, const PinName &led3Name): @@ -98,7 +98,7 @@ * @param led3Name Pin to control the led1 status. */ static X_NUCLEO_NFC01A1* Instance(I2C &devI2C, - Nfc::gpoEventCallback eventCallback=NULL, + M24SR::gpoEventCallback eventCallback=NULL, const PinName &gpoName = DEFAULT_GPO_PIN, const PinName &RFDisableName = DEFAULT_RF_DISABLE_PIN, const PinName &led1Name = DEFAULT_LED1_PIN,
--- a/m24sr/NDefNfcTagM24SR.cpp Wed Feb 03 09:01:05 2016 +0000
+++ b/m24sr/NDefNfcTagM24SR.cpp Fri Sep 30 12:33:20 2016 +0000
@@ -2,8 +2,8 @@
******************************************************************************
* @file NdefNfcTagSTM24SR.cpp
* @author ST Central Labs
- * @version V1.0.0
- * @date 05 Nov 2015
+ * @version V1.1.0
+ * @date 30 Set 2016
* @brief Wrapper class of the NDefLib library to write/read NDEF messages
******************************************************************************
* @attention
@@ -51,18 +51,18 @@
OpenSessionCallBack(NDefNfcTagM24SR& sender):
mSender(sender),mNTrials(OPENSESSION_NTRIALS){}
-void NDefNfcTagM24SR::OpenSessionCallBack::onSessionOpen(Nfc *nfc,
- NFC_StatusTypeDef status){
- if(status==NFC_SUCCESS){
+void NDefNfcTagM24SR::OpenSessionCallBack::onSessionOpen(M24SR *nfc,
+ M24SR::StatusTypeDef status){
+ if(status==M24SR::M24SR_SUCCESS){
nfc->SelectApplication();
}else{
mSender.mCallBack->onSessionOpen(&mSender,false);
}
}
-void NDefNfcTagM24SR::OpenSessionCallBack::onSelectedApplication(Nfc *nfc,
- NFC_StatusTypeDef status){
- if(status==NFC_SUCCESS){
+void NDefNfcTagM24SR::OpenSessionCallBack::onSelectedApplication(M24SR *nfc,
+ M24SR::StatusTypeDef status){
+ if(status==M24SR::M24SR_SUCCESS){
nfc->SelectCCfile();
}else{
if(mNTrials==0)
@@ -74,19 +74,19 @@
}//if-else
}
-void NDefNfcTagM24SR::OpenSessionCallBack::onSelectedCCFile(Nfc *nfc,
- NFC_StatusTypeDef status){
- if(status==NFC_SUCCESS){
+void NDefNfcTagM24SR::OpenSessionCallBack::onSelectedCCFile(M24SR *nfc,
+ M24SR::StatusTypeDef status){
+ if(status==M24SR::M24SR_SUCCESS){
nfc->ReadBinary(0x0000, CC_FILE_LENGTH_BYTE, CCFile);
}else{
mSender.mCallBack->onSessionOpen(&mSender,false);
}
}
-void NDefNfcTagM24SR::OpenSessionCallBack::onReadByte(Nfc *nfc,
- NFC_StatusTypeDef status,uint16_t offset,uint8_t *readByte, uint16_t nReadByte){
+void NDefNfcTagM24SR::OpenSessionCallBack::onReadByte(M24SR *nfc,
+ M24SR::StatusTypeDef status,uint16_t offset,uint8_t *readByte, uint16_t nReadByte){
(void)offset;
- if(status!=NFC_SUCCESS || nReadByte!=CC_FILE_LENGTH_BYTE){
+ if(status!=M24SR::M24SR_SUCCESS || nReadByte!=CC_FILE_LENGTH_BYTE){
return mSender.mCallBack->onSessionOpen(&mSender,false);
}//else
uint16_t NDefFileId = (uint16_t) ((readByte[0x09] << 8) | readByte[0x0A]);
@@ -95,10 +95,11 @@
nfc->SelectNDEFfile(NDefFileId);
}
-void NDefNfcTagM24SR::OpenSessionCallBack::onSelectedNDEFFile(Nfc *nfc,
- NFC_StatusTypeDef status){
+void NDefNfcTagM24SR::OpenSessionCallBack::onSelectedNDEFFile(M24SR *nfc,
+ M24SR::StatusTypeDef status){
(void)nfc;
- mSender.mIsSessionOpen = status==NFC_SUCCESS;
+
+ mSender.mIsSessionOpen = status==M24SR::M24SR_SUCCESS;
mSender.mCallBack->onSessionOpen(&mSender,mSender.mIsSessionOpen);
}
////////////////////////////END OpenSessionCallBack/////////////////////////
@@ -112,22 +113,22 @@
mDevice.SetCallback(&mOpenSessionCallback);
if(force)
- return mDevice.ForceGetSession() == NFC_SUCCESS;
+ return mDevice.ForceGetSession() == M24SR::M24SR_SUCCESS;
else
- return mDevice.GetSession() == NFC_SUCCESS;
+ return mDevice.GetSession() == M24SR::M24SR_SUCCESS;
}
bool NDefNfcTagM24SR::closeSession() {
mDevice.SetCallback(&mCloseSessionCallback);
- return mDevice.Deselect() == NFC_SUCCESS;
+ return mDevice.Deselect() == M24SR::M24SR_SUCCESS;
}
-void NDefNfcTagM24SR::WriteByteCallback::onUpdatedBinary(Nfc *nfc,
- NFC_StatusTypeDef status,uint16_t startOffset, uint8_t *writeByte,uint16_t nWriteByte){
+void NDefNfcTagM24SR::WriteByteCallback::onUpdatedBinary(M24SR *nfc,
+ M24SR::StatusTypeDef status,uint16_t startOffset, uint8_t *writeByte,uint16_t nWriteByte){
- if(status!=NFC_SUCCESS){ // error -> finish to write
+ if(status!=M24SR::M24SR_SUCCESS){ // error -> finish to write
mCallback(mCallbackParam,false,mByteToWrite,mNByteToWrite);
return;
}//else
@@ -151,17 +152,17 @@
mDevice.SetCallback(&mWriteByteCallback);
if (length > mMaxWriteBytes) {
- return mDevice.UpdateBinary(offset, mMaxWriteBytes,(uint8_t*) buffer) == NFC_SUCCESS;
+ return mDevice.UpdateBinary(offset, mMaxWriteBytes,(uint8_t*) buffer) == M24SR::M24SR_SUCCESS;
}else{
- return mDevice.UpdateBinary(offset,length,(uint8_t*)buffer) == NFC_SUCCESS;
+ return mDevice.UpdateBinary(offset,length,(uint8_t*)buffer) == M24SR::M24SR_SUCCESS;
}//if-else
}
-void NDefNfcTagM24SR::ReadByteCallback::onReadByte(Nfc *nfc,
- NFC_StatusTypeDef status,uint16_t startOffset, uint8_t *readBffer,uint16_t nReadByte){
+void NDefNfcTagM24SR::ReadByteCallback::onReadByte(M24SR *nfc,
+ M24SR::StatusTypeDef status,uint16_t startOffset, uint8_t *readBffer,uint16_t nReadByte){
- if(status!=NFC_SUCCESS){ // error -> finish to write
+ if(status!=M24SR::M24SR_SUCCESS){ // error -> finish to write
mCallback(mCallbackParam,false,mBuffer,mNByteToRead);
return;
}//else
@@ -187,9 +188,9 @@
mDevice.SetCallback(&mReadByteCallback);
if (length > mMaxReadBytes) {
- return mDevice.ReadBinary(byteOffset, mMaxReadBytes,buffer)== NFC_SUCCESS;;
+ return mDevice.ReadBinary(byteOffset, mMaxReadBytes,buffer)== M24SR::M24SR_SUCCESS;;
}else{
- return mDevice.ReadBinary(byteOffset,length,buffer)== NFC_SUCCESS;;
+ return mDevice.ReadBinary(byteOffset,length,buffer)== M24SR::M24SR_SUCCESS;;
}//if-else
}
--- a/m24sr/NDefNfcTagM24SR.h Wed Feb 03 09:01:05 2016 +0000
+++ b/m24sr/NDefNfcTagM24SR.h Fri Sep 30 12:33:20 2016 +0000
@@ -2,8 +2,8 @@
******************************************************************************
* @file Type4NfcTagM24SR.h
* @author ST Central Labs
- * @version V1.0.0
- * @date 05 Nov 2015
+ * @version V1.1.0
+ * @date 30 Set 2016
* @brief M24SR specific NDefLib derived class
******************************************************************************
* @attention
@@ -43,7 +43,7 @@
#include "NDefLib/NDefNfcTag.h"
-#include "Nfc_class.h"
+#include "m24sr_class.h"
/**
* Helper class to use the NDefLib
@@ -56,7 +56,7 @@
*
* @param device device to use
*/
- NDefNfcTagM24SR(Nfc &device) :
+ NDefNfcTagM24SR(M24SR &device):
NDefLib::NDefNfcTag(),
mDevice(device),mIsSessionOpen(false),
mMaxReadBytes(0xFF), mMaxWriteBytes(0xFF),
@@ -91,7 +91,7 @@
private:
- Nfc &mDevice;
+ M24SR &mDevice;
/**
* true if the session is open
@@ -112,16 +112,16 @@
* Class containing the callback needed to open a session and read the max
* read/write size
*/
- class OpenSessionCallBack: public Nfc::Callbacks{
+ class OpenSessionCallBack: public M24SR::Callbacks{
public:
OpenSessionCallBack(NDefNfcTagM24SR &sender);
- virtual void onSessionOpen(Nfc *nfc,NFC_StatusTypeDef status);
- virtual void onSelectedApplication(Nfc *nfc,NFC_StatusTypeDef status);
- virtual void onSelectedCCFile(Nfc *nfc,NFC_StatusTypeDef status);
- virtual void onReadByte(Nfc *nfc,NFC_StatusTypeDef status,uint16_t offset,
+ virtual void onSessionOpen(M24SR *nfc,M24SR::StatusTypeDef status);
+ virtual void onSelectedApplication(M24SR *nfc,M24SR::StatusTypeDef status);
+ virtual void onSelectedCCFile(M24SR *nfc,M24SR::StatusTypeDef status);
+ virtual void onReadByte(M24SR *nfc,M24SR::StatusTypeDef status,uint16_t offset,
uint8_t *readByte, uint16_t nReadByte);
- virtual void onSelectedNDEFFile(Nfc *nfc,NFC_StatusTypeDef status);
+ virtual void onSelectedNDEFFile(M24SR *nfc,M24SR::StatusTypeDef status);
private:
/**
@@ -146,14 +146,14 @@
/**
* Class containing the callback needed to close a session
*/
- class CloseSessionCallBack : public Nfc::Callbacks{
+ class CloseSessionCallBack : public M24SR::Callbacks{
public:
CloseSessionCallBack(NDefNfcTagM24SR &sender):
mSender(sender){}
- virtual void onDeselect(Nfc *nfc,NFC_StatusTypeDef status){
+ virtual void onDeselect(M24SR *nfc,M24SR::StatusTypeDef status){
(void)nfc;
- if(status==NFC_SUCCESS){
+ if(status==M24SR::M24SR_SUCCESS){
mSender.mIsSessionOpen=false;
mSender.mCallBack->onSessionClose(&mSender,true);
}else{
@@ -174,7 +174,7 @@
/**
* Class containing the callback needed to write a buffer
*/
- class WriteByteCallback : public Nfc::Callbacks{
+ class WriteByteCallback : public M24SR::Callbacks{
public:
/**
@@ -205,7 +205,7 @@
mCallbackParam = param;
}
- virtual void onUpdatedBinary(Nfc *nfc,NFC_StatusTypeDef status,
+ virtual void onUpdatedBinary(M24SR *nfc,M24SR::StatusTypeDef status,
uint16_t startOffset,uint8_t *writeByte,uint16_t nWriteByte);
@@ -233,7 +233,7 @@
/**
* Class containing the callback needed to read a buffer
*/
- class ReadByteCallback : public Nfc::Callbacks{
+ class ReadByteCallback : public M24SR::Callbacks{
public:
/**
@@ -264,7 +264,7 @@
mCallbackParam = param;
}
- virtual void onReadByte(Nfc *nfc,NFC_StatusTypeDef status,
+ virtual void onReadByte(M24SR *nfc,M24SR::StatusTypeDef status,
uint16_t offset,uint8_t *readByte, uint16_t nReadByte);
--- a/m24sr/m24sr.h Wed Feb 03 09:01:05 2016 +0000
+++ b/m24sr/m24sr.h Fri Sep 30 12:33:20 2016 +0000
@@ -34,7 +34,7 @@
#endif
/* Includes ------------------------------------------------------------------*/
-#include "Common/nfc.h"
+#include "Nfc.h"
/** @addtogroup M24SR_Driver
* @{
--- a/m24sr/m24sr_class.cpp Wed Feb 03 09:01:05 2016 +0000
+++ b/m24sr/m24sr_class.cpp Fri Sep 30 12:33:20 2016 +0000
@@ -2,8 +2,8 @@
******************************************************************************
* @file m24sr_class.cpp
* @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.
******************************************************************************
@@ -39,8 +39,10 @@
/* Includes ------------------------------------------------------------------*/
+#include "m24sr.h"
#include "m24sr_class.h"
-#include "m24sr.h"
+#include "NDefNfcTagM24SR.h"
+
#ifdef GPIO_PIN_RESET
#undef GPIO_PIN_RESET
#endif
@@ -74,14 +76,14 @@
/** value returned by the NFC chip when a command is successfully completed */
#define NFC_COMMAND_SUCCESS 0x9000
-/** call the fCall function and check that the return status is NFC_SUCCESS,
+/** call the fCall function and check that the return status is M24SR_SUCCESS,
* otherwise return the error status*/
#define errchk(fCall) {\
- const NFC_StatusTypeDef status = (fCall); \
- if((status!=NFC_SUCCESS)) \
- return status; \
+ const int status = (int) (fCall); \
+ if((status!=M24SR_SUCCESS)){ \
+ return (M24SR::StatusTypeDef)status; \
}\
-
+}
#endif
/**
@@ -123,29 +125,31 @@
* @retval Status (SW1&SW2) : CRC16 residue is correct
* @retval M24SR_ERROR_CRC : CRC16 residue is false
*/
- static NFC_StatusTypeDef M24SR_IsCorrectCRC16Residue(uint8_t *DataIn, uint8_t Length) {
+ static M24SR::StatusTypeDef M24SR_IsCorrectCRC16Residue(uint8_t *DataIn, uint8_t Length) {
uint16_t ResCRC = 0x0000;
-
+ M24SR::StatusTypeDef status;
/* check the CRC16 Residue */
if (Length != 0)
ResCRC = M24SR_ComputeCrc(DataIn, Length);
if (ResCRC == 0x0000) {
/* Good CRC, but error status from M24SR */
- return (NFC_StatusTypeDef) (((DataIn[Length - UB_STATUS_OFFSET] << 8)
+ status = (M24SR::StatusTypeDef) (((DataIn[Length - UB_STATUS_OFFSET] << 8)
& 0xFF00) | (DataIn[Length - LB_STATUS_OFFSET] & 0x00FF));
} else {
ResCRC = 0x0000;
ResCRC = M24SR_ComputeCrc(DataIn, 5);
if (ResCRC != 0x0000) {
/* Bad CRC */
- return NFC_IO_ERROR_CRC;
+ return M24SR::M24SR_IO_ERROR_CRC;
} else {
/* Good CRC, but error status from M24SR */
- return (NFC_StatusTypeDef) (((DataIn[1] << 8) & 0xFF00)
+ status= (M24SR::StatusTypeDef) (((DataIn[1] << 8) & 0xFF00)
| (DataIn[2] & 0x00FF));
}
}
+ if(status==NFC_COMMAND_SUCCESS) status = M24SR::M24SR_SUCCESS;
+ return status;
}
/**
@@ -216,30 +220,63 @@
}
+
+
/**
* @brief This function returns M24SR_STATUS_SUCCESS if the pBuffer is an s-block
* @param pBuffer : pointer to the data
- * @retval NFC_SUCCESS : the data is a S-Block
+ * @retval M24SR_SUCCESS : the data is a S-Block
* @retval NFC_ERROR : the data is not a S-Block
*/
- static NFC_StatusTypeDef IsSBlock(uint8_t *pBuffer) {
+ static M24SR::StatusTypeDef IsSBlock(uint8_t *pBuffer) {
if ((pBuffer[M24SR_OFFSET_PCB] & M24SR_MASK_BLOCK) == M24SR_MASK_SBLOCK) {
- return NFC_SUCCESS;
+ return M24SR::M24SR_SUCCESS;
} else {
- return NFC_ERROR;
+ return M24SR::M24SR_ERROR;
}
}
+
+M24SR::M24SR(const uint8_t address, I2C &I2C,gpoEventCallback eventCallback, const PinName& GPOPinName,
+ const PinName& RFDISPinName) :
+ who_am_i(0),
+ type(0),
+ address(address),
+ dev_I2C(I2C),
+ GPOPin(GPOPinName),
+ RFDisablePin(RFDISPinName),
+ mCommunicationType(SYNC),
+ mLastCommandSend(NONE),
+ mGpoEventInterrupt(GPOPinName),
+ mManageGPOCallback(*this),
+ mCallback(&defaultCallback),
+ mComponentCallback(NULL),
+ mNDefTagUtil(new NDefNfcTagM24SR(*this)),
+ mReadIDCallback(*this){
+ //mNDefTagUtil(NULL){
+ memset(uM24SRbuffer, 0, 0xFF * sizeof(int8_t));
+ uDIDbyte = 0;
+ RFDisablePin = 0;
+ if(eventCallback!=NULL)
+ mGpoEventInterrupt.fall(eventCallback);
+ mGpoEventInterrupt.mode(PullUp);
+ mGpoEventInterrupt.disable_irq();
+}
+
+M24SR::~M24SR(){
+ delete mNDefTagUtil;
+}
+
/**
* @brief This function sends the FWT extension command (S-Block format)
* @param FWTbyte : FWT value
- * @return NFC_SUCCESS if no errors
+ * @return M24SR_SUCCESS if no errors
*/
- NFC_StatusTypeDef M24SR::M24SR_SendFWTExtension(uint8_t FWTbyte) {
+ M24SR::StatusTypeDef M24SR::M24SR_SendFWTExtension(uint8_t FWTbyte) {
uint8_t pBuffer[M24SR_STATUSRESPONSE_NBBYTE];
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
uint8_t NthByte = 0;
uint16_t uCRC16;
@@ -254,14 +291,14 @@
/* send the request */
status = M24SR_IO_SendI2Ccommand(NthByte, pBuffer);
- if(status != NFC_SUCCESS)
+ if(status != M24SR_SUCCESS)
return status;
mLastCommandSend=UPDATE;
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status == NFC_SUCCESS)
+ if(status == M24SR_SUCCESS)
return M24SR_ReceiveUpdateBinary();
else{
mLastCommandSend = NONE;
@@ -271,37 +308,46 @@
}//if-else
}//if
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
/**
* @brief This function initialize the M24SR device
* @retval None
*/
- NFC_StatusTypeDef M24SR::M24SR_Init(M24SR_InitTypeDef *notUsed) {
+ M24SR::StatusTypeDef M24SR::M24SR_Init(M24SR_InitTypeDef *notUsed) {
(void) notUsed;
//force to open a i2c session
- errchk(M24SR_ForceSession())
+ StatusTypeDef status = M24SR_ForceSession();
+ if(status!= M24SR_SUCCESS)
+ return status;
//leave the gpo always up
- errchk(M24SR_ManageI2CGPO(DEFAULT_GPO_STATUS))
- errchk(M24SR_ManageRFGPO(DEFAULT_GPO_STATUS))
+ status = M24SR_ManageI2CGPO(DEFAULT_GPO_STATUS);
+ if(status!= M24SR_SUCCESS)
+ return status;
+ status = M24SR_ManageRFGPO(DEFAULT_GPO_STATUS);
+ if(status!= M24SR_SUCCESS)
+ return status;
//close the session
- errchk(M24SR_Deselect())
+ status = M24SR_Deselect();
+ if(status!= M24SR_SUCCESS)
+ return status;
+
mGpoEventInterrupt.enable_irq();
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
/**
* @brief This function sends the KillSession command to the M24SR device
* @param None
- * @return NFC_SUCCESS if no errors
+ * @return M24SR_SUCCESS if no errors
*/
- NFC_StatusTypeDef M24SR::M24SR_ForceSession(void) {
+ M24SR::StatusTypeDef M24SR::M24SR_ForceSession(void) {
uint8_t commandBuffer[] = M24SR_KILLSESSION_COMMAND;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
status = M24SR_IO_SendI2Ccommand(sizeof(commandBuffer), commandBuffer);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
mCallback->onSessionOpen(this,status);
return status;
}
@@ -318,14 +364,14 @@
/**
* @brief This function sends the Deselect command (S-Block format)
- * @return NFC_SUCCESS if no errors
+ * @return M24SR_SUCCESS if no errors
*/
- NFC_StatusTypeDef M24SR::M24SR_Deselect(void) {
+ M24SR::StatusTypeDef M24SR::M24SR_Deselect(void) {
uint8_t pBuffer[] = M24SR_DESELECTREQUEST_COMMAND;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
/* send the request */
status = M24SR_IO_SendI2Ccommand(sizeof(pBuffer), pBuffer);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onDeselect(this,status);
}
@@ -333,7 +379,7 @@
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status == NFC_SUCCESS)
+ if(status == M24SR_SUCCESS)
return M24SR_ReceiveDeselect();
else{
mLastCommandSend = NONE;
@@ -343,12 +389,12 @@
}
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_ReceiveDeselect(void){
+M24SR::StatusTypeDef M24SR::M24SR_ReceiveDeselect(void){
uint8_t pBuffer[4];
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
status = M24SR_IO_ReceiveI2Cresponse(sizeof(pBuffer), pBuffer);
getCallback()->onDeselect(this,status);
return status;
@@ -358,15 +404,15 @@
/**
* @brief This function sends the GetSession command to the M24SR device
- * @retval NFC_SUCCESS the function is successful.
+ * @retval M24SR_SUCCESS the function is successful.
* @retval Status (SW1&SW2) if operation does not complete.
*/
- NFC_StatusTypeDef M24SR::M24SR_GetSession(void) {
+ M24SR::StatusTypeDef M24SR::M24SR_GetSession(void) {
uint8_t commandBuffer[] = M24SR_OPENSESSION_COMMAND;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
status = M24SR_IO_SendI2Ccommand(sizeof(commandBuffer), commandBuffer);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onSessionOpen(this,status);
return status;
}
@@ -382,12 +428,12 @@
/**
* @brief This function sends the SelectApplication command
- * @return NFC_SUCCESS if no errors
+ * @return M24SR_SUCCESS if no errors
*/
- NFC_StatusTypeDef M24SR::M24SR_SendSelectApplication(void) {
+ M24SR::StatusTypeDef M24SR::M24SR_SendSelectApplication(void) {
C_APDU command;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
uint8_t *pBuffer = uM24SRbuffer;
uint8_t pDataOut[] = M24SR_SELECTAPPLICATION_COMMAND;
uint8_t uLe = 0x00;
@@ -411,7 +457,7 @@
/* send the request */
status = M24SR_IO_SendI2Ccommand(NbByte, pBuffer);
- if(status != NFC_SUCCESS){
+ if(status != M24SR_SUCCESS){
getCallback()->onSelectedApplication(this,status);
return status;
}
@@ -420,7 +466,7 @@
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status == NFC_SUCCESS)
+ if(status == M24SR_SUCCESS)
return M24SR_ReceiveSelectApplication();
else{
mLastCommandSend = NONE;
@@ -429,18 +475,18 @@
}//if-else
}//if
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_ReceiveSelectApplication(void) {
+M24SR::StatusTypeDef M24SR::M24SR_ReceiveSelectApplication(void) {
uint8_t pDataIn[M24SR_STATUSRESPONSE_NBBYTE];
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
mLastCommandSend = NONE;
status = M24SR_IO_ReceiveI2Cresponse(sizeof(pDataIn), pDataIn);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onSelectedApplication(this,status);
return status;
}//else
@@ -452,9 +498,9 @@
-NFC_StatusTypeDef M24SR::M24SR_ReadID(uint8_t *nfc_id) {
+M24SR::StatusTypeDef M24SR::M24SR_ReadID(uint8_t *nfc_id) {
if (!nfc_id) {
- return NFC_ERROR;
+ return M24SR_ERROR;
}
//enable the callback for change the gpo
@@ -467,13 +513,13 @@
/**
* @brief This function sends the SelectCCFile command
- * @retval NFC_SUCCESS the function is successful.
+ * @retval M24SR_SUCCESS the function is successful.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
* @retval Status (SW1&SW2) if operation does not complete for another reason.
*/
- NFC_StatusTypeDef M24SR::M24SR_SendSelectCCfile(void) {
+ M24SR::StatusTypeDef M24SR::M24SR_SendSelectCCfile(void) {
C_APDU command;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
uint8_t *pBuffer = uM24SRbuffer;
uint8_t pDataOut[] = CC_FILE_ID_BYTES;
uint16_t uP1P2 =0x000C,
@@ -494,7 +540,7 @@
/* send the request */
status = M24SR_IO_SendI2Ccommand(NbByte, pBuffer);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onSelectedCCFile(this,status);
return status;
}//else
@@ -504,7 +550,7 @@
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status==NFC_SUCCESS)
+ if(status==M24SR_SUCCESS)
return M24SR_ReceiveSelectCCfile();
else{
mLastCommandSend = NONE;
@@ -513,18 +559,18 @@
}//if-else
}//if
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_ReceiveSelectCCfile(void){
+M24SR::StatusTypeDef M24SR::M24SR_ReceiveSelectCCfile(void){
uint8_t pDataIn[M24SR_STATUSRESPONSE_NBBYTE];
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
mLastCommandSend = NONE;
status = M24SR_IO_ReceiveI2Cresponse(sizeof(pDataIn), pDataIn);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onSelectedCCFile(this,status);
return status;
}//else
@@ -539,12 +585,12 @@
* @retval Status (SW1&SW2) Status of the operation to complete.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
*/
- NFC_StatusTypeDef M24SR::M24SR_SendSelectSystemfile(void) {
+ M24SR::StatusTypeDef M24SR::M24SR_SendSelectSystemfile(void) {
C_APDU command;
uint8_t *pBuffer = uM24SRbuffer;
uint8_t pDataOut[] = SYSTEM_FILE_ID_BYTES;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
uint16_t uP1P2 =0x000C, NbByte;
/* build the command */
@@ -556,13 +602,13 @@
/* copy the number of byte of the data field */
command.Body.LC = sizeof(pDataOut);
command.Body.pData = pDataOut;
- /* build the I²C command */
+ /* build the I²C command */
M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_SELECTCCFILE, &command, uDIDbyte,
&NbByte, pBuffer);
/* send the request */
status = M24SR_IO_SendI2Ccommand(NbByte, pBuffer);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onSelectedSystemFile(this,status);
return status;
}//else
@@ -571,7 +617,7 @@
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status == NFC_SUCCESS)
+ if(status == M24SR_SUCCESS)
return M24SR_ReceiveSelectSystemfile();
else{
mLastCommandSend = NONE;
@@ -580,18 +626,18 @@
}//if-else
}//if
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_ReceiveSelectSystemfile(){
+M24SR::StatusTypeDef M24SR::M24SR_ReceiveSelectSystemfile(){
uint8_t pDataIn[M24SR_STATUSRESPONSE_NBBYTE];
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
mLastCommandSend = NONE;
status = M24SR_IO_ReceiveI2Cresponse(sizeof(pDataIn), pDataIn);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onSelectedSystemFile(this,status);
return status;
}//else
@@ -606,9 +652,9 @@
* @retval Status (SW1&SW2) Status of the operation to complete.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
*/
- NFC_StatusTypeDef M24SR::M24SR_SendSelectNDEFfile(uint16_t NDEFfileId) {
+ M24SR::StatusTypeDef M24SR::M24SR_SendSelectNDEFfile(uint16_t NDEFfileId) {
C_APDU command;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
uint8_t *pBuffer = uM24SRbuffer;
uint8_t pDataOut[] = { GETMSB(NDEFfileId), GETLSB(NDEFfileId) };
uint16_t uP1P2 = 0x000C, NbByte;
@@ -629,7 +675,7 @@
/* send the request */
status = M24SR_IO_SendI2Ccommand(NbByte, pBuffer);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
}
@@ -637,7 +683,7 @@
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status==NFC_SUCCESS)
+ if(status==M24SR_SUCCESS)
return M24SR_ReceiveSelectNDEFfile();
else{
mLastCommandSend = NONE;
@@ -646,19 +692,19 @@
}
}
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_ReceiveSelectNDEFfile(){
+M24SR::StatusTypeDef M24SR::M24SR_ReceiveSelectNDEFfile(){
uint8_t pDataIn[M24SR_STATUSRESPONSE_NBBYTE];
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
mLastCommandSend = NONE;
status = M24SR_IO_ReceiveI2Cresponse(sizeof(pDataIn), pDataIn);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onSelectedNDEFFile(this,status);
return status;
}//else
@@ -676,7 +722,7 @@
* @retval Status (SW1&SW2) Status of the operation to complete.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
*/
- NFC_StatusTypeDef M24SR::M24SR_SendReadBinary(uint16_t Offset, uint8_t NbByteToRead,
+ M24SR::StatusTypeDef M24SR::M24SR_SendReadBinary(uint16_t Offset, uint8_t NbByteToRead,
uint8_t *pBufferRead) {
//clamp the buffer to the max size
if(NbByteToRead>M24SR_MAX_BYTE_OPERATION_LENGHT)
@@ -685,7 +731,7 @@
C_APDU command;
uint8_t *pBuffer = uM24SRbuffer;
uint16_t NbByte;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
/* build the command */
command.Header.CLA = C_APDU_CLA_DEFAULT;
@@ -700,7 +746,7 @@
&NbByte, pBuffer);
status = M24SR_IO_SendI2Ccommand(NbByte, pBuffer);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onReadByte(this,status,Offset,pBufferRead,NbByteToRead);
return status;
}
@@ -712,7 +758,7 @@
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status==NFC_SUCCESS){
+ if(status==M24SR_SUCCESS){
return M24SR_ReceiveReadBinary();
}else{
mLastCommandSend = NONE;
@@ -721,12 +767,12 @@
}//if-else
}//if
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_ReceiveReadBinary(){
+M24SR::StatusTypeDef M24SR::M24SR_ReceiveReadBinary(){
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
const uint16_t length = mLastCommandData.length;
const uint16_t offset = mLastCommandData.offset;
uint8_t *data = mLastCommandData.data;
@@ -734,12 +780,12 @@
mLastCommandSend=NONE;
status = M24SR_IO_ReceiveI2Cresponse (length + M24SR_STATUSRESPONSE_NBBYTE , uM24SRbuffer );
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onReadByte(this,status,offset,data,length);
return status;
}
status = M24SR_IsCorrectCRC16Residue(uM24SRbuffer, length + M24SR_STATUSRESPONSE_NBBYTE);
- if(status != NFC_SUCCESS)
+ if(status != M24SR_SUCCESS)
getCallback()->onReadByte(this,status,offset,data,length);
else{
/* retrieve the data without SW1 & SW2 as provided as return value of the function */
@@ -758,7 +804,7 @@
* @retval Status (SW1&SW2) Status of the operation to complete.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
*/
- NFC_StatusTypeDef M24SR::M24SR_SendSTReadBinary(uint16_t Offset,
+ M24SR::StatusTypeDef M24SR::M24SR_SendSTReadBinary(uint16_t Offset,
uint8_t NbByteToRead, uint8_t *pBufferRead) {
//clamp the buffer to the max size
if(NbByteToRead>M24SR_MAX_BYTE_OPERATION_LENGHT)
@@ -767,7 +813,7 @@
C_APDU command;
uint8_t *pBuffer = uM24SRbuffer;
uint16_t NbByte;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
/* build the command */
command.Header.CLA = C_APDU_CLA_ST;
@@ -782,7 +828,7 @@
&NbByte, pBuffer);
status = M24SR_IO_SendI2Ccommand(NbByte, pBuffer);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onReadByte(this,status,Offset,pBufferRead,NbByteToRead);
return status;
}
@@ -793,7 +839,7 @@
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status==NFC_SUCCESS){
+ if(status==M24SR_SUCCESS){
return M24SR_ReceiveReadBinary();
}else{
mLastCommandSend = NONE;
@@ -802,7 +848,7 @@
}//if-else
}//if
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
/**
@@ -813,14 +859,14 @@
* @retval Status (SW1&SW2) Status of the operation to complete.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
*/
- NFC_StatusTypeDef M24SR::M24SR_SendUpdateBinary(uint16_t Offset,
+ M24SR::StatusTypeDef M24SR::M24SR_SendUpdateBinary(uint16_t Offset,
uint8_t NbByteToWrite, uint8_t *pDataToWrite) {
//clamp the buffer to the max size
if(NbByteToWrite>M24SR_MAX_BYTE_OPERATION_LENGHT)
NbByteToWrite=M24SR_MAX_BYTE_OPERATION_LENGHT;
C_APDU command;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
uint8_t *pBuffer = uM24SRbuffer;
uint16_t NbByte;
@@ -839,7 +885,7 @@
&NbByte, pBuffer);
status = M24SR_IO_SendI2Ccommand(NbByte, pBuffer);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onUpdatedBinary(this,status,Offset,pDataToWrite,NbByteToWrite);
return status;
}
@@ -851,7 +897,7 @@
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status==NFC_SUCCESS){
+ if(status==M24SR_SUCCESS){
return M24SR_ReceiveUpdateBinary();
}else{
mLastCommandSend = NONE;
@@ -860,13 +906,13 @@
}//if-else
}
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_ReceiveUpdateBinary() {
+M24SR::StatusTypeDef M24SR::M24SR_ReceiveUpdateBinary() {
uint8_t respBuffer[M24SR_STATUSRESPONSE_NBBYTE];
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
const uint16_t length = mLastCommandData.length;
uint8_t *data = mLastCommandData.data;
const uint16_t offset = mLastCommandData.offset;
@@ -874,20 +920,20 @@
mLastCommandSend=NONE;
status= M24SR_IO_ReceiveI2Cresponse (sizeof(respBuffer) , respBuffer);
- if(status != NFC_SUCCESS){
+ if(status != M24SR_SUCCESS){
getCallback()->onUpdatedBinary(this,status,offset,data,length);
return status;
}
- if (IsSBlock(respBuffer) == NFC_SUCCESS) {
+ if (IsSBlock(respBuffer) == M24SR_SUCCESS) {
/*check the CRC */
status =M24SR_IsCorrectCRC16Residue(respBuffer,
M24SR_WATINGTIMEEXTRESPONSE_NBBYTE);
// TODO: why if we check ==NFC_Commandsuccess it fail?
- if (status != NFC_IO_ERROR_CRC) {
+ if (status != M24SR_IO_ERROR_CRC) {
/* send the FrameExension response*/
status = M24SR_SendFWTExtension(respBuffer[M24SR_OFFSET_PCB + 1]);
- if(status!=NFC_SUCCESS){ //something get wrong -> abort the update
+ if(status!=M24SR_SUCCESS){ //something get wrong -> abort the update
getCallback()->onUpdatedBinary(this,status,offset,data,length);
}//status
}//if
@@ -908,17 +954,17 @@
* @retval Status (SW1&SW2) Status of the operation to complete.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
*/
- NFC_StatusTypeDef M24SR::M24SR_SendVerify(uint16_t uPwdId, uint8_t NbPwdByte,
+ M24SR::StatusTypeDef M24SR::M24SR_SendVerify(uint16_t uPwdId, uint8_t NbPwdByte,
const uint8_t *pPwd) {
C_APDU command;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
uint8_t *pBuffer = uM24SRbuffer;
uint16_t NbByte;
/*check the parameters */
if ((uPwdId > 0x0003)|| ((NbPwdByte != 0x00) && (NbPwdByte != 0x10))) {
- getCallback()->onVerified(this,NFC_IO_ERROR_PARAMETER,constToPasswordType(uPwdId),pPwd);
- return NFC_IO_ERROR_PARAMETER;
+ getCallback()->onVerified(this,M24SR_IO_ERROR_PARAMETER,constToPasswordType(uPwdId),pPwd);
+ return M24SR_IO_ERROR_PARAMETER;
}
/* build the command */
@@ -945,7 +991,7 @@
/* send the request */
status = M24SR_IO_SendI2Ccommand(NbByte, pBuffer);
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onVerified(this,status,constToPasswordType(uPwdId),pPwd);
return status;
}
@@ -956,7 +1002,7 @@
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status == NFC_SUCCESS)
+ if(status == M24SR_SUCCESS)
return M24SR_ReceiveVerify();
else{
mLastCommandSend = NONE;
@@ -965,11 +1011,11 @@
}
}
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_ReceiveVerify(){
- NFC_StatusTypeDef status;
+M24SR::StatusTypeDef M24SR::M24SR_ReceiveVerify(){
+ M24SR::StatusTypeDef status;
uint8_t respBuffer[M24SR_STATUSRESPONSE_NBBYTE];
mLastCommandSend=NONE;
@@ -978,7 +1024,7 @@
status=M24SR_IO_ReceiveI2Cresponse (sizeof(respBuffer),respBuffer);
- if(status !=NFC_SUCCESS){
+ if(status !=M24SR_SUCCESS){
getCallback()->onVerified(this,status,type,data);
return status;
}
@@ -995,18 +1041,18 @@
* @retval Status (SW1&SW2) Satus of the operation to complete.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
*/
- NFC_StatusTypeDef M24SR::M24SR_SendChangeReferenceData(uint16_t uPwdId,
+ M24SR::StatusTypeDef M24SR::M24SR_SendChangeReferenceData(uint16_t uPwdId,
uint8_t *pPwd) {
C_APDU command;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
uint8_t *pBuffer = uM24SRbuffer;
uint16_t NbByte;
/*check the parameters */
if (uPwdId > 0x0003) {
- getCallback()->onChangeReferenceData(this,NFC_IO_ERROR_PARAMETER,
+ getCallback()->onChangeReferenceData(this,M24SR_IO_ERROR_PARAMETER,
constToPasswordType(uPwdId), pPwd);
- return NFC_IO_ERROR_PARAMETER;
+ return M24SR_IO_ERROR_PARAMETER;
}
/* build the command */
@@ -1019,13 +1065,13 @@
command.Body.LC = M24SR_PASSWORD_NBBYTE;
/* copy the password */
command.Body.pData = pPwd;
- /* build the I²C command */
+ /* build the I²C command */
M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_CHANGEREFDATA, &command, uDIDbyte,
&NbByte, pBuffer);
/* send the request */
status = M24SR_IO_SendI2Ccommand(NbByte, pBuffer);
- if(status != NFC_SUCCESS){
+ if(status != M24SR_SUCCESS){
getCallback()->onChangeReferenceData(this,status,
constToPasswordType(uPwdId), pPwd);
return status;
@@ -1038,7 +1084,7 @@
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status == NFC_SUCCESS){
+ if(status == M24SR_SUCCESS){
return M24SR_ReceiveChangeReferenceData();
}else{
mLastCommandSend = NONE;
@@ -1048,11 +1094,11 @@
}//if-else
}//if
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_ReceiveChangeReferenceData(){
- NFC_StatusTypeDef status;
+M24SR::StatusTypeDef M24SR::M24SR_ReceiveChangeReferenceData(){
+ M24SR::StatusTypeDef status;
//TODO the size is 3?
uint8_t rensponseBuffer[M24SR_STATUSRESPONSE_NBBYTE];
@@ -1060,14 +1106,12 @@
uint8_t *data = mLastCommandData.data;
status =M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , rensponseBuffer );
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onChangeReferenceData(this,status,type,data);
return status;
}//else
status = M24SR_IsCorrectCRC16Residue(rensponseBuffer, M24SR_STATUSRESPONSE_NBBYTE);
-
- status = (status == NFC_COMMAND_SUCCESS) ? NFC_SUCCESS : status;
getCallback()->onChangeReferenceData(this,status,type,data);
return status;
}
@@ -1078,18 +1122,18 @@
* @retval Status (SW1&SW2) Status of the operation to complete.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
*/
- NFC_StatusTypeDef M24SR::M24SR_SendEnableVerificationRequirement(
+ M24SR::StatusTypeDef M24SR::M24SR_SendEnableVerificationRequirement(
uint16_t uReadOrWrite) {
C_APDU command;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
uint8_t *pBuffer = uM24SRbuffer;
uint16_t NbByte;
/*check the parameters */
if ((uReadOrWrite != 0x0001) && (uReadOrWrite != 0x0002)) {
- getCallback()->onEnableVerificationRequirement(this,NFC_IO_ERROR_PARAMETER,
+ getCallback()->onEnableVerificationRequirement(this,M24SR_IO_ERROR_PARAMETER,
constToPasswordType(uReadOrWrite));
- return NFC_IO_ERROR_PARAMETER;
+ return M24SR_IO_ERROR_PARAMETER;
}
/* build the command */
@@ -1098,13 +1142,13 @@
/* copy the Password Id */
command.Header.P1 = GETMSB(uReadOrWrite);
command.Header.P2 = GETLSB(uReadOrWrite);
- /* build the I²C command */
+ /* build the I²C command */
M24SR_BuildIBlockCommand( M24SR_CMDSTRUCT_ENABLEVERIFREQ, &command,
uDIDbyte, &NbByte, pBuffer);
/* send the request */
status = M24SR_IO_SendI2Ccommand(NbByte, pBuffer);
- if(status != NFC_SUCCESS){
+ if(status != M24SR_SUCCESS){
getCallback()->onEnableVerificationRequirement(this,status,
constToPasswordType(uReadOrWrite));
return status;
@@ -1116,7 +1160,7 @@
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status == NFC_SUCCESS){
+ if(status == M24SR_SUCCESS){
return M24SR_ReceiveEnableVerificationRequirement();
}else{
mLastCommandSend = NONE;
@@ -1126,25 +1170,23 @@
}//if-else
}//if
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_ReceiveEnableVerificationRequirement(){
- NFC_StatusTypeDef status;
+M24SR::StatusTypeDef M24SR::M24SR_ReceiveEnableVerificationRequirement(){
+ M24SR::StatusTypeDef status;
//TODO the size is 3?
uint8_t rensponseBuffer[M24SR_STATUSRESPONSE_NBBYTE];
const PasswordType_t type = constToPasswordType(mLastCommandData.offset);
status =M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , rensponseBuffer );
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onEnableVerificationRequirement(this,status,type);
return status;
}//else
status = M24SR_IsCorrectCRC16Residue(rensponseBuffer, M24SR_STATUSRESPONSE_NBBYTE);
-
- status = (status == NFC_COMMAND_SUCCESS) ? NFC_SUCCESS : status;
getCallback()->onEnableVerificationRequirement(this,status,type);
return status;
}
@@ -1156,18 +1198,18 @@
* @retval Status (SW1&SW2) Status of the operation to complete.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
*/
- NFC_StatusTypeDef M24SR::M24SR_SendDisableVerificationRequirement(
+ M24SR::StatusTypeDef M24SR::M24SR_SendDisableVerificationRequirement(
uint16_t uReadOrWrite) {
C_APDU command;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
uint8_t *pBuffer = uM24SRbuffer;
uint16_t NbByte;
/*check the parameters */
if ((uReadOrWrite != 0x0001) && (uReadOrWrite != 0x0002)) {
- getCallback()->onDisableVerificationRequirement(this,NFC_IO_ERROR_PARAMETER,
+ getCallback()->onDisableVerificationRequirement(this,M24SR_IO_ERROR_PARAMETER,
constToPasswordType(uReadOrWrite));
- return NFC_IO_ERROR_PARAMETER;
+ return M24SR_IO_ERROR_PARAMETER;
}
/* build the command */
@@ -1176,13 +1218,13 @@
/* copy the Password Id */
command.Header.P1 = GETMSB(uReadOrWrite);
command.Header.P2 = GETLSB(uReadOrWrite);
- /* build the I²C command */
+ /* build the I²C command */
M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_DISABLEVERIFREQ, &command,
uDIDbyte, &NbByte, pBuffer);
/* send the request */
status = M24SR_IO_SendI2Ccommand(NbByte, pBuffer);
- if(status != NFC_SUCCESS){
+ if(status != M24SR_SUCCESS){
getCallback()->onDisableVerificationRequirement(this,status,
constToPasswordType(uReadOrWrite));
return status;
@@ -1194,7 +1236,7 @@
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status==NFC_SUCCESS){
+ if(status==M24SR_SUCCESS){
return M24SR_ReceiveDisableVerificationRequirement();
}else{
mLastCommandSend = NONE;
@@ -1204,26 +1246,24 @@
}//if-else
}
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_ReceiveDisableVerificationRequirement(){
- NFC_StatusTypeDef status;
+M24SR::StatusTypeDef M24SR::M24SR_ReceiveDisableVerificationRequirement(){
+ M24SR::StatusTypeDef status;
//TODO the size is 3?
uint8_t rensponseBuffer[M24SR_STATUSRESPONSE_NBBYTE];
PasswordType_t type = constToPasswordType(mLastCommandData.offset);
status =M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , rensponseBuffer );
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onDisableVerificationRequirement(this,status,type);
return status;
}//else
status = M24SR_IsCorrectCRC16Residue(rensponseBuffer, M24SR_STATUSRESPONSE_NBBYTE);
-
- status = (status == NFC_COMMAND_SUCCESS) ? NFC_SUCCESS : status;
getCallback()->onDisableVerificationRequirement(this,status,type);
return status;
}
@@ -1235,18 +1275,18 @@
* @retval Status (SW1&SW2) Status of the operation to complete.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
*/
- NFC_StatusTypeDef M24SR::M24SR_SendEnablePermanentState(uint16_t uReadOrWrite) {
+ M24SR::StatusTypeDef M24SR::M24SR_SendEnablePermanentState(uint16_t uReadOrWrite) {
C_APDU command;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
uint8_t *pBuffer = uM24SRbuffer;
uint16_t NbByte;
/*check the parameters */
if ((uReadOrWrite != 0x0001) && (uReadOrWrite != 0x0002)) {
- getCallback()->onEnablePermanentState(this,NFC_IO_ERROR_PARAMETER,
+ getCallback()->onEnablePermanentState(this,M24SR_IO_ERROR_PARAMETER,
constToPasswordType(uReadOrWrite));
- return NFC_IO_ERROR_PARAMETER;
+ return M24SR_IO_ERROR_PARAMETER;
}
/* build the command */
@@ -1255,13 +1295,13 @@
/* copy the Password Id */
command.Header.P1 = GETMSB(uReadOrWrite);
command.Header.P2 = GETLSB(uReadOrWrite);
- /* build the I²C command */
+ /* build the I2C command */
M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_ENABLEVERIFREQ, &command, uDIDbyte,
&NbByte, pBuffer);
/* send the request */
status = M24SR_IO_SendI2Ccommand(NbByte, pBuffer);
- if(status != NFC_SUCCESS){
+ if(status != M24SR_SUCCESS){
getCallback()->onEnablePermanentState(this,status,
constToPasswordType(uReadOrWrite));
return status;
@@ -1273,7 +1313,7 @@
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status==NFC_SUCCESS){
+ if(status==M24SR_SUCCESS){
return M24SR_ReceiveEnablePermanentState();
}else{
mLastCommandSend = NONE;
@@ -1283,25 +1323,23 @@
}//if-else
}
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_ReceiveEnablePermanentState(){
- NFC_StatusTypeDef status;
+M24SR::StatusTypeDef M24SR::M24SR_ReceiveEnablePermanentState(){
+ M24SR::StatusTypeDef status;
//TODO the size is 3?
uint8_t rensponseBuffer[M24SR_STATUSRESPONSE_NBBYTE];
PasswordType_t type = constToPasswordType(mLastCommandData.offset);
status =M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , rensponseBuffer );
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onEnablePermanentState(this,status,type);
return status;
}//else
status = M24SR_IsCorrectCRC16Residue(rensponseBuffer, M24SR_STATUSRESPONSE_NBBYTE);
-
- status = (status == NFC_COMMAND_SUCCESS) ? NFC_SUCCESS : status;
getCallback()->onEnablePermanentState(this,status,type);
return status;
}
@@ -1313,17 +1351,17 @@
* @retval Status (SW1&SW2) Status of the operation to complete.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
*/
- NFC_StatusTypeDef M24SR::M24SR_SendDisablePermanentState(uint16_t uReadOrWrite) {
+ M24SR::StatusTypeDef M24SR::M24SR_SendDisablePermanentState(uint16_t uReadOrWrite) {
C_APDU command;
- NFC_StatusTypeDef status;
+ M24SR::StatusTypeDef status;
uint8_t *pBuffer = uM24SRbuffer;
uint16_t NbByte;
/*check the parameters */
if ((uReadOrWrite != 0x0001) && (uReadOrWrite != 0x0002)) {
- getCallback()->onDisablePermanentState(this,NFC_IO_ERROR_PARAMETER,
+ getCallback()->onDisablePermanentState(this,M24SR_IO_ERROR_PARAMETER,
constToPasswordType(uReadOrWrite));
- return NFC_IO_ERROR_PARAMETER;
+ return M24SR_IO_ERROR_PARAMETER;
}
/* build the command */
@@ -1332,25 +1370,25 @@
/* copy the Password Id */
command.Header.P1 = GETMSB(uReadOrWrite);
command.Header.P2 = GETLSB(uReadOrWrite);
- /* build the I²C command */
+ /* build the I²C command */
M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_DISABLEVERIFREQ, &command,
uDIDbyte, &NbByte, pBuffer);
/* send the request */
status = M24SR_IO_SendI2Ccommand(NbByte, pBuffer);
- if(status != NFC_SUCCESS){
+ if(status != M24SR_SUCCESS){
getCallback()->onEnablePermanentState(this,status,
constToPasswordType(uReadOrWrite));
return status;
}
- mLastCommandSend = ENABLE_PERMANET_STATE;
+ mLastCommandSend = DISABLE_PERMANET_STATE;
//use the offset filed for store the pwd id;
mLastCommandData.offset = (uint8_t)uReadOrWrite;
if(mCommunicationType==M24SR::SYNC){
status = M24SR_IO_PollI2C();
- if(status==NFC_SUCCESS){
+ if(status==M24SR_SUCCESS){
return M24SR_ReceiveDisablePermanentState();
}else{
mLastCommandSend = NONE;
@@ -1360,25 +1398,23 @@
}//if-else
}
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_ReceiveDisablePermanentState(){
- NFC_StatusTypeDef status;
+M24SR::StatusTypeDef M24SR::M24SR_ReceiveDisablePermanentState(){
+ M24SR::StatusTypeDef status;
//TODO the size is 3?
uint8_t rensponseBuffer[M24SR_STATUSRESPONSE_NBBYTE];
PasswordType_t type = constToPasswordType(mLastCommandData.offset);
status =M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , rensponseBuffer );
- if(status!=NFC_SUCCESS){
+ if(status!=M24SR_SUCCESS){
getCallback()->onDisablePermanentState(this,status,type);
return status;
}//else
status = M24SR_IsCorrectCRC16Residue(rensponseBuffer, M24SR_STATUSRESPONSE_NBBYTE);
-
- status = (status == NFC_COMMAND_SUCCESS) ? NFC_SUCCESS : status;
getCallback()->onDisablePermanentState(this,status,type);
return status;
}
@@ -1389,15 +1425,14 @@
* @retval Status (SW1&SW2) Status of the operation to complete.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
*/
- NFC_StatusTypeDef M24SR::M24SR_SendInterrupt(void) {
+ M24SR::StatusTypeDef M24SR::M24SR_SendInterrupt(void) {
C_APDU command;
uint8_t *pBuffer = uM24SRbuffer;
uint16_t uP1P2 = 0x001E;
- NFC_StatusTypeDef status = NFC_SUCCESS;
uint16_t NbByte;
- status = M24SR_ManageI2CGPO(INTERRUPT);
+ M24SR_ManageI2CGPO(INTERRUPT);
/* build the command */
command.Header.CLA = C_APDU_CLA_ST;
@@ -1406,7 +1441,7 @@
command.Header.P1 = GETMSB(uP1P2);
command.Header.P2 = GETLSB(uP1P2);
command.Body.LC = 0x00;
- /* build the I²C command */
+ /* build the I²C command */
M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_SENDINTERRUPT, &command, uDIDbyte,
&NbByte, pBuffer);
@@ -1417,12 +1452,7 @@
errchk(
M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
- status = M24SR_IsCorrectCRC16Residue(pBuffer, M24SR_STATUSRESPONSE_NBBYTE);
-
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
+ return M24SR_IsCorrectCRC16Residue(pBuffer, M24SR_STATUSRESPONSE_NBBYTE);
}
@@ -1432,19 +1462,18 @@
* @retval Status (SW1&SW2) Status of the operation to complete.
* @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
*/
- NFC_StatusTypeDef M24SR::M24SR_StateControl(uint8_t uSetOrReset) {
+ M24SR::StatusTypeDef M24SR::M24SR_StateControl(uint8_t uSetOrReset) {
C_APDU command;
uint8_t *pBuffer = uM24SRbuffer;
uint16_t uP1P2 = 0x001F;
- NFC_StatusTypeDef status = NFC_SUCCESS;
uint16_t NbByte;
/*check the parameters */
if ((uSetOrReset != 0x01) && (uSetOrReset != 0x00)) {
- return NFC_IO_ERROR_PARAMETER;
+ return M24SR_IO_ERROR_PARAMETER;
}
- status = M24SR_ManageI2CGPO(STATE_CONTROL);
+ M24SR_ManageI2CGPO(STATE_CONTROL);
/* build the command */
command.Header.CLA = C_APDU_CLA_ST;
@@ -1457,7 +1486,7 @@
/* copy the data */
//memcpy(command.Body.pData , &uSetOrReset, 0x01 );
//command.Body.LE = 0x00 ;
- /* build the I²C command */
+ /* build the I2C command */
M24SR_BuildIBlockCommand( M24SR_CMDSTRUCT_GPOSTATE, &command, uDIDbyte,
&NbByte, pBuffer);
@@ -1468,19 +1497,15 @@
errchk(
M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
- status = M24SR_IsCorrectCRC16Residue(pBuffer, M24SR_STATUSRESPONSE_NBBYTE);
+ return M24SR_IsCorrectCRC16Residue(pBuffer, M24SR_STATUSRESPONSE_NBBYTE);
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
}
-NFC_StatusTypeDef M24SR::M24SR_ManageI2CGPO(NFC_GPO_MGMT GPO_I2Cconfig) {
+M24SR::StatusTypeDef M24SR::M24SR_ManageI2CGPO(NFC_GPO_MGMT GPO_I2Cconfig) {
if (GPO_I2Cconfig > STATE_CONTROL) {
- return NFC_IO_ERROR_PARAMETER;
+ return M24SR_IO_ERROR_PARAMETER;
}
//enable the callback for change the gpo
@@ -1491,10 +1516,10 @@
return M24SR_SendSelectApplication();
}
-NFC_StatusTypeDef M24SR::M24SR_ManageRFGPO(NFC_GPO_MGMT GPO_I2Cconfig) {
+M24SR::StatusTypeDef M24SR::M24SR_ManageRFGPO(NFC_GPO_MGMT GPO_I2Cconfig) {
if (GPO_I2Cconfig > STATE_CONTROL) {
- return NFC_IO_ERROR_PARAMETER;
+ return M24SR_IO_ERROR_PARAMETER;
}
//enable the callback for change the gpo
@@ -1505,34 +1530,34 @@
return M24SR_SendSelectApplication();
}
-NFC_StatusTypeDef M24SR::M24SR_RFConfig(uint8_t OnOffChoice) {
+M24SR::StatusTypeDef M24SR::M24SR_RFConfig(uint8_t OnOffChoice) {
/* Disable RF */
if (OnOffChoice != 0) {
M24SR_IO_RFDIS_WritePin(GPIO_PIN_RESET);
} else {
M24SR_IO_RFDIS_WritePin(GPIO_PIN_SET);
}
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}
-NFC_StatusTypeDef M24SR::M24SR_IO_SendI2Ccommand(uint8_t NbByte,
+M24SR::StatusTypeDef M24SR::M24SR_IO_SendI2Ccommand(uint8_t NbByte,
uint8_t *pBuffer) {
int ret = dev_I2C.write(address, (char*) pBuffer, NbByte);
if (ret == 0)
- return NFC_SUCCESS;
- return NFC_IO_ERROR_I2CTIMEOUT;
+ return M24SR_SUCCESS;
+ return M24SR_IO_ERROR_I2CTIMEOUT;
}
-NFC_StatusTypeDef M24SR::M24SR_IO_ReceiveI2Cresponse(uint8_t NbByte,
+M24SR::StatusTypeDef M24SR::M24SR_IO_ReceiveI2Cresponse(uint8_t NbByte,
uint8_t *pBuffer) {
int ret = dev_I2C.read(address, (char*) pBuffer, NbByte);
if (ret == 0)
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
- return NFC_IO_ERROR_I2CTIMEOUT;
+ return M24SR_IO_ERROR_I2CTIMEOUT;
}
-NFC_StatusTypeDef M24SR::M24SR_IO_PollI2C(void) {
+M24SR::StatusTypeDef M24SR::M24SR_IO_PollI2C(void) {
int status = 1;
char buffer;
@@ -1541,12 +1566,12 @@
}
if (status == 0)
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
//else
- return NFC_IO_ERROR_I2CTIMEOUT;
+ return M24SR_IO_ERROR_I2CTIMEOUT;
}
-NFC_StatusTypeDef M24SR::ManageEvent(void){
+M24SR::StatusTypeDef M24SR::ManageEvent(void){
switch(mLastCommandSend){
case SELECT_APPLICATION:
@@ -1571,11 +1596,18 @@
return M24SR_ReceiveEnableVerificationRequirement();
case DISABLE_VERIFICATION_REQUIREMENT:
return M24SR_ReceiveDisableVerificationRequirement();
+ case ENABLE_PERMANET_STATE:
+ return M24SR_ReceiveEnablePermanentState();
+ case DISABLE_PERMANET_STATE:
+ return M24SR_ReceiveDisablePermanentState();
default:
- return NFC_SUCCESS;
+ return M24SR_SUCCESS;
}//switch
}//manageInterrupt
+NDefLib::NDefNfcTag& M24SR::getNDefTag(){
+ return *mNDefTagUtil;
+}
/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
--- 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);
}

X-NUCLEO-NFC01A1 Dynamic NFC Tag