Unverified Commit 323aeda3 authored by Don Gagne's avatar Don Gagne Committed by GitHub
Browse files

Merge pull request #8322 from mavlink/pr-remove-nxpnfc

Remove reference to NXP NFC Library. Keep only QtNFC.
parents afe86c3e 1d36547d
......@@ -22,7 +22,6 @@ linux {
message("Linux build")
CONFIG += LinuxBuild
DEFINES += __STDC_LIMIT_MACROS
DEFINES += QGC_ENABLE_NFC RW_SUPPORT
DEFINES += QGC_GST_TAISYNC_ENABLED
DEFINES += QGC_GST_MICROHARD_ENABLED
DEFINES += QGC_ENABLE_MAVLINK_INSPECTOR
......
......@@ -147,12 +147,10 @@ contains(DEFINES, QGC_ENABLE_PAIRING) {
} else {
# There is some circular reference settings going on between QGCExternalLibs.pri and gqgroundcontrol.pro.
# So this duplicates some of the enable/disable logic which would normally be in qgroundcontrol.pro.
DEFINES -= QGC_ENABLE_NFC
DEFINES -= QGC_ENABLE_PAIRING
}
} else:WindowsBuild {
#- Pairing is not supported on Windows
DEFINES -= QGC_ENABLE_NFC
DEFINES -= QGC_ENABLE_PAIRING
} else {
LIBS += -lcrypto -lz
......
......@@ -187,18 +187,6 @@ contains (DEFINES, QGC_DISABLE_BLUETOOTH) {
DEFINES += QGC_ENABLE_BLUETOOTH
}
# NFC
contains (DEFINES, QGC_DISABLE_NFC) {
message("Skipping support for NFC (manual override from command line)")
DEFINES -= QGC_ENABLE_NFC
} else:exists(user_config.pri):infile(user_config.pri, DEFINES, QGC_DISABLE_NFC) {
message("Skipping support for NFC (manual override from user_config.pri)")
DEFINES -= QGC_ENABLE_NFC
} else:exists(user_config.pri):infile(user_config.pri, DEFINES, QGC_ENABLE_NFC) {
message("Including support for NFC (manual override from user_config.pri)")
DEFINES += QGC_ENABLE_NFC
}
# QTNFC
contains (DEFINES, QGC_DISABLE_QTNFC) {
message("Skipping support for QTNFC (manual override from command line)")
......@@ -318,14 +306,11 @@ DEFINES+=QGC_DISABLE_PAIRING
# Pairing
contains (DEFINES, QGC_DISABLE_PAIRING) {
message("Skipping support for Pairing")
DEFINES -= QGC_ENABLE_NFC
} else:exists(user_config.pri):infile(user_config.pri, DEFINES, QGC_DISABLE_PAIRING) {
message("Skipping support for Pairing (manual override from user_config.pri)")
DEFINES -= QGC_ENABLE_NFC
} else:AndroidBuild:contains(QT_ARCH, arm64) {
# Haven't figured out how to get 64 bit arm OpenSLL yet which pairing requires
message("Skipping support for Pairing (Missing Android OpenSSL 64 bit support)")
DEFINES -= QGC_ENABLE_NFC
} else {
message("Enabling support for Pairing")
DEFINES += QGC_ENABLE_PAIRING
......@@ -737,37 +722,6 @@ contains (DEFINES, QGC_ENABLE_PAIRING) {
}
}
contains (DEFINES, QGC_ENABLE_PAIRING) {
contains(DEFINES, QGC_ENABLE_NFC) {
HEADERS += \
src/PairingManager/PairingNFC.h \
src/PairingManager/NfcLibrary/inc/Nfc.h \
src/PairingManager/NfcLibrary/inc/Nfc_settings.h \
src/PairingManager/NfcLibrary/NdefLibrary/inc/P2P_NDEF.h \
src/PairingManager/NfcLibrary/NdefLibrary/inc/RW_NDEF.h \
src/PairingManager/NfcLibrary/NdefLibrary/inc/RW_NDEF_T1T.h \
src/PairingManager/NfcLibrary/NdefLibrary/inc/RW_NDEF_T2T.h \
src/PairingManager/NfcLibrary/NdefLibrary/inc/RW_NDEF_T3T.h \
src/PairingManager/NfcLibrary/NdefLibrary/inc/RW_NDEF_T4T.h \
src/PairingManager/NfcLibrary/NdefLibrary/inc/T4T_NDEF_emu.h \
src/PairingManager/NfcLibrary/NxpNci/inc/NxpNci.h \
src/PairingManager/NfcTask/inc/ndef_helper.h \
src/PairingManager/TML/inc/framework_Allocator.h \
src/PairingManager/TML/inc/framework_Interface.h \
src/PairingManager/TML/inc/framework_Map.h \
src/PairingManager/TML/inc/framework_Timer.h \
src/PairingManager/TML/inc/lpcusbsio.h \
src/PairingManager/TML/inc/tml.h \
src/PairingManager/TML/inc/tool.h \
src/PairingManager/TML/inc/framework_Container.h \
src/PairingManager/TML/inc/framework_linux.h \
src/PairingManager/TML/inc/framework_Parcel.h \
src/PairingManager/TML/inc/hidapi.h \
src/PairingManager/TML/inc/lpcusbsio_i2c.h \
src/PairingManager/TML/inc/tml_hid.h
}
}
!NoSerialBuild {
HEADERS += \
src/comm/QGCSerialPortInfo.h \
......@@ -966,36 +920,6 @@ contains (DEFINES, QGC_ENABLE_PAIRING) {
}
}
contains (DEFINES, QGC_ENABLE_PAIRING) {
contains(DEFINES, QGC_ENABLE_NFC) {
SOURCES += \
src/PairingManager/PairingNFC.cc \
src/PairingManager/NfcLibrary/NxpNci/src/NxpNci.c \
src/PairingManager/NfcLibrary/NdefLibrary/src/RW_NDEF_T4T.c \
src/PairingManager/NfcLibrary/NdefLibrary/src/P2P_NDEF.c \
src/PairingManager/NfcLibrary/NdefLibrary/src/RW_NDEF_T3T.c \
src/PairingManager/NfcLibrary/NdefLibrary/src/RW_NDEF.c \
src/PairingManager/NfcLibrary/NdefLibrary/src/RW_NDEF_T1T.c \
src/PairingManager/NfcLibrary/NdefLibrary/src/RW_NDEF_T2T.c \
src/PairingManager/NfcLibrary/NdefLibrary/src/T4T_NDEF_emu.c \
src/PairingManager/TML/src/framework_Map.c \
src/PairingManager/TML/src/framework_log.c \
src/PairingManager/TML/src/framework_Parcel.c \
src/PairingManager/TML/src/framework_sem.c \
src/PairingManager/TML/src/framework_mutex.c \
src/PairingManager/TML/src/hid.c \
src/PairingManager/TML/src/framework_Allocator.c \
src/PairingManager/TML/src/tml_hid.c \
src/PairingManager/TML/src/framework_Container.c \
src/PairingManager/TML/src/framework_thread.c \
src/PairingManager/TML/src/framework_Timer.c \
src/PairingManager/TML/src/lpcusbsio.c \
src/PairingManager/TML/src/tml.c \
src/PairingManager/NfcTask/src/ndef_helper.c
LIBS += -lrt -ludev
}
}
!MobileBuild {
SOURCES += \
src/GPS/Drivers/src/gps_helper.cpp \
......
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
#define P2P_NDEF_MAX_NDEF_MESSAGE_SIZE 240
void P2P_NDEF_Reset(void);
void P2P_NDEF_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size);
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
#define RW_MAX_NDEF_FILE_SIZE 500
extern unsigned char NdefBuffer[RW_MAX_NDEF_FILE_SIZE];
typedef void RW_NDEF_Callback_t (unsigned char*, unsigned short);
#define RW_NDEF_TYPE_T1T 0x1
#define RW_NDEF_TYPE_T2T 0x2
#define RW_NDEF_TYPE_T3T 0x3
#define RW_NDEF_TYPE_T4T 0x4
extern unsigned char *pRW_NdefMessage;
extern unsigned short RW_NdefMessage_size;
extern RW_NDEF_Callback_t *pRW_NDEF_PullCb;
extern RW_NDEF_Callback_t *pRW_NDEF_PushCb;
void RW_NDEF_Reset(unsigned char type);
void RW_NDEF_Read_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size);
void RW_NDEF_Write_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size);
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
void RW_NDEF_T1T_Reset(void);
void RW_NDEF_T1T_Read_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size);
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
void RW_NDEF_T2T_Reset(void);
void RW_NDEF_T2T_Read_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size);
void RW_NDEF_T2T_Write_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size);
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
void RW_NDEF_T3T_Reset(void);
void RW_NDEF_T3T_SetIDm(unsigned char *pIDm);
void RW_NDEF_T3T_Read_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size);
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
void RW_NDEF_T4T_Reset(void);
void RW_NDEF_T4T_Read_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size);
void RW_NDEF_T4T_Write_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size);
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
void T4T_NDEF_EMU_Reset(void);
void T4T_NDEF_EMU_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size);
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
#ifdef P2P_SUPPORT
#include <TML/inc/tool.h>
#include <NfcLibrary/NdefLibrary/inc/P2P_NDEF.h>
/* Well-known LLCP SAP Values */
#define SAP_SDP 1
#define SAP_SNEP 4
/* SNEP codes */
#define SNEP_VER10 0x10
#define SNEP_PUT 0x2
#define SNEP_SUCCESS 0x81
/* LLCP PDU Types */
#define SYMM 0x0
#define PAX 0x1
#define AGF 0x2
#define UI 0x3
#define CONNECT 0x4
#define DISC 0x5
#define CC 0x6
#define DM 0x7
#define FRMR 0x8
#define SNL 0x9
#define reservedA 0xA
#define reservedB 0xB
#define I 0xC
#define RR 0xD
#define RNR 0xE
#define reservedF 0xF
/* LLCP parameters */
#define VERSION 1
#define MIUX 2
#define WKS 3
#define LTO 4
#define RW 5
#define SN 6
const unsigned char SNEP_PUT_SUCCESS[] = {SNEP_VER10, SNEP_SUCCESS, 0x00, 0x00, 0x00, 0x00};
const unsigned char LLCP_CONNECT_SNEP[] = {0x11, 0x20};
const unsigned char LLCP_I_SNEP_PUT_HEADER[] = {SNEP_VER10, SNEP_PUT, 0x00, 0x00, 0x00, 0x00};
const unsigned char LLCP_SYMM[] = {0x00, 0x00};
unsigned char *pNdefMessage;
unsigned short NdefMessage_size = 0;
/* Defines the number of symmetry exchanges is expected before initiating the NDEF push (to allow a remote phone to beam an NDEF message first) */
#define NDEF_PUSH_DELAY_COUNT 2
/* Defines at which frequency the symmetry is exchange (in ms) */
#define SYMM_FREQ 500
typedef enum
{
Idle,
Initial,
DelayingPush,
SnepClientConnecting,
SnepClientConnected,
NdefMsgSent
} P2P_SnepClient_state_t;
typedef struct
{
unsigned char Dsap;
unsigned char Pdu;
unsigned char Ssap;
unsigned char Version;
unsigned short Miux;
unsigned short Wks;
unsigned char Lto;
unsigned char Rw;
unsigned char Sn[30];
} P2P_NDEF_LlcpHeader_t;
typedef void P2P_NDEF_Callback_t (unsigned char*, unsigned short);
static P2P_SnepClient_state_t eP2P_SnepClient_State = Initial;
static P2P_NDEF_Callback_t *pP2P_NDEF_PushCb = NULL;
static P2P_NDEF_Callback_t *pP2P_NDEF_PullCb = NULL;
static unsigned short P2P_SnepClient_DelayCount = NDEF_PUSH_DELAY_COUNT;
static void ParseLlcp(unsigned char *pBuf, unsigned short BufSize, P2P_NDEF_LlcpHeader_t *pLlcpHeader)
{
uint8_t i = 2;
pLlcpHeader->Dsap = pBuf[0] >> 2;
pLlcpHeader->Pdu = ((pBuf[0] & 3) << 2) + (pBuf[1] >> 6);
pLlcpHeader->Ssap = pBuf[1] & 0x3F;
while(i<BufSize)
{
switch (pBuf[i]){
case VERSION:
pLlcpHeader->Version = pBuf[i+2];
break;
case MIUX:
pLlcpHeader->Miux = (pBuf[i+2] << 8) + pBuf[i+3];
break;
case WKS:
pLlcpHeader->Wks = (pBuf[i+2] << 8) + pBuf[i+3];
break;
case LTO:
pLlcpHeader->Lto = pBuf[i+2];
break;
case RW:
pLlcpHeader->Rw = pBuf[i+2];
break;
case SN:
memcpy(pLlcpHeader->Sn, &pBuf[i+2], pBuf[i+1] < sizeof(pLlcpHeader->Sn) ? pBuf[i+1] : sizeof(pLlcpHeader->Sn));
break;
default:
break;
}
i += pBuf[i+1]+2;
}
}
static void FillLlcp(P2P_NDEF_LlcpHeader_t LlcpHeader, unsigned char *pBuf)
{
pBuf[0] = (LlcpHeader.Ssap << 2) + ((LlcpHeader.Pdu >> 2) & 3);
pBuf[1] = (LlcpHeader.Pdu << 6) + LlcpHeader.Dsap;
}
bool P2P_NDEF_SetMessage(unsigned char *pMessage, unsigned short Message_size, void *pCb)
{
if (Message_size <= P2P_NDEF_MAX_NDEF_MESSAGE_SIZE)
{
pNdefMessage = pMessage;
NdefMessage_size = Message_size;
pP2P_NDEF_PushCb = (P2P_NDEF_Callback_t*) pCb;
return true;
}
else
{
NdefMessage_size = 0;
pP2P_NDEF_PushCb = NULL;
return false;
}
}
void P2P_NDEF_RegisterPullCallback(void *pCb)
{
pP2P_NDEF_PullCb = (P2P_NDEF_Callback_t*) pCb;
}
void P2P_NDEF_Reset(void)
{
if (NdefMessage_size != 0)
{
eP2P_SnepClient_State = Initial;
}
else
{
eP2P_SnepClient_State = Idle;
}
}
void P2P_NDEF_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *pRsp, unsigned short *pRsp_size)
{
P2P_NDEF_LlcpHeader_t LlcpHeader;
/* Initialize answer */
*pRsp_size = 0;
ParseLlcp(pCmd, Cmd_size, &LlcpHeader);
switch (LlcpHeader.Pdu)
{
case CONNECT:
/* Is connection from SNEP Client ? */
if ((LlcpHeader.Dsap == SAP_SNEP) || (memcmp(LlcpHeader.Sn, "urn:nfc:sn:snep", 15) == 0))
{
/* Only accept the connection is application is registered for NDEF reception */
if(pP2P_NDEF_PullCb != NULL)
{
LlcpHeader.Pdu = CC;
FillLlcp(LlcpHeader, pRsp);
*pRsp_size = 2;
}
}
else
{
/* Refuse any other connection request */
LlcpHeader.Pdu = DM;
FillLlcp(LlcpHeader, pRsp);
*pRsp_size = 2;
}
break;
case I:
/* Is SNEP PUT ? */
if ((pCmd[3] == SNEP_VER10) && (pCmd[4] == SNEP_PUT))
{
/* Notify application of the NDEF reception */
if(pP2P_NDEF_PullCb != NULL) pP2P_NDEF_PullCb(&pCmd[9], pCmd[8]);
/* Acknowledge the PUT request */
LlcpHeader.Pdu = I;
FillLlcp(LlcpHeader, pRsp);
pRsp[2] = (pCmd[2] >> 4) + 1; // N(R)
memcpy(&pRsp[3], SNEP_PUT_SUCCESS, sizeof(SNEP_PUT_SUCCESS));
*pRsp_size = 9;
}
break;
case CC:
/* Connection to remote SNEP server completed, send NDEF message inside SNEP PUT request */
eP2P_SnepClient_State = SnepClientConnected;
break;
default:
break;
}
/* No answer was set */
if (*pRsp_size == 0)
{
switch(eP2P_SnepClient_State)
{
case Initial:
if((pP2P_NDEF_PullCb == NULL) || (NDEF_PUSH_DELAY_COUNT == 0))
{
memcpy(pRsp, LLCP_CONNECT_SNEP, sizeof(LLCP_CONNECT_SNEP));
*pRsp_size = sizeof(LLCP_CONNECT_SNEP);
eP2P_SnepClient_State = SnepClientConnecting;
}
else
{
P2P_SnepClient_DelayCount = 1;
eP2P_SnepClient_State = DelayingPush;
/* Wait then send a SYMM */
Sleep (SYMM_FREQ);
memcpy(pRsp, LLCP_SYMM, sizeof(LLCP_SYMM));
*pRsp_size = sizeof(LLCP_SYMM);
}
break;
case DelayingPush:
if(P2P_SnepClient_DelayCount == NDEF_PUSH_DELAY_COUNT)
{
memcpy(pRsp, LLCP_CONNECT_SNEP, sizeof(LLCP_CONNECT_SNEP));
*pRsp_size = sizeof(LLCP_CONNECT_SNEP);
eP2P_SnepClient_State = SnepClientConnecting;
}
else
{
P2P_SnepClient_DelayCount++;
/* Wait then send a SYMM */
Sleep (1000);
memcpy(pRsp, LLCP_SYMM, sizeof(LLCP_SYMM));
*pRsp_size = sizeof(LLCP_SYMM);
}
break;
case SnepClientConnected:
LlcpHeader.Pdu = I;
FillLlcp(LlcpHeader, pRsp);
pRsp[2] = 0; // N(R)
pRsp[3] = SNEP_VER10;
pRsp[4] = SNEP_PUT;
pRsp[5] = 0;
pRsp[6] = 0;
pRsp[7] = 0;
pRsp[8] = (unsigned char) NdefMessage_size;
memcpy(&pRsp[9], pNdefMessage, NdefMessage_size);
*pRsp_size = 9 + NdefMessage_size;
eP2P_SnepClient_State = NdefMsgSent;
/* Notify application of the NDEF push */
if(pP2P_NDEF_PushCb != NULL) pP2P_NDEF_PushCb(pNdefMessage, NdefMessage_size);
break;
default:
/* Wait then send a SYMM */
Sleep (SYMM_FREQ);
memcpy(pRsp, LLCP_SYMM, sizeof(LLCP_SYMM));
*pRsp_size = sizeof(LLCP_SYMM);
break;
}
}
}
#endif
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
#ifdef RW_SUPPORT
#ifndef NO_NDEF_SUPPORT
#include <TML/inc/tool.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF_T1T.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF_T2T.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF_T3T.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF_T4T.h>
/* Allocate buffer for NDEF operations */
unsigned char NdefBuffer[RW_MAX_NDEF_FILE_SIZE];
typedef void RW_NDEF_Fct_t (unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size);
unsigned char *pRW_NdefMessage;
unsigned short RW_NdefMessage_size;
RW_NDEF_Callback_t *pRW_NDEF_PullCb;
RW_NDEF_Callback_t *pRW_NDEF_PushCb;
static RW_NDEF_Fct_t *pReadFct = NULL;
static RW_NDEF_Fct_t *pWriteFct = NULL;
bool RW_NDEF_SetMessage(unsigned char *pMessage, unsigned short Message_size, void *pCb)
{
if (Message_size <= RW_MAX_NDEF_FILE_SIZE)
{
pRW_NdefMessage = pMessage;
RW_NdefMessage_size = Message_size;
pRW_NDEF_PushCb = (RW_NDEF_Callback_t*) pCb;
return true;
}
else
{
RW_NdefMessage_size = 0;
pRW_NDEF_PushCb = NULL;
return false;
}
}
void RW_NDEF_RegisterPullCallback(void *pCb)
{
pRW_NDEF_PullCb = (RW_NDEF_Callback_t *) pCb;
}
void RW_NDEF_Reset(unsigned char type)
{
pReadFct = NULL;
pWriteFct = NULL;
switch (type)
{
case RW_NDEF_TYPE_T1T:
RW_NDEF_T1T_Reset();
pReadFct = RW_NDEF_T1T_Read_Next;
break;
case RW_NDEF_TYPE_T2T:
RW_NDEF_T2T_Reset();
pReadFct = RW_NDEF_T2T_Read_Next;
pWriteFct = RW_NDEF_T2T_Write_Next;
break;
case RW_NDEF_TYPE_T3T:
RW_NDEF_T3T_Reset();
pReadFct = RW_NDEF_T3T_Read_Next;
break;
case RW_NDEF_TYPE_T4T:
RW_NDEF_T4T_Reset();
pReadFct = RW_NDEF_T4T_Read_Next;
pWriteFct = RW_NDEF_T4T_Write_Next;
break;
default:
break;
}
}
void RW_NDEF_Read_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size)
{
if (pReadFct != NULL) pReadFct(pCmd, Cmd_size, Rsp, pRsp_size);
}
void RW_NDEF_Write_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *Rsp, unsigned short *pRsp_size)
{
if (pWriteFct != NULL) pWriteFct(pCmd, Cmd_size, Rsp, pRsp_size);
}
#endif
#endif
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
#ifdef RW_SUPPORT
#ifndef NO_NDEF_SUPPORT
#include <TML/inc/tool.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF.h>
#define T1T_MAGIC_NUMBER 0xE1
#define T1T_NDEF_TLV 0x03
const unsigned char T1T_RID[] = {0x78,0x00,0x00,0x00,0x00,0x00,0x00};
const unsigned char T1T_RALL[] = {0x00,0x00,0x00};
const unsigned char T1T_READ8[] = {0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
typedef enum
{
Initial,
Getting_ID,
Reading_CardContent,
Reading_NDEF
} RW_NDEF_T1T_state_t;
typedef struct
{
unsigned char HR0;
unsigned char HR1;
unsigned char UID[4];
unsigned char BlkNb;
unsigned short MessagePtr;
unsigned short MessageSize;
unsigned char *pMessage;
} RW_NDEF_T1T_Ndef_t;
static RW_NDEF_T1T_state_t eRW_NDEF_T1T_State = Initial;
static RW_NDEF_T1T_Ndef_t RW_NDEF_T1T_Ndef;
void RW_NDEF_T1T_Reset(void)
{
eRW_NDEF_T1T_State = Initial;
RW_NDEF_T1T_Ndef.pMessage = NdefBuffer;
}
void RW_NDEF_T1T_Read_Next(unsigned char *pRsp, unsigned short Rsp_size, unsigned char *pCmd, unsigned short *pCmd_size)
{
/* By default no further command to be sent */
*pCmd_size = 0;
switch(eRW_NDEF_T1T_State)
{
case Initial:
/* Send T1T_RID */
memcpy (pCmd, T1T_RID, sizeof(T1T_RID));
*pCmd_size = 7;
eRW_NDEF_T1T_State = Getting_ID;
break;
case Getting_ID:
/* Is CC Read and Is Ndef ?*/
if ((Rsp_size == 7) && (pRsp[Rsp_size-1] == 0x00))
{
/* Fill File structure */
RW_NDEF_T1T_Ndef.HR0 = pRsp[0];
RW_NDEF_T1T_Ndef.HR1 = pRsp[1];
memcpy (RW_NDEF_T1T_Ndef.UID, &pRsp[2], sizeof(RW_NDEF_T1T_Ndef.UID));
/* Read full card content */
memcpy (pCmd, T1T_RALL, sizeof(T1T_RALL));
memcpy (&pCmd[3], RW_NDEF_T1T_Ndef.UID, sizeof(RW_NDEF_T1T_Ndef.UID));
*pCmd_size = sizeof(T1T_RALL) + sizeof(RW_NDEF_T1T_Ndef.UID);
eRW_NDEF_T1T_State = Reading_CardContent;
}
break;
case Reading_CardContent:
/* Is Read success ?*/
if ((Rsp_size == 123) && (pRsp[Rsp_size-1] == 0x00))
{
/* Check CC */
if (pRsp[10] == T1T_MAGIC_NUMBER)
{
unsigned char Tmp = 14;
unsigned char data_size;
/* If not NDEF Type skip TLV */
while (pRsp[Tmp] != T1T_NDEF_TLV)
{
Tmp += 2 + pRsp[Tmp+1];
if (Tmp > Rsp_size) return;
}
RW_NDEF_T1T_Ndef.MessageSize = pRsp[Tmp+1];
data_size = (Rsp_size - 1) - 16 - Tmp - 2;
/* If provisioned buffer is not large enough, notify the application and stop reading */
if (RW_NDEF_T1T_Ndef.MessageSize > RW_MAX_NDEF_FILE_SIZE)
{
if(pRW_NDEF_PullCb != NULL) pRW_NDEF_PullCb(NULL, 0);
break;
}
/* Is NDEF read already completed ? */
if(RW_NDEF_T1T_Ndef.MessageSize <= data_size)
{
memcpy(RW_NDEF_T1T_Ndef.pMessage, &pRsp[Tmp+2], RW_NDEF_T1T_Ndef.MessageSize);
/* Notify application of the NDEF reception */
if(pRW_NDEF_PullCb != NULL) pRW_NDEF_PullCb(RW_NDEF_T1T_Ndef.pMessage, RW_NDEF_T1T_Ndef.MessageSize);
}
else
{
RW_NDEF_T1T_Ndef.MessagePtr = data_size;
memcpy (RW_NDEF_T1T_Ndef.pMessage, &pRsp[Tmp+2], RW_NDEF_T1T_Ndef.MessagePtr);
RW_NDEF_T1T_Ndef.BlkNb = 0x10;
/* Read NDEF content */
memcpy (pCmd, T1T_READ8, sizeof(T1T_READ8));
pCmd[1] = RW_NDEF_T1T_Ndef.BlkNb;
memcpy (&pCmd[10], RW_NDEF_T1T_Ndef.UID, sizeof(RW_NDEF_T1T_Ndef.UID));
*pCmd_size = sizeof(T1T_READ8) + sizeof(RW_NDEF_T1T_Ndef.UID);
eRW_NDEF_T1T_State = Reading_NDEF;
}
}
}
break;
case Reading_NDEF:
/* Is Read success ?*/
if ((Rsp_size == 10) && (pRsp[Rsp_size-1] == 0x00))
{
/* Is NDEF read already completed ? */
if ((RW_NDEF_T1T_Ndef.MessageSize - RW_NDEF_T1T_Ndef.MessagePtr) < 8)
{
memcpy (&RW_NDEF_T1T_Ndef.pMessage[RW_NDEF_T1T_Ndef.MessagePtr], &pRsp[1], RW_NDEF_T1T_Ndef.MessageSize - RW_NDEF_T1T_Ndef.MessagePtr);
/* Notify application of the NDEF reception */
if(pRW_NDEF_PullCb != NULL) pRW_NDEF_PullCb(RW_NDEF_T1T_Ndef.pMessage, RW_NDEF_T1T_Ndef.MessageSize);
}
else
{
memcpy (&RW_NDEF_T1T_Ndef.pMessage[RW_NDEF_T1T_Ndef.MessagePtr], &pRsp[1], 8);
RW_NDEF_T1T_Ndef.MessagePtr += 8;
RW_NDEF_T1T_Ndef.BlkNb++;
/* Read NDEF content */
memcpy (pCmd, T1T_READ8, sizeof(T1T_READ8));
pCmd[1] = RW_NDEF_T1T_Ndef.BlkNb;
memcpy (&pCmd[10], RW_NDEF_T1T_Ndef.UID, sizeof(RW_NDEF_T1T_Ndef.UID));
*pCmd_size = sizeof(T1T_READ8) + sizeof(RW_NDEF_T1T_Ndef.UID);
}
}
break;
default:
break;
}
}
#endif
#endif
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
#ifdef RW_SUPPORT
#ifndef NO_NDEF_SUPPORT
#include <TML/inc/tool.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF.h>
/* TODO: No support for tag larger than 1024 bytes (requiring SECTOR_SELECT command use) */
#define T2T_MAGIC_NUMBER 0xE1
#define T2T_NDEF_TLV 0x03
typedef enum
{
Initial,
Reading_CC,
Reading_Data,
Reading_NDEF,
Writing_Data
} RW_NDEF_T2T_state_t;
typedef struct
{
unsigned char BlkNb;
unsigned short MessagePtr;
unsigned short MessageSize;
unsigned char *pMessage;
} RW_NDEF_T2T_Ndef_t;
static RW_NDEF_T2T_state_t eRW_NDEF_T2T_State = Initial;
static RW_NDEF_T2T_Ndef_t RW_NDEF_T2T_Ndef;
void RW_NDEF_T2T_Reset(void)
{
eRW_NDEF_T2T_State = Initial;
RW_NDEF_T2T_Ndef.pMessage = NdefBuffer;
}
void RW_NDEF_T2T_Read_Next(unsigned char *pRsp, unsigned short Rsp_size, unsigned char *pCmd, unsigned short *pCmd_size)
{
/* By default no further command to be sent */
*pCmd_size = 0;
switch(eRW_NDEF_T2T_State)
{
case Initial:
/* Read CC */
pCmd[0] = 0x30;
pCmd[1] = 0x03;
*pCmd_size = 2;
eRW_NDEF_T2T_State = Reading_CC;
break;
case Reading_CC:
/* Is CC Read and Is Ndef ?*/
if ((Rsp_size == 17) && (pRsp[Rsp_size-1] == 0x00) && (pRsp[0] == T2T_MAGIC_NUMBER))
{
/* Read First data */
pCmd[0] = 0x30;
pCmd[1] = 0x04;
*pCmd_size = 2;
eRW_NDEF_T2T_State = Reading_Data;
}
break;
case Reading_Data:
/* Is Read success ?*/
if ((Rsp_size == 17) && (pRsp[Rsp_size-1] == 0x00))
{
unsigned char Tmp = 0;
/* If not NDEF Type skip TLV */
while (pRsp[Tmp] != T2T_NDEF_TLV)
{
Tmp += 2 + pRsp[Tmp+1];
if (Tmp > Rsp_size) return;
}
if(pRsp[Tmp+1] == 0xFF)
{
RW_NDEF_T2T_Ndef.MessageSize = (pRsp[Tmp+2] << 8) + pRsp[Tmp+3];
Tmp += 2;
}
else RW_NDEF_T2T_Ndef.MessageSize = pRsp[Tmp+1];
/* If provisioned buffer is not large enough, notify the application and stop reading */
if (RW_NDEF_T2T_Ndef.MessageSize > RW_MAX_NDEF_FILE_SIZE)
{
if(pRW_NDEF_PullCb != NULL) pRW_NDEF_PullCb(NULL, 0);
break;
}
/* Is NDEF read already completed ? */
if (RW_NDEF_T2T_Ndef.MessageSize <= ((Rsp_size-1) - Tmp - 2))
{
memcpy (RW_NDEF_T2T_Ndef.pMessage, &pRsp[Tmp+2], RW_NDEF_T2T_Ndef.MessageSize);
/* Notify application of the NDEF reception */
if(pRW_NDEF_PullCb != NULL) pRW_NDEF_PullCb(RW_NDEF_T2T_Ndef.pMessage, RW_NDEF_T2T_Ndef.MessageSize);
}
else
{
RW_NDEF_T2T_Ndef.MessagePtr = (Rsp_size-1) - Tmp - 2;
memcpy (RW_NDEF_T2T_Ndef.pMessage, &pRsp[Tmp+2], RW_NDEF_T2T_Ndef.MessagePtr);
RW_NDEF_T2T_Ndef.BlkNb = 8;
/* Read NDEF content */
pCmd[0] = 0x30;
pCmd[1] = RW_NDEF_T2T_Ndef.BlkNb;
*pCmd_size = 2;
eRW_NDEF_T2T_State = Reading_NDEF;
}
}
break;
case Reading_NDEF:
/* Is Read success ?*/
if ((Rsp_size == 17) && (pRsp[Rsp_size-1] == 0x00))
{
/* Is NDEF read already completed ? */
if ((RW_NDEF_T2T_Ndef.MessageSize - RW_NDEF_T2T_Ndef.MessagePtr) < 16)
{
memcpy (&RW_NDEF_T2T_Ndef.pMessage[RW_NDEF_T2T_Ndef.MessagePtr], pRsp, RW_NDEF_T2T_Ndef.MessageSize - RW_NDEF_T2T_Ndef.MessagePtr);
/* Notify application of the NDEF reception */
if(pRW_NDEF_PullCb != NULL) pRW_NDEF_PullCb(RW_NDEF_T2T_Ndef.pMessage, RW_NDEF_T2T_Ndef.MessageSize);
}
else
{
memcpy (&RW_NDEF_T2T_Ndef.pMessage[RW_NDEF_T2T_Ndef.MessagePtr], pRsp, 16);
RW_NDEF_T2T_Ndef.MessagePtr += 16;
RW_NDEF_T2T_Ndef.BlkNb += 4;
/* Read NDEF content */
pCmd[0] = 0x30;
pCmd[1] = RW_NDEF_T2T_Ndef.BlkNb;
*pCmd_size = 2;
}
}
break;
default:
break;
}
}
void RW_NDEF_T2T_Write_Next(unsigned char *pRsp, unsigned short Rsp_size, unsigned char *pCmd, unsigned short *pCmd_size)
{
/* By default no further command to be sent */
*pCmd_size = 0;
switch(eRW_NDEF_T2T_State)
{
case Initial:
/* Read CC */
pCmd[0] = 0x30;
pCmd[1] = 0x03;
*pCmd_size = 2;
eRW_NDEF_T2T_State = Reading_CC;
break;
case Reading_CC:
/* Is CC Read, Is Ndef and is R/W ?*/
if ((Rsp_size == 17) && (pRsp[Rsp_size-1] == 0x00) && (pRsp[0] == T2T_MAGIC_NUMBER) && (pRsp[3] == 0x00))
{
/* Is size enough ? */
if (pRsp[2]*8 >= RW_NdefMessage_size)
{
/* Write First data */
pCmd[0] = 0xA2;
pCmd[1] = 0x04;
pCmd[2] = 0x03;
if (RW_NdefMessage_size > 0xFF)
{
pCmd[3] = 0xFF;
pCmd[4] = (RW_NdefMessage_size & 0xFF00) >> 8;
pCmd[5] = RW_NdefMessage_size & 0xFF;
RW_NDEF_T2T_Ndef.MessagePtr = 0;
}
else
{
pCmd[3] = (unsigned char) RW_NdefMessage_size;
memcpy(&pCmd[4], pRW_NdefMessage, 2);
RW_NDEF_T2T_Ndef.MessagePtr = 2;
}
RW_NDEF_T2T_Ndef.BlkNb = 5;
*pCmd_size = 6;
eRW_NDEF_T2T_State = Writing_Data;
}
}
break;
case Writing_Data:
/* Is Write success ?*/
if ((Rsp_size == 2) && (pRsp[Rsp_size-1] == 0x00))
{
/* Is NDEF write already completed ? */
if (RW_NdefMessage_size <= RW_NDEF_T2T_Ndef.MessagePtr)
{
/* Notify application of the NDEF reception */
if(pRW_NDEF_PushCb != NULL) pRW_NDEF_PushCb(pRW_NdefMessage, RW_NdefMessage_size);
}
else
{
/* Write NDEF content */
pCmd[0] = 0xA2;
pCmd[1] = RW_NDEF_T2T_Ndef.BlkNb;
memcpy(&pCmd[2], pRW_NdefMessage+RW_NDEF_T2T_Ndef.MessagePtr, 4);
*pCmd_size = 6;
RW_NDEF_T2T_Ndef.MessagePtr+=4;
RW_NDEF_T2T_Ndef.BlkNb++;
}
}
break;
default:
break;
}
}
#endif
#endif
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
#ifdef RW_SUPPORT
#ifndef NO_NDEF_SUPPORT
#include <TML/inc/tool.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF.h>
#define T3T_MAGIC_NUMBER 0xE1
#define T3T_NDEF_TLV 0x03
unsigned char T3T_Check[] = {0x10,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x0B,0x00,0x1,0x80,0x00};
typedef enum
{
Initial,
Getting_AttributeInfo,
Reading_CardContent
} RW_NDEF_T3T_state_t;
typedef struct
{
unsigned char IDm[8];
unsigned char BlkNb;
unsigned short Ptr;
unsigned short Size;
unsigned char *p;
} RW_NDEF_T3T_Ndef_t;
static RW_NDEF_T3T_state_t eRW_NDEF_T3T_State = Initial;
static RW_NDEF_T3T_Ndef_t RW_NDEF_T3T_Ndef;
void RW_NDEF_T3T_Reset(void)
{
eRW_NDEF_T3T_State = Initial;
RW_NDEF_T3T_Ndef.p = NdefBuffer;
}
void RW_NDEF_T3T_SetIDm(unsigned char *pIDm)
{
memcpy(RW_NDEF_T3T_Ndef.IDm, pIDm, sizeof(RW_NDEF_T3T_Ndef.IDm));
memcpy(&T3T_Check[2], pIDm, sizeof(RW_NDEF_T3T_Ndef.IDm));
}
void RW_NDEF_T3T_Read_Next(unsigned char *pRsp, unsigned short Rsp_size, unsigned char *pCmd, unsigned short *pCmd_size)
{
/* By default no further command to be sent */
*pCmd_size = 0;
switch(eRW_NDEF_T3T_State)
{
case Initial:
/* Get AttributeInfo */
memcpy (pCmd, T3T_Check, sizeof(T3T_Check));
*pCmd_size = sizeof(T3T_Check);
eRW_NDEF_T3T_State = Getting_AttributeInfo;
break;
case Getting_AttributeInfo:
/* Is Check success ?*/
if ((pRsp[Rsp_size-1] == 0x00) && (pRsp[1] == 0x07) && (pRsp[10] == 0x00) && (pRsp[11] == 0x00))
{
/* Fill File structure */
RW_NDEF_T3T_Ndef.Size = (pRsp[24] << 16) + (pRsp[25] << 16) + pRsp[26];
/* If provisioned buffer is not large enough, notify the application and stop reading */
if (RW_NDEF_T3T_Ndef.Size > RW_MAX_NDEF_FILE_SIZE)
{
if(pRW_NDEF_PullCb != NULL) pRW_NDEF_PullCb(NULL, 0);
break;
}
RW_NDEF_T3T_Ndef.Ptr = 0;
RW_NDEF_T3T_Ndef.BlkNb = 1;
/* Read first NDEF block */
memcpy (pCmd, T3T_Check, sizeof(T3T_Check));
pCmd[15] = 0x01;
*pCmd_size = sizeof(T3T_Check);
eRW_NDEF_T3T_State = Reading_CardContent;
}
break;
case Reading_CardContent:
/* Is Check success ?*/
if ((pRsp[Rsp_size-1] == 0x00) && (pRsp[1] == 0x07) && (pRsp[10] == 0x00) && (pRsp[11] == 0x00))
{
/* Is NDEF message read completed ?*/
if ((RW_NDEF_T3T_Ndef.Size - RW_NDEF_T3T_Ndef.Ptr) <= 16)
{
memcpy(&RW_NDEF_T3T_Ndef.p[RW_NDEF_T3T_Ndef.Ptr], &pRsp[13], (RW_NDEF_T3T_Ndef.Size - RW_NDEF_T3T_Ndef.Ptr));
/* Notify application of the NDEF reception */
if(pRW_NDEF_PullCb != NULL) pRW_NDEF_PullCb(RW_NDEF_T3T_Ndef.p, RW_NDEF_T3T_Ndef.Size);
}
else
{
memcpy(&RW_NDEF_T3T_Ndef.p[RW_NDEF_T3T_Ndef.Ptr], &pRsp[13], 16);
RW_NDEF_T3T_Ndef.Ptr += 16;
RW_NDEF_T3T_Ndef.BlkNb++;
/* Read next NDEF block */
memcpy (pCmd, T3T_Check, sizeof(T3T_Check));
pCmd[15] = RW_NDEF_T3T_Ndef.BlkNb;
*pCmd_size = sizeof(T3T_Check);
}
}
break;
default:
break;
}
}
#endif
#endif
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
#ifdef RW_SUPPORT
#ifndef NO_NDEF_SUPPORT
#include <TML/inc/tool.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF.h>
const unsigned char RW_NDEF_T4T_APP_Select20[] = {0x00,0xA4,0x04,0x00,0x07,0xD2,0x76,0x00,0x00,0x85,0x01,0x01,0x00};
const unsigned char RW_NDEF_T4T_APP_Select10[] = {0x00,0xA4,0x04,0x00,0x07,0xD2,0x76,0x00,0x00,0x85,0x01,0x00};
const unsigned char RW_NDEF_T4T_CC_Select[] = {0x00,0xA4,0x00,0x0C,0x02,0xE1,0x03};
const unsigned char RW_NDEF_T4T_NDEF_Select[] = {0x00,0xA4,0x00,0x0C,0x02,0xE1,0x04};
const unsigned char RW_NDEF_T4T_Read[] = {0x00,0xB0,0x00,0x00,0x0F};
const unsigned char RW_NDEF_T4T_Write[] = {0x00,0xD6,0x00,0x00,0x00};
const unsigned char RW_NDEF_T4T_OK[] = {0x90, 0x00};
#define WRITE_SZ 54
typedef enum
{
Initial,
Selecting_NDEF_Application20,
Selecting_NDEF_Application10,
Selecting_CC,
Reading_CC,
Selecting_NDEF,
Reading_NDEF_Size,
Reading_NDEF,
Writing_NDEF,
Writing_NDEFsize,
Write_NDEFcomplete
} RW_NDEF_T4T_state_t;
typedef struct
{
unsigned char MappingVersion;
unsigned short MLe;
unsigned short MLc;
unsigned char FileID[2];
unsigned short MaxNdefFileSize;
unsigned char RdAccess;
unsigned char WrAccess;
unsigned short MessagePtr;
unsigned short MessageSize;
unsigned char *pMessage;
} RW_NDEF_T4T_Ndef_t;
static RW_NDEF_T4T_state_t eRW_NDEF_T4T_State = Initial;
static RW_NDEF_T4T_Ndef_t RW_NDEF_T4T_Ndef;
void RW_NDEF_T4T_Reset(void)
{
eRW_NDEF_T4T_State = Initial;
RW_NDEF_T4T_Ndef.pMessage = NdefBuffer;
}
void RW_NDEF_T4T_Read_Next(unsigned char *pRsp, unsigned short Rsp_size, unsigned char *pCmd, unsigned short *pCmd_size)
{
/* By default no further command to be sent */
*pCmd_size = 0;
switch(eRW_NDEF_T4T_State)
{
case Initial:
/* Select NDEF Application in version 2.0 */
memcpy(pCmd, RW_NDEF_T4T_APP_Select20, sizeof(RW_NDEF_T4T_APP_Select20));
*pCmd_size = sizeof(RW_NDEF_T4T_APP_Select20);
eRW_NDEF_T4T_State = Selecting_NDEF_Application20;
break;
case Selecting_NDEF_Application20:
/* Is NDEF Application Selected ?*/
if (!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK)))
{
/* Select CC */
memcpy(pCmd, RW_NDEF_T4T_CC_Select, sizeof(RW_NDEF_T4T_CC_Select));
*pCmd_size = sizeof(RW_NDEF_T4T_CC_Select);
eRW_NDEF_T4T_State = Selecting_CC;
}
else
{
/* Select NDEF Application in version 1.0 */
memcpy(pCmd, RW_NDEF_T4T_APP_Select10, sizeof(RW_NDEF_T4T_APP_Select10));
*pCmd_size = sizeof(RW_NDEF_T4T_APP_Select10);
eRW_NDEF_T4T_State = Selecting_NDEF_Application10;
}
break;
case Selecting_NDEF_Application10:
/* Is NDEF Application Selected ?*/
if (!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK)))
{
/* Select CC */
memcpy(pCmd, RW_NDEF_T4T_CC_Select, sizeof(RW_NDEF_T4T_CC_Select));
pCmd[3] = 0x00;
*pCmd_size = sizeof(RW_NDEF_T4T_CC_Select);
eRW_NDEF_T4T_State = Selecting_CC;
}
break;
case Selecting_CC:
/* Is CC Selected ?*/
if (!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK)))
{
/* Read CC */
memcpy(pCmd, RW_NDEF_T4T_Read, sizeof(RW_NDEF_T4T_Read));
*pCmd_size = sizeof(RW_NDEF_T4T_Read);
eRW_NDEF_T4T_State = Reading_CC;
}
break;
case Reading_CC:
/* Is CC Read ?*/
if ((!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK))) && (Rsp_size == 15 + 2))
{
/* Fill CC structure */
RW_NDEF_T4T_Ndef.MappingVersion = pRsp[2];
RW_NDEF_T4T_Ndef.MLe = (pRsp[3] << 8) + pRsp[4];
RW_NDEF_T4T_Ndef.MLc = (pRsp[5] << 8) + pRsp[6];
RW_NDEF_T4T_Ndef.FileID[0] = pRsp[9];
RW_NDEF_T4T_Ndef.FileID[1] = pRsp[10];
RW_NDEF_T4T_Ndef.MaxNdefFileSize = (pRsp[11] << 8) + pRsp[12];
RW_NDEF_T4T_Ndef.RdAccess = pRsp[13];
RW_NDEF_T4T_Ndef.WrAccess = pRsp[14];
/* Select NDEF */
memcpy(pCmd, RW_NDEF_T4T_NDEF_Select, sizeof(RW_NDEF_T4T_NDEF_Select));
if (RW_NDEF_T4T_Ndef.MappingVersion == 0x10) pCmd[3] = 0x00;
pCmd[5] = RW_NDEF_T4T_Ndef.FileID[0];
pCmd[6] = RW_NDEF_T4T_Ndef.FileID[1];
*pCmd_size = sizeof(RW_NDEF_T4T_NDEF_Select);
eRW_NDEF_T4T_State = Selecting_NDEF;
}
break;
case Selecting_NDEF:
/* Is NDEF Selected ?*/
if (!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK)))
{
/* Get NDEF file size */
memcpy(pCmd, RW_NDEF_T4T_Read, sizeof(RW_NDEF_T4T_Read));
*pCmd_size = sizeof(RW_NDEF_T4T_Read);
pCmd[4] = 2;
eRW_NDEF_T4T_State = Reading_NDEF_Size;
}
break;
case Reading_NDEF_Size:
/* Is Read Success ?*/
if (!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK)))
{
RW_NDEF_T4T_Ndef.MessageSize = (pRsp[0] << 8) + pRsp[1];
/* If provisioned buffer is not large enough, notify the application and stop reading */
if (RW_NDEF_T4T_Ndef.MessageSize > RW_MAX_NDEF_FILE_SIZE)
{
if(pRW_NDEF_PullCb != NULL) pRW_NDEF_PullCb(NULL, 0);
break;
}
RW_NDEF_T4T_Ndef.MessagePtr = 0;
/* Read NDEF data */
memcpy(pCmd, RW_NDEF_T4T_Read, sizeof(RW_NDEF_T4T_Read));
pCmd[3] = 2;
pCmd[4] = (RW_NDEF_T4T_Ndef.MessageSize > RW_NDEF_T4T_Ndef.MLe-1) ? RW_NDEF_T4T_Ndef.MLe-1 : (unsigned char) RW_NDEF_T4T_Ndef.MessageSize;
*pCmd_size = sizeof(RW_NDEF_T4T_Read);
eRW_NDEF_T4T_State = Reading_NDEF;
}
break;
case Reading_NDEF:
/* Is Read Success ?*/
//if (!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK)))
{
memcpy(&RW_NDEF_T4T_Ndef.pMessage[RW_NDEF_T4T_Ndef.MessagePtr], pRsp, Rsp_size - 2);
RW_NDEF_T4T_Ndef.MessagePtr += Rsp_size - 2;
/* Is NDEF message read completed ?*/
if (RW_NDEF_T4T_Ndef.MessagePtr == RW_NDEF_T4T_Ndef.MessageSize)
{
/* Notify application of the NDEF reception */
if(pRW_NDEF_PullCb != NULL) pRW_NDEF_PullCb(RW_NDEF_T4T_Ndef.pMessage, RW_NDEF_T4T_Ndef.MessageSize);
}
else
{
/* Read NDEF data */
memcpy(pCmd, RW_NDEF_T4T_Read, sizeof(RW_NDEF_T4T_Read));
pCmd[3] = RW_NDEF_T4T_Ndef.MessagePtr + 2;
pCmd[4] = ((RW_NDEF_T4T_Ndef.MessageSize - RW_NDEF_T4T_Ndef.MessagePtr) > RW_NDEF_T4T_Ndef.MLe-1) ? RW_NDEF_T4T_Ndef.MLe-1 : (unsigned char) (RW_NDEF_T4T_Ndef.MessageSize - RW_NDEF_T4T_Ndef.MessagePtr);
*pCmd_size = sizeof(RW_NDEF_T4T_Read);
}
}
break;
default:
break;
}
}
void RW_NDEF_T4T_Write_Next(unsigned char *pRsp, unsigned short Rsp_size, unsigned char *pCmd, unsigned short *pCmd_size)
{
/* By default no further command to be sent */
*pCmd_size = 0;
switch(eRW_NDEF_T4T_State)
{
case Initial:
/* Select NDEF Application in version 2.0 */
memcpy(pCmd, RW_NDEF_T4T_APP_Select20, sizeof(RW_NDEF_T4T_APP_Select20));
*pCmd_size = sizeof(RW_NDEF_T4T_APP_Select20);
eRW_NDEF_T4T_State = Selecting_NDEF_Application20;
break;
case Selecting_NDEF_Application20:
/* Is NDEF Application Selected ?*/
if (!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK)))
{
/* Select CC */
memcpy(pCmd, RW_NDEF_T4T_CC_Select, sizeof(RW_NDEF_T4T_CC_Select));
*pCmd_size = sizeof(RW_NDEF_T4T_CC_Select);
eRW_NDEF_T4T_State = Selecting_CC;
}
else
{
/* Select NDEF Application in version 1.0 */
memcpy(pCmd, RW_NDEF_T4T_APP_Select10, sizeof(RW_NDEF_T4T_APP_Select10));
*pCmd_size = sizeof(RW_NDEF_T4T_APP_Select10);
eRW_NDEF_T4T_State = Selecting_NDEF_Application10;
}
break;
case Selecting_NDEF_Application10:
/* Is NDEF Application Selected ?*/
if (!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK)))
{
/* Select CC */
memcpy(pCmd, RW_NDEF_T4T_CC_Select, sizeof(RW_NDEF_T4T_CC_Select));
pCmd[3] = 0x00;
*pCmd_size = sizeof(RW_NDEF_T4T_CC_Select);
eRW_NDEF_T4T_State = Selecting_CC;
}
break;
case Selecting_CC:
/* Is CC Selected ?*/
if (!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK)))
{
/* Read CC */
memcpy(pCmd, RW_NDEF_T4T_Read, sizeof(RW_NDEF_T4T_Read));
*pCmd_size = sizeof(RW_NDEF_T4T_Read);
eRW_NDEF_T4T_State = Reading_CC;
}
break;
case Reading_CC:
/* Is CC Read ?*/
if ((!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK))) && (Rsp_size == 15 + 2))
{
/* Fill CC structure */
RW_NDEF_T4T_Ndef.MappingVersion = pRsp[2];
RW_NDEF_T4T_Ndef.MLe = (pRsp[3] << 8) + pRsp[4];
RW_NDEF_T4T_Ndef.MLc = (pRsp[5] << 8) + pRsp[6];
RW_NDEF_T4T_Ndef.FileID[0] = pRsp[9];
RW_NDEF_T4T_Ndef.FileID[1] = pRsp[10];
RW_NDEF_T4T_Ndef.MaxNdefFileSize = (pRsp[11] << 8) + pRsp[12];
RW_NDEF_T4T_Ndef.RdAccess = pRsp[13];
RW_NDEF_T4T_Ndef.WrAccess = pRsp[14];
/* Select NDEF */
memcpy(pCmd, RW_NDEF_T4T_NDEF_Select, sizeof(RW_NDEF_T4T_NDEF_Select));
if (RW_NDEF_T4T_Ndef.MappingVersion == 0x10) pCmd[3] = 0x00;
pCmd[5] = RW_NDEF_T4T_Ndef.FileID[0];
pCmd[6] = RW_NDEF_T4T_Ndef.FileID[1];
*pCmd_size = sizeof(RW_NDEF_T4T_NDEF_Select);
eRW_NDEF_T4T_State = Selecting_NDEF;
}
break;
case Selecting_NDEF:
/* Is NDEF Selected ?*/
if (!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK)))
{
/* Clearing NDEF message size*/
memcpy(pCmd, RW_NDEF_T4T_Write, sizeof(RW_NDEF_T4T_Write));
pCmd[4] = 2;
pCmd[5] = 0;
pCmd[6] = 0;
*pCmd_size = sizeof(RW_NDEF_T4T_Write) + 2;
RW_NDEF_T4T_Ndef.MessagePtr = 0;
eRW_NDEF_T4T_State = Writing_NDEF;
}
break;
case Writing_NDEF:
/* Is Write Success ?*/
if (!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK)))
{
/* Writing NDEF message */
memcpy(pCmd, RW_NDEF_T4T_Write, sizeof(RW_NDEF_T4T_Write));
pCmd[2] = (RW_NDEF_T4T_Ndef.MessagePtr + 2) >> 8;
pCmd[3] = (RW_NDEF_T4T_Ndef.MessagePtr + 2) & 0xFF;
if((RW_NdefMessage_size - RW_NDEF_T4T_Ndef.MessagePtr) < WRITE_SZ)
{
pCmd[4] = (RW_NdefMessage_size - RW_NDEF_T4T_Ndef.MessagePtr);
memcpy(&pCmd[5], pRW_NdefMessage + RW_NDEF_T4T_Ndef.MessagePtr, (RW_NdefMessage_size - RW_NDEF_T4T_Ndef.MessagePtr));
*pCmd_size = sizeof(RW_NDEF_T4T_Write) + (RW_NdefMessage_size - RW_NDEF_T4T_Ndef.MessagePtr);
eRW_NDEF_T4T_State = Writing_NDEFsize;
}
else
{
pCmd[4] = WRITE_SZ;
memcpy(&pCmd[5], pRW_NdefMessage + RW_NDEF_T4T_Ndef.MessagePtr, WRITE_SZ);
*pCmd_size = sizeof(RW_NDEF_T4T_Write) + WRITE_SZ;
RW_NDEF_T4T_Ndef.MessagePtr += WRITE_SZ;
eRW_NDEF_T4T_State = Writing_NDEF;
}
}
break;
case Writing_NDEFsize:
/* Is Write Success ?*/
if (!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK)))
{
memcpy(pCmd, RW_NDEF_T4T_Write, sizeof(RW_NDEF_T4T_Write));
pCmd[4] = 2;
pCmd[5] = RW_NdefMessage_size >> 8;
pCmd[6] = RW_NdefMessage_size & 0xFF;
*pCmd_size = sizeof(RW_NDEF_T4T_Write) + 2;
eRW_NDEF_T4T_State = Write_NDEFcomplete;
}
break;
case Write_NDEFcomplete:
/* Is Write Success ?*/
if (!memcmp(&pRsp[Rsp_size - 2], RW_NDEF_T4T_OK, sizeof(RW_NDEF_T4T_OK)))
{
/* Notify application of the NDEF reception */
if(pRW_NDEF_PushCb != NULL) pRW_NDEF_PushCb(pRW_NdefMessage, RW_NdefMessage_size);
}
break;
default:
break;
}
}
#endif
#endif
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
#ifdef CARDEMU_SUPPORT
#ifndef NO_NDEF_SUPPORT
#include <TML/inc/tool.h>
#include <NfcLibrary/NdefLibrary/inc/T4T_NDEF_emu.h>
const unsigned char T4T_NDEF_EMU_APP_Select[] = {0x00,0xA4,0x04,0x00,0x07,0xD2,0x76,0x00,0x00,0x85,0x01,0x01};
const unsigned char T4T_NDEF_EMU_CC[] = {0x00, 0x0F, 0x20, 0x00, 0xFF, 0x00, 0xFF, 0x04, 0x06, 0xE1, 0x04, 0x00, 0xFF, 0x00, 0xFF};
const unsigned char T4T_NDEF_EMU_CC_Select[] = {0x00,0xA4,0x00,0x0C,0x02,0xE1,0x03};
const unsigned char T4T_NDEF_EMU_NDEF_Select[] = {0x00,0xA4,0x00,0x0C,0x02,0xE1,0x04};
const unsigned char T4T_NDEF_EMU_Read[] = {0x00,0xB0};
const unsigned char T4T_NDEF_EMU_OK[] = {0x90, 0x00};
const unsigned char T4T_NDEF_EMU_NOK[] = {0x6A, 0x82};
unsigned char *pT4T_NdefMessage;
unsigned short T4T_NdefMessage_size = 0;
typedef enum
{
Ready,
NDEF_Application_Selected,
CC_Selected,
NDEF_Selected,
} T4T_NDEF_EMU_state_t;
typedef void T4T_NDEF_EMU_Callback_t (unsigned char*, unsigned short);
static T4T_NDEF_EMU_state_t eT4T_NDEF_EMU_State = Ready;
static T4T_NDEF_EMU_Callback_t *pT4T_NDEF_EMU_PushCb = NULL;
static void T4T_NDEF_EMU_FillRsp (unsigned char *pRsp, unsigned short offset, unsigned char length)
{
if (offset == 0)
{
pRsp[0] = (T4T_NdefMessage_size & 0xFF00) >> 8;
pRsp[1] = (T4T_NdefMessage_size & 0x00FF);
memcpy(&pRsp[2], &pT4T_NdefMessage[0], length-2);
}
else if (offset == 1)
{
pRsp[0] = (T4T_NdefMessage_size & 0x00FF);
memcpy(&pRsp[1], &pT4T_NdefMessage[0], length-1);
}
else
{
memcpy(pRsp, &pT4T_NdefMessage[offset-2], length);
}
/* Did we reached the end of NDEF message ?*/
if ((offset + length) >= (T4T_NdefMessage_size + 2))
{
/* Notify application of the NDEF send */
if(pT4T_NDEF_EMU_PushCb != NULL) pT4T_NDEF_EMU_PushCb(pT4T_NdefMessage, T4T_NdefMessage_size);
}
}
bool T4T_NDEF_EMU_SetMessage(unsigned char *pMessage, unsigned short Message_size, void *pCb)
{
pT4T_NdefMessage = pMessage;
T4T_NdefMessage_size = Message_size;
pT4T_NDEF_EMU_PushCb = (T4T_NDEF_EMU_Callback_t*) pCb;
return true;
}
void T4T_NDEF_EMU_Reset(void)
{
eT4T_NDEF_EMU_State = Ready;
}
void T4T_NDEF_EMU_Next(unsigned char *pCmd, unsigned short Cmd_size, unsigned char *pRsp, unsigned short *pRsp_size)
{
bool eStatus = false;
if (!memcmp(pCmd, T4T_NDEF_EMU_APP_Select, sizeof(T4T_NDEF_EMU_APP_Select)))
{
*pRsp_size = 0;
eStatus = true;
eT4T_NDEF_EMU_State = NDEF_Application_Selected;
}
else if (!memcmp(pCmd, T4T_NDEF_EMU_CC_Select, sizeof(T4T_NDEF_EMU_CC_Select)))
{
if(eT4T_NDEF_EMU_State == NDEF_Application_Selected)
{
*pRsp_size = 0;
eStatus = true;
eT4T_NDEF_EMU_State = CC_Selected;
}
}
else if (!memcmp(pCmd, T4T_NDEF_EMU_NDEF_Select, sizeof(T4T_NDEF_EMU_NDEF_Select)))
{
*pRsp_size = 0;
eStatus = true;
eT4T_NDEF_EMU_State = NDEF_Selected;
}
else if (!memcmp(pCmd, T4T_NDEF_EMU_Read, sizeof(T4T_NDEF_EMU_Read)))
{
if(eT4T_NDEF_EMU_State == CC_Selected)
{
memcpy(pRsp, T4T_NDEF_EMU_CC, sizeof(T4T_NDEF_EMU_CC));
*pRsp_size = sizeof(T4T_NDEF_EMU_CC);
eStatus = true;
}
else if (eT4T_NDEF_EMU_State == NDEF_Selected)
{
unsigned short offset = (pCmd[2] << 8) + pCmd[3];
unsigned char length = pCmd[4];
if(length <= (T4T_NdefMessage_size + offset + 2))
{
T4T_NDEF_EMU_FillRsp(pRsp, offset, length);
*pRsp_size = length;
eStatus = true;
}
}
}
if (eStatus == true)
{
memcpy(&pRsp[*pRsp_size], T4T_NDEF_EMU_OK, sizeof(T4T_NDEF_EMU_OK));
*pRsp_size += sizeof(T4T_NDEF_EMU_OK);
} else
{
memcpy(pRsp, T4T_NDEF_EMU_NOK, sizeof(T4T_NDEF_EMU_NOK));
*pRsp_size = sizeof(T4T_NDEF_EMU_NOK);
T4T_NDEF_EMU_Reset();
}
}
#endif
#endif
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
#include <NfcLibrary/inc/Nfc.h>
#ifdef CARDEMU_SUPPORT
#include <NfcLibrary/NdefLibrary/inc/T4T_NDEF_emu.h>
#endif
#ifdef P2P_SUPPORT
#include <NfcLibrary/NdefLibrary/inc/P2P_NDEF.h>
#endif
#ifdef RW_SUPPORT
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF.h>
#include <NfcLibrary/NdefLibrary/inc/RW_NDEF_T3T.h>
#endif
#define NXPNCI_SUCCESS NFC_SUCCESS
#define NXPNCI_ERROR NFC_ERROR
#ifdef NCI_DEBUG
#include <stdio.h>
#define NCI_PRINT(...) {printf(__VA_ARGS__);}
unsigned short debug_loop;
#define NCI_PRINT_LOOP(x,y) {for(debug_loop=0; debug_loop<y; debug_loop++) printf("%.2x ", x[debug_loop]);}
#define NCI_PRINT_BUF(x,y,z) {char tmp[200]; int loop; sprintf(tmp, x); \
for(loop=0;loop<(z<30?z:30);loop++) sprintf(tmp+7+(loop*3), "%.2x ", y[loop]); \
if(loop==30) sprintf(tmp+7+(loop*3), "...\n"); \
else sprintf(tmp+7+(loop*3), "\n"); \
printf(tmp);}
#else
#define NCI_PRINT(...)
#define NCI_PRINT_LOOP(x,y)
#define NCI_PRINT_BUF(x,y,z)
#endif
This diff is collapsed.
/*
* Copyright (c), NXP Semiconductors Caen / France
*
* (C)NXP Semiconductors
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* NXP reserves the right to make changes without notice at any time.
* NXP makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. NXP must not be liable for any loss or damage
* arising from its use.
*/
/***** NFC dedicated interface ****************************************/
/*
* Status code definition used as API returned values
*/
#define NFC_SUCCESS 0
#define NFC_ERROR 1
/*
* Flag definition used as Interface values
*/
#define INTF_UNDETERMINED 0x0
#define INTF_FRAME 0x1
#define INTF_ISODEP 0x2
#define INTF_NFCDEP 0x3
#define INTF_TAGCMD 0x80
/*
* Flag definition used as Protocol values
*/
#define PROT_UNDETERMINED 0x0
#define PROT_T1T 0x1
#define PROT_T2T 0x2
#define PROT_T3T 0x3
#define PROT_ISODEP 0x4
#define PROT_NFCDEP 0x5
#define PROT_ISO15693 0x6
#define PROT_MIFARE 0x80
/*
* Flag definition used as Mode values
*/
#define MODE_POLL 0x00
#define MODE_LISTEN 0x80
#define MODE_MASK 0xF0
/*
* Flag definition used as Technologies values
*/
#define TECH_PASSIVE_NFCA 0
#define TECH_PASSIVE_NFCB 1
#define TECH_PASSIVE_NFCF 2
#define TECH_ACTIVE_NFCA 3
#define TECH_ACTIVE_NFCF 5
#define TECH_PASSIVE_15693 6
/*
* Flag definition used for NFC library configuration
*/
#define NXPNCI_MODE_CARDEMU (1<<0)
#define NXPNCI_MODE_P2P (1<<1)
#define NXPNCI_MODE_RW (1<<2)
/*
* Definition of operations handled when processing Reader mode
*/
typedef enum
{
#ifndef NO_NDEF_SUPPORT
READ_NDEF,
WRITE_NDEF,
#endif
PRESENCE_CHECK
} NxpNci_RW_Operation_t;
/*
* Definition of discovered remote device properties information
*/
/* POLL passive type A */
typedef struct
{
unsigned char SensRes[2];
unsigned char NfcIdLen;
unsigned char NfcId[10];
unsigned char SelResLen;
unsigned char SelRes[1];
} NxpNci_RfIntf_info_APP_t;
/* POLL passive type B */
typedef struct
{
unsigned char SensResLen;
unsigned char SensRes[12];
} NxpNci_RfIntf_info_BPP_t;
/* POLL passive type F */
typedef struct
{
unsigned char BitRate;
unsigned char SensResLen;
unsigned char SensRes[18];
} NxpNci_RfIntf_info_FPP_t;
/* POLL passive type ISO15693 */
typedef struct
{
unsigned char AFI;
unsigned char DSFID;
unsigned char ID[8];
} NxpNci_RfIntf_info_VPP_t;
typedef union
{
NxpNci_RfIntf_info_APP_t NFC_APP;
NxpNci_RfIntf_info_BPP_t NFC_BPP;
NxpNci_RfIntf_info_FPP_t NFC_FPP;
NxpNci_RfIntf_info_VPP_t NFC_VPP;
} NxpNci_RfIntf_Info_t;
/*
* Definition of discovered remote device properties
*/
typedef struct
{
unsigned char Interface;
unsigned char Protocol;
unsigned char ModeTech;
bool MoreTags;
NxpNci_RfIntf_Info_t Info;
} NxpNci_RfIntf_t;
/**********************************************************************/
/***** NFC dedicated API **********************************************/
/*
* Open connection to the NXP-NCI device
* return NFC_SUCCESS or NFC_ERROR
*/
bool NxpNci_Connect(void);
/*
* Close connection to the NXP-NCI device
* return NFC_SUCCESS or NFC_ERROR
*/
bool NxpNci_Disconnect(void);
/*
* Configure NXP-NCI device settings
* Related settings are defined in Nfc_settings.h header file
* To be called after NxpNci_Connect() and prior to NxpNci_ConfigureMode() APIs
* return NFC_SUCCESS or NFC_ERROR
*/
bool NxpNci_ConfigureSettings(void);
/*
* Configure NXP-NCI device mode
* - mode: specifies which modes to be configured (see NXPNCI_MODE_xxx flags)
* return NFC_SUCCESS or NFC_ERROR
*/
bool NxpNci_ConfigureMode(unsigned char mode);
/*
* Start NFC Discovery loop for remote NFC device detection
* - pTechTab: list of NFC technologies to look for (see TECH_xxx_xxx flags)
* \param TechTabSize: number of items in the list
* return NFC_SUCCESS or NFC_ERROR
*/
bool NxpNci_StartDiscovery(unsigned char *pTechTab, unsigned char TechTabSize);
/*
* Stop NFC Discovery loop
* return NFC_SUCCESS or NFC_ERROR
*/
bool NxpNci_StopDiscovery(void);
/*
* Wait until remote NFC device is discovered
* - pRfIntf: filled with discovered NFC remote device properties
* return NFC_SUCCESS or NFC_ERROR
*/
bool NxpNci_WaitForDiscoveryNotification(NxpNci_RfIntf_t *pRfIntf);
/**********************************************************************/
/***** Reader/writer dedicated APIs ***********************************/
#ifdef RW_SUPPORT
#ifndef NO_NDEF_SUPPORT
/*
* Register NDEF message to be written to remote NFC Tag
* - pMessage: pointer to the NDEF message
* - Message_size: NDEF message size
* - pCb: pointer to function to be called back when tag has been written
* return NFC_SUCCESS or NFC_ERROR
*/
bool RW_NDEF_SetMessage(unsigned char *pMessage, unsigned short Message_size, void *pCb);
/*
* Register function called when NDEF message is read from remote NFC Tag
* - pCb: pointer to function to be called back when NDEF message has been read
*/
void RW_NDEF_RegisterPullCallback(void *pCb);
#endif
/*
* Process the operation identified as parameter with discovered remote NFC tag (function is blocking until the end of the operation)
* - RfIntf: discovered NFC device properties
* - Operation: select operation to be done with the remote NFC tag
* o READ_NDEF: extract NDEF message from the tag, previously registered callback function will be called whenever complete NDEF message is found.
* o WRITE_NDEF: write previously registered NDEF message to the tag
* o PRESENCE_CHECK: perform presence check until tag has been removed (function is blocking until card is removed)
*/
void NxpNci_ProcessReaderMode(NxpNci_RfIntf_t RfIntf, NxpNci_RW_Operation_t Operation);
/*
* Perform RAW transceive operation (send then receive) with the remote tag
* - pCommand: pointer to the command to send
* - CommandSize: command size
* - pAnswer: pointer to buffer for getting the response
* - pAnswerSize: response size
* return NFC_SUCCESS or NFC_ERROR
*/
bool NxpNci_ReaderTagCmd (unsigned char *pCommand, unsigned char CommandSize, unsigned char *pAnswer, unsigned char *pAnswerSize);
/*
* Perform activation of the next tag (in case of multiple tag detection or multi-protocol tag)
* - pRfIntf: filled with discovered NFC remote device properties
* return NFC_SUCCESS or NFC_ERROR
*/
bool NxpNci_ReaderActivateNext(NxpNci_RfIntf_t *pRfIntf);
/*
* Perform deactivation then reactivation of the current tag
* - pRfIntf: filled with discovered NFC remote device properties
* return NFC_SUCCESS or NFC_ERROR
*/
bool NxpNci_ReaderReActivate(NxpNci_RfIntf_t *pRfIntf);
#endif
/**********************************************************************/
/***** Card Emulation dedicated APIs **********************************/
#ifdef CARDEMU_SUPPORT
#ifndef NO_NDEF_SUPPORT
/*
* Register NDEF message to be exposed to remote NFC reader Device
* - pMessage: pointer to the NDEF message
* - Message_size: NDEF message size
* - pCb: pointer to function to be called back when tag has been written
* return NFC_SUCCESS or NFC_ERROR
*/
bool T4T_NDEF_EMU_SetMessage(unsigned char *pMessage, unsigned short Message_size, void *pCb);
#endif
/*
* Expose the previously registered NDEF message to discovered remote NFC reader (function is blocking until the remote reader is lost):
* - RfIntf: discovered NFC device properties
*/
void NxpNci_ProcessCardMode(NxpNci_RfIntf_t RfIntf);
/*
* Perform RAW reception of data from the remote reader
* - pData: pointer to buffer for getting the data
* - pDataSize: received data size
* return NFC_SUCCESS or NFC_ERROR
*/
bool NxpNci_CardModeReceive (unsigned char *pData, unsigned char *pDataSize);
/*
* Perform RAW transmission of data from the remote reader
* - pData: pointer to data to transmit
* - DataSize: size of data to transmit
* return NFC_SUCCESS or NFC_ERROR
*/
bool NxpNci_CardModeSend (unsigned char *pData, unsigned char DataSize);
#endif
/**********************************************************************/
/***** P2P dedicated APIs *********************************************/
#ifdef P2P_SUPPORT
/*
* Register NDEF message to be sent to remote NFC Peer to peer Device
* - pMessage: pointer to the NDEF message
* - Message_size: NDEF message size
* - pCb: pointer to function to be called back when tag has been sent
* return NFC_SUCCESS or NFC_ERROR
*/
bool P2P_NDEF_SetMessage(unsigned char *pMessage, unsigned short Message_size, void *pCb);
/*
* Register function called when NDEF message is received from remote NFC Peer to peer Device
* - pCb: pointer to function to be called back when NDEF message has been received
*/
void P2P_NDEF_RegisterPullCallback(void *pCb);
/* Process P2P operation (function is blocking until the remote peer is lost):
* ¤ SNEP server to allow receiving NDEF message from remote NFC P2P device
* ¤ SNEP client to send previously registered NDEF message
* - RfIntf: discovered NFC device properties
*/
void NxpNci_ProcessP2pMode(NxpNci_RfIntf_t RfIntf);
#endif
/**********************************************************************/
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment