Commit 1d36547d authored by Matej Frančeškin's avatar Matej Frančeškin

Remove reference to NXP NFC Library. Keep only QtNFC.

parent a97230c7
......@@ -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 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.
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 setting ****************************************/
/* Following definitions specifies which settings will apply when NxpNci_ConfigureSettings()
* API is called from the application
*/
#define NXP_CORE_CONF 1
#define NXP_CORE_CONF_EXTN 1
#define NXP_CORE_STANDBY 1
#define NXP_CLK_CONF 1 // 1=Xtal, 2=PLL
#define NXP_TVDD_CONF 1 // 1=CFG1, 2=CFG2
#define NXP_RF_CONF 1
#if NXP_CORE_CONF
/* NCI standard dedicated settings
* Refer to NFC Forum NCI standard for more details
*/
uint8_t NxpNci_CORE_CONF[]={0x20, 0x02, 0x05, 0x01, /* CORE_SET_CONFIG_CMD */
0x00, 0x02, 0x00, 0x01 /* TOTAL_DURATION */
};
#endif
#if NXP_CORE_CONF_EXTN
/* NXP-NCI extension dedicated setting
* Refer to NFC controller User Manual for more details
*/
uint8_t NxpNci_CORE_CONF_EXTN[]={0x20, 0x02, 0x0D, 0x03, /* CORE_SET_CONFIG_CMD */
0xA0, 0x40, 0x01, 0x00, /* TAG_DETECTOR_CFG */
0xA0, 0x41, 0x01, 0x04, /* TAG_DETECTOR_THRESHOLD_CFG */
0xA0, 0x43, 0x01, 0x00 /* TAG_DETECTOR_FALLBACK_CNT_CFG */
};
#endif
#if NXP_CORE_STANDBY
/* NXP-NCI standby enable setting
* Refer to NFC controller User Manual for more details
*/
uint8_t NxpNci_CORE_STANDBY[]={0x2F, 0x00, 0x01, 0x01}; /* last byte indicates enable/disable */
#endif
#if NXP_CLK_CONF
/* NXP-NCI CLOCK configuration
* Refer to NFC controller Hardware Design Guide document for more details
*/
#if (NXP_CLK_CONF == 1)
/* Xtal configuration */
uint8_t NxpNci_CLK_CONF[]={0x20, 0x02, 0x05, 0x01, /* CORE_SET_CONFIG_CMD */
0xA0, 0x03, 0x01, 0x08 /* CLOCK_SEL_CFG */
};
#else
/* PLL configuration */
uint8_t NxpNci_CLK_CONF[]={0x20, 0x02, 0x09, 0x02, /* CORE_SET_CONFIG_CMD */
0xA0, 0x03, 0x01, 0x11, /* CLOCK_SEL_CFG */
0xA0, 0x04, 0x01, 0x01 /* CLOCK_TO_CFG */
};
#endif
#endif
#if NXP_TVDD_CONF
/* NXP-NCI TVDD configuration
* Refer to NFC controller Hardware Design Guide document for more details
*/
/* RF configuration related to 1st generation of NXP-NCI controller (e.g PN7120) */
uint8_t NxpNci_TVDD_CONF_1stGen[]={0x20, 0x02, 0x05, 0x01, 0xA0, 0x13, 0x01, 0x00};
/* RF configuration related to 2nd generation of NXP-NCI controller (e.g PN7150)*/
#if (NXP_TVDD_CONF == 1)
/* CFG1: Vbat is used to generate the VDD(TX) through TXLDO */
uint8_t NxpNci_TVDD_CONF_2ndGen[]={0x20, 0x02, 0x07, 0x01, 0xA0, 0x0E, 0x03, 0x02, 0x09, 0x00};
#else
/* CFG2: external 5V is used to generate the VDD(TX) through TXLDO */
uint8_t NxpNci_TVDD_CONF_2ndGen[]={0x20, 0x02, 0x07, 0x01, 0xA0, 0x0E, 0x03, 0x06, 0x64, 0x00};
#endif
#endif
#if NXP_RF_CONF
/* NXP-NCI RF configuration
* Refer to NFC controller Antenna Design and Tuning Guidelines document for more details
*/
/* RF configuration related to 1st generation of NXP-NCI controller (e.g PN7120) */
/* Following configuration is the default settings of PN7120 NFC Controller */
uint8_t NxpNci_RF_CONF_1stGen[]={0x20, 0x02, 0x38, 0x07,
0xA0, 0x0D, 0x06, 0x06, 0x42, 0x01, 0x00, 0xF1, 0xFF, /* RF_CLIF_CFG_TARGET CLIF_ANA_TX_AMPLITUDE_REG */
0xA0, 0x0D, 0x06, 0x06, 0x44, 0xA3, 0x90, 0x03, 0x00, /* RF_CLIF_CFG_TARGET CLIF_ANA_RX_REG */
0xA0, 0x0D, 0x06, 0x34, 0x2D, 0xDC, 0x50, 0x0C, 0x00, /* RF_CLIF_CFG_BR_106_I_RXA_P CLIF_SIGPRO_RM_CONFIG1_REG */
0xA0, 0x0D, 0x04, 0x06, 0x03, 0x00, 0x70, /* RF_CLIF_CFG_TARGET CLIF_TRANSCEIVE_CONTROL_REG */
0xA0, 0x0D, 0x03, 0x06, 0x16, 0x00, /* RF_CLIF_CFG_TARGET CLIF_TX_UNDERSHOOT_CONFIG_REG */
0xA0, 0x0D, 0x03, 0x06, 0x15, 0x00, /* RF_CLIF_CFG_TARGET CLIF_TX_OVERSHOOT_CONFIG_REG */
0xA0, 0x0D, 0x06, 0x32, 0x4A, 0x53, 0x07, 0x01, 0x1B /* RF_CLIF_CFG_BR_106_I_TXA CLIF_ANA_TX_SHAPE_CONTROL_REG */
};
/* RF configuration related to 2nd generation of NXP-NCI controller (e.g PN7150)*/
/* Following configuration relates to performance optimization of OM5578/PN7150 NFC Controller demo kit */
uint8_t NxpNci_RF_CONF_2ndGen[]={0x20, 0x02, 0xB7, 0x14,
0xA0, 0x0D, 0x06, 0x04, 0x35, 0x90, 0x01, 0xF4, 0x01, /* RF_CLIF_CFG_INITIATOR CLIF_AGC_INPUT_REG */
0xA0, 0x0D, 0x06, 0x06, 0x44, 0x01, 0x90, 0x03, 0x00, /* RF_CLIF_CFG_TARGET CLIF_ANA_RX_REG */
0xA0, 0x0D, 0x06, 0x06, 0x30, 0xB0, 0x01, 0x10, 0x00, /* RF_CLIF_CFG_TARGET CLIF_SIGPRO_ADCBCM_THRESHOLD_REG */
0xA0, 0x0D, 0x06, 0x06, 0x42, 0x02, 0x00, 0xFF, 0xFF, /* RF_CLIF_CFG_TARGET CLIF_ANA_TX_AMPLITUDE_REG */
0xA0, 0x0D, 0x03, 0x06, 0x3F, 0x04, /* RF_CLIF_CFG_TARGET CLIF_TEST_CONTROL_REG */
0xA0, 0x0D, 0x06, 0x20, 0x42, 0x88, 0x00, 0xFF, 0xFF, /* RF_CLIF_CFG_TECHNO_I_TX15693 CLIF_ANA_TX_AMPLITUDE_REG */
0xA0, 0x0D, 0x04, 0x22, 0x44, 0x22, 0x00, /* RF_CLIF_CFG_TECHNO_I_RX15693 CLIF_ANA_RX_REG */
0xA0, 0x0D, 0x06, 0x22, 0x2D, 0x50, 0x34, 0x0C, 0x00, /* RF_CLIF_CFG_TECHNO_I_RX15693 CLIF_SIGPRO_RM_CONFIG1_REG */
0xA0, 0x0D, 0x06, 0x32, 0x42, 0xF8, 0x00, 0xFF, 0xFF, /* RF_CLIF_CFG_BR_106_I_TXA CLIF_ANA_TX_AMPLITUDE_REG */
0xA0, 0x0D, 0x06, 0x34, 0x2D, 0x24, 0x37, 0x0C, 0x00, /* RF_CLIF_CFG_BR_106_I_RXA_P CLIF_SIGPRO_RM_CONFIG1_REG */
0xA0, 0x0D, 0x06, 0x34, 0x33, 0x86, 0x80, 0x00, 0x70, /* RF_CLIF_CFG_BR_106_I_RXA_P CLIF_AGC_CONFIG0_REG */
0xA0, 0x0D, 0x04, 0x34, 0x44, 0x22, 0x00, /* RF_CLIF_CFG_BR_106_I_RXA_P CLIF_ANA_RX_REG */
0xA0, 0x0D, 0x06, 0x42, 0x2D, 0x15, 0x45, 0x0D, 0x00, /* RF_CLIF_CFG_BR_848_I_RXA CLIF_SIGPRO_RM_CONFIG1_REG */
0xA0, 0x0D, 0x04, 0x46, 0x44, 0x22, 0x00, /* RF_CLIF_CFG_BR_106_I_RXB CLIF_ANA_RX_REG */
0xA0, 0x0D, 0x06, 0x46, 0x2D, 0x05, 0x59, 0x0E, 0x00, /* RF_CLIF_CFG_BR_106_I_RXB CLIF_SIGPRO_RM_CONFIG1_REG */
0xA0, 0x0D, 0x06, 0x44, 0x42, 0x88, 0x00, 0xFF, 0xFF, /* RF_CLIF_CFG_BR_106_I_TXB CLIF_ANA_TX_AMPLITUDE_REG */
0xA0, 0x0D, 0x06, 0x56, 0x2D, 0x05, 0x9F, 0x0C, 0x00, /* RF_CLIF_CFG_BR_212_I_RXF_P CLIF_SIGPRO_RM_CONFIG1_REG */
0xA0, 0x0D, 0x06, 0x54, 0x42, 0x88, 0x00, 0xFF, 0xFF, /* RF_CLIF_CFG_BR_212_I_TXF CLIF_ANA_TX_AMPLITUDE_REG */
0xA0, 0x0D, 0x06, 0x0A, 0x33, 0x80, 0x86, 0x00, 0x70, /* RF_CLIF_CFG_I_ACTIVE CLIF_AGC_CONFIG0_REG */
0xA0, 0x1D, 0x11, 0x57, 0x33, 0x14, 0x17, 0x00, 0xAA, 0x85, 0x00, 0x80, 0x55, 0x2A, 0x04, 0x00, 0x63, 0x00, 0x00, 0x00
};
#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.
*/
#define NDEF_EMPTY 0x00
#define NDEF_WELL_KNOWN 0x01
#define NDEF_MEDIA 0x02
#define NDEF_ABSOLUTE_URI 0x03
#define NDEF_EXTERNAL 0x04
#define NDEF_UNKNOWN 0x05
#define NDEF_UNCHANGED 0x06
#define NDEF_RESERVED 0x07
#define NDEF_RECORD_MB_MASK 0x80
#define NDEF_RECORD_ME_MASK 0x40
#define NDEF_RECORD_CF_MASK 0x20
#define NDEF_RECORD_SR_MASK 0x10
#define NDEF_RECORD_IL_MASK 0x08
#define NDEF_RECORD_TNF_MASK 0x07
typedef enum
{
WELL_KNOWN_SIMPLE_TEXT,
WELL_KNOWN_SIMPLE_URI,
WELL_KNOWN_SMART_POSTER,
WELL_KNOWN_HANDOVER_SELECT,
WELL_KNOWN_HANDOVER_REQUEST,
WELL_KNOWN_ALTERNATIVE_CARRIER,
WELL_KNOWN_COLLISION_RESOLUTION,
MEDIA_VCARD,
MEDIA_HANDOVER_WIFI,
MEDIA_HANDOVER_BT,
MEDIA_HANDOVER_BLE,
MEDIA_HANDOVER_BLE_SECURE,
ABSOLUTE_URI,
UNSUPPORTED_NDEF_RECORD = 0xFF
}NdefRecordType_e;
typedef struct
{
NdefRecordType_e recordType;
unsigned char * recordPayload;
unsigned int recordPayloadSize;
} NdefRecord_t;
const char* ndef_helper_WifiAuth(unsigned char auth);
const char* ndef_helper_WifiEnc(unsigned char enc);
const char* ndef_helper_UriHead(unsigned char head);
NdefRecord_t DetectNdefRecordType(unsigned char *pNdefRecord);
unsigned char* GetNextRecord(unsigned char *pNdefRecord);
/*
* 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.
*/
extern "C" {
void task_nfc(void);
}
/*
* 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 <stdio.h>
#include <stdint.h>
#include <string.h>
#include <NfcTask/inc/ndef_helper.h>
const char* ndef_helper_WifiAuth(unsigned char auth)
{
switch (auth)
{
case 0x01: return "Open";
case 0x02: return "WPA-Personal";
case 0x04: return "Shared";
case 0x08: return "WPA-Enterprise";
case 0x10: return "WPA2-Enterprise";
case 0x20: return "WPA2-Personal";
default: return "unknown";
}
}
const char* ndef_helper_WifiEnc(unsigned char enc)
{
switch (enc)
{
case 0x01: return "None";
case 0x02: return "WEP";
case 0x04: return "TKIP";
case 0x08: return "AES";
case 0x10: return "AES/TKIP";
default: return "unknown";
}
}
const char* ndef_helper_UriHead(unsigned char head)
{
switch (head) {
case 0: return ("");
case 1: return ("http://www.");
case 2: return ("https://www.");
case 3: return ("http://");
case 4: return ("https://");
case 5: return ("tel:");
case 6: return ("mailto:");
default:return ("!!!unknown!!!");
}
}
NdefRecord_t DetectNdefRecordType(unsigned char *pNdefRecord)
{
NdefRecord_t record;
uint8_t typeField;
/* Short or normal record ?*/
if (pNdefRecord[0] & NDEF_RECORD_SR_MASK)
{
record.recordPayloadSize = pNdefRecord[2];
typeField = 3;
}
else
{
record.recordPayloadSize = (pNdefRecord[2]<<24) + (pNdefRecord[3]<<16) + (pNdefRecord[4]<<8) + pNdefRecord[5];
typeField = 6;
}
/* ID present ?*/
if(pNdefRecord[0] & NDEF_RECORD_IL_MASK)
{
record.recordPayload = pNdefRecord + typeField + pNdefRecord[1] + 1 + pNdefRecord[typeField];
typeField++;
}
else
{
record.recordPayload = pNdefRecord + typeField + pNdefRecord[1];
}
/* Well known Record Type ?*/
if ((pNdefRecord[0] & NDEF_RECORD_TNF_MASK) == NDEF_WELL_KNOWN)
{
if (pNdefRecord[1] == 0x1)
{
switch (pNdefRecord[typeField])
{
case 'T':
record.recordType = WELL_KNOWN_SIMPLE_TEXT;
break;
case 'U':
record.recordType = WELL_KNOWN_SIMPLE_URI;
break;
default:
record.recordType = UNSUPPORTED_NDEF_RECORD;
break;
}
} else if (pNdefRecord[1] == 0x2)
{
if (memcmp(&pNdefRecord[typeField], "Sp", pNdefRecord[1]) == 0x0)
{
record.recordType = WELL_KNOWN_SMART_POSTER;
}
else if (memcmp(&pNdefRecord[typeField], "Hs", pNdefRecord[1]) == 0x0)
{
record.recordType = WELL_KNOWN_HANDOVER_SELECT;
}
else if (memcmp(&pNdefRecord[typeField], "Hr", pNdefRecord[1]) == 0x0)
{
record.recordType = WELL_KNOWN_HANDOVER_REQUEST;
}
else if (memcmp(&pNdefRecord[typeField], "ac", pNdefRecord[1]) == 0x0)
{
record.recordType = WELL_KNOWN_ALTERNATIVE_CARRIER;
}
else if (memcmp(&pNdefRecord[typeField], "cr", pNdefRecord[1]) == 0x0)
{
record.recordType = WELL_KNOWN_COLLISION_RESOLUTION;
}
else
{
record.recordType = UNSUPPORTED_NDEF_RECORD;
}
}
}
/* Media Record Type ?*/
else if ((pNdefRecord[0] & NDEF_RECORD_TNF_MASK) == NDEF_MEDIA)
{
if ((memcmp(&pNdefRecord[typeField], "text/x-vCard", pNdefRecord[1]) == 0x0) ||
(memcmp(&pNdefRecord[typeField], "text/vcard", pNdefRecord[1]) == 0x0))
{
record.recordType = MEDIA_VCARD;
}
else if (memcmp(&pNdefRecord[typeField], "application/vnd.wfa.wsc", pNdefRecord[1]) == 0x0)
{
record.recordType = MEDIA_HANDOVER_WIFI;
}
else if (memcmp(&pNdefRecord[typeField], "application/vnd.bluetooth.ep.oob", pNdefRecord[1]) == 0x0)
{
record.recordType = MEDIA_HANDOVER_BT;
}
else if (memcmp(&pNdefRecord[typeField], "application/vnd.bluetooth.le.oob", pNdefRecord[1]) == 0x0)
{
record.recordType = MEDIA_HANDOVER_BLE;
}
else if (memcmp(&pNdefRecord[typeField], "application/vnd.bluetooth.secure.le.oob", pNdefRecord[1]) == 0x0)
{
record.recordType = MEDIA_HANDOVER_BLE_SECURE;
}
else
{
record.recordType = UNSUPPORTED_NDEF_RECORD;
}
}
/* Absolute URI Record Type ?*/
else if ((pNdefRecord[0] & NDEF_RECORD_TNF_MASK) == NDEF_ABSOLUTE_URI)
{
record.recordType = ABSOLUTE_URI;
}
else
{
record.recordType = UNSUPPORTED_NDEF_RECORD;
}
return record;
}
unsigned char* GetNextRecord(unsigned char *pNdefRecord)
{
unsigned char *temp = NULL;
/* Message End ?*/
if (!(pNdefRecord[0] & NDEF_RECORD_ME_MASK)) {
/* Short or normal record ?*/
if (pNdefRecord[0] & NDEF_RECORD_SR_MASK)
{
/* ID present ?*/
if(pNdefRecord[0] & NDEF_RECORD_IL_MASK)
temp = (pNdefRecord + 4 + pNdefRecord[1] + pNdefRecord[2] + pNdefRecord[3]);
else
temp = (pNdefRecord + 3 + pNdefRecord[1] + pNdefRecord[2]);
}
else
{
/* ID present ?*/
if(pNdefRecord[0] & NDEF_RECORD_IL_MASK)
temp = (pNdefRecord + 7 + pNdefRecord[1] + (pNdefRecord[2]<<24) + (pNdefRecord[3]<<16) + (pNdefRecord[4]<<8) + pNdefRecord[5] + pNdefRecord[6]);
else
temp = (pNdefRecord + 6 + pNdefRecord[1] + (pNdefRecord[2]<<24) + (pNdefRecord[3]<<16) + (pNdefRecord[4]<<8) + pNdefRecord[5]);
}
}
return temp;
}
This diff is collapsed.
......@@ -457,7 +457,7 @@ PairingManager::pairingLinkTypeStrings()
static QStringList list;
int i = 0;
if (!list.size()) {
#if defined QGC_ENABLE_NFC || defined QGC_ENABLE_QTNFC
#if defined QGC_ENABLE_QTNFC
list += tr("NFC");
_nfcIndex = i++;
#endif
......@@ -501,14 +501,14 @@ PairingManager::startMicrohardPairing()
void
PairingManager::stopPairing()
{
#if defined QGC_ENABLE_NFC || defined QGC_ENABLE_QTNFC
#if defined QGC_ENABLE_QTNFC
pairingNFC.stop();
#endif
_stopUpload();
setPairingStatus(PairingIdle, "");
}
#if defined QGC_ENABLE_NFC || defined QGC_ENABLE_QTNFC
#if defined QGC_ENABLE_QTNFC
//-----------------------------------------------------------------------------
void
PairingManager::startNFCScan()
......
......@@ -20,9 +20,6 @@
#include "QGCToolbox.h"
#include "QGCLoggingCategory.h"
#include "Fact.h"
#if defined QGC_ENABLE_NFC
#include "PairingNFC.h"
#endif
#if defined QGC_ENABLE_QTNFC
#include "QtNFC.h"
#endif
......@@ -79,7 +76,7 @@ public:
Q_INVOKABLE void connectToPairedDevice (QString name);
Q_INVOKABLE void removePairedDevice (QString name);
#if defined QGC_ENABLE_NFC || defined QGC_ENABLE_QTNFC
#if defined defined QGC_ENABLE_QTNFC
Q_INVOKABLE void startNFCScan();
#endif
#if QGC_GST_MICROHARD_ENABLED
......@@ -150,7 +147,7 @@ private:
QString _pairingCacheFile (QString uavName);
void _updatePairedDeviceNameList ();
#if defined QGC_ENABLE_NFC || defined QGC_ENABLE_QTNFC
#if defined QGC_ENABLE_QTNFC
PairingNFC pairingNFC;
#endif
};
/****************************************************************************
*
* (c) 2019 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#include "PairingManager.h"
#include "PairingNFC.h"
#include "QGCApplication.h"
#include <QSoundEffect>
QGC_LOGGING_CATEGORY(PairingNFCLog, "PairingNFCLog")
extern "C" {
#include <TML/inc/tool.h>
#include <NfcTask/inc/ndef_helper.h>
//-----------------------------------------------------------------------------
void logmsg(char *buf)
{
QString s = buf;
s.replace("\n", "");
qCDebug(PairingNFCLog) << s;
}
//-----------------------------------------------------------------------------
void NdefPull_Cb(unsigned char *pNdefMessage, unsigned short NdefMessageSize)
{
Q_UNUSED(NdefMessageSize);
unsigned char *pNdefRecord = pNdefMessage;
NdefRecord_t NdefRecord;
unsigned char save;
if (!pNdefMessage)
{
qCDebug(PairingNFCLog) << "Issue during NDEF message reception (check provisioned buffer size)";
return;
}
QSoundEffect _nfcSound;
_nfcSound.setSource(QUrl::fromUserInput("qrc:/auterion/wav/beep.wav"));
_nfcSound.setVolume(0.9);
_nfcSound.play();
while (pNdefRecord)
{
qCDebug(PairingNFCLog) << "NDEF record received";
NdefRecord = DetectNdefRecordType(pNdefRecord);
switch(NdefRecord.recordType)
{
case MEDIA_VCARD:
save = NdefRecord.recordPayload[NdefRecord.recordPayloadSize];
NdefRecord.recordPayload[NdefRecord.recordPayloadSize] = '\0';
qCDebug(PairingNFCLog) << " vCard: " << reinterpret_cast<char *>(NdefRecord.recordPayload);
NdefRecord.recordPayload[NdefRecord.recordPayloadSize] = save;
break;
case WELL_KNOWN_SIMPLE_TEXT:
{
save = NdefRecord.recordPayload[NdefRecord.recordPayloadSize];
NdefRecord.recordPayload[NdefRecord.recordPayloadSize] = '\0';
QString text = reinterpret_cast<char *>(&NdefRecord.recordPayload[NdefRecord.recordPayload[0]+1]);
qCDebug(PairingNFCLog) << " Text: " << text;
qgcApp()->toolbox()->pairingManager()->jsonReceived(text);
NdefRecord.recordPayload[NdefRecord.recordPayloadSize] = save;
break;
}
default:
qCDebug(PairingNFCLog) << " Unsupported NDEF record, cannot parse";
break;
}
pNdefRecord = GetNextRecord(pNdefRecord);
}
}
//-----------------------------------------------------------------------------
}
// Discovery loop configuration according to the targeted modes of operation
static unsigned char discoveryTechnologies[] = {
MODE_POLL | TECH_PASSIVE_NFCA,
MODE_POLL | TECH_PASSIVE_NFCF,
MODE_POLL | TECH_PASSIVE_NFCB,
MODE_POLL | TECH_PASSIVE_15693,
};
//-----------------------------------------------------------------------------
PairingNFC::PairingNFC()
{
}
//-----------------------------------------------------------------------------
void PairingNFC::start()
{
if (!isRunning()) {
_exitThread = false;
QThread::start();
}
}
//-----------------------------------------------------------------------------
void PairingNFC::stop()
{
if (isRunning()) {
_exitThread = true;
}
}
//-----------------------------------------------------------------------------
void PairingNFC::run()
{
NxpNci_RfIntf_t RfInterface;
// Register callback for reception of NDEF message from remote cards
RW_NDEF_RegisterPullCallback(reinterpret_cast<void*>(*NdefPull_Cb));
// Open connection to NXPNCI device
if (NxpNci_Connect() == NFC_ERROR) {
qCDebug(PairingNFCLog) << "Error: cannot connect to NXPNCI device";
return;
}
if (NxpNci_ConfigureSettings() == NFC_ERROR) {
qCDebug(PairingNFCLog) << "Error: cannot configure NXPNCI settings";
return;
}
if (NxpNci_ConfigureMode(NXPNCI_MODE_RW) == NFC_ERROR)
{
qCDebug(PairingNFCLog) << "Error: cannot configure NXPNCI";
return;
}
// Start Discovery
if (NxpNci_StartDiscovery(discoveryTechnologies,sizeof(discoveryTechnologies)) != NFC_SUCCESS)
{
qCDebug(PairingNFCLog) << "Error: cannot start discovery";
return;
}
while(!_exitThread)
{
qCDebug(PairingNFCLog) << "Waiting for NFC connection";
qgcApp()->toolbox()->pairingManager()->setStatusMessage(PairingManager::PairingActive, tr("Waiting for NFC connection"));
// Wait until a peer is discovered
while(NxpNci_WaitForDiscoveryNotification(&RfInterface) != NFC_SUCCESS);
if ((RfInterface.ModeTech & MODE_MASK) == MODE_POLL)
{
task_nfc_reader(RfInterface);
}
else
{
qCDebug(PairingNFCLog) << "Wrong discovery";
}
}
qgcApp()->toolbox()->pairingManager()->setStatusMessage(PairingManager::PairingIdle, "");
qCDebug(PairingNFCLog) << "NFC: Stop";
}
//-----------------------------------------------------------------------------
void PairingNFC::task_nfc_reader(NxpNci_RfIntf_t RfIntf)
{
qgcApp()->toolbox()->pairingManager()->setStatusMessage(PairingManager::PairingActive, tr("Device detected"));
qCDebug(PairingNFCLog) << "NFC: Device detected";
// For each discovered cards
while(!_exitThread) {
// What's the detected card type ?
switch(RfIntf.Protocol) {
case PROT_T1T:
case PROT_T2T:
case PROT_T3T:
case PROT_ISODEP:
// Process NDEF message read
NxpNci_ProcessReaderMode(RfIntf, READ_NDEF);
break;
case PROT_ISO15693:
break;
case PROT_MIFARE:
break;
default:
break;
}
// If more cards (or multi-protocol card) were discovered (only same technology are supported) select next one
if (RfIntf.MoreTags) {
if (NxpNci_ReaderActivateNext(&RfIntf) == NFC_ERROR)
break;
}
// Otherwise leave
else
break;
}
// Wait for card removal
NxpNci_ProcessReaderMode(RfIntf, PRESENCE_CHECK);
qgcApp()->toolbox()->pairingManager()->setStatusMessage(PairingManager::PairingActive, tr("Device removed"));
qCDebug(PairingNFCLog) << "NFC device removed";
// Restart discovery loop
NxpNci_StopDiscovery();
NxpNci_StartDiscovery(discoveryTechnologies, sizeof(discoveryTechnologies));
}
//-----------------------------------------------------------------------------
/****************************************************************************
*
* (c) 2019 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#pragma once
#include <QObject>
#include <QThread>
#include "QGCLoggingCategory.h"
extern "C" {
#include <NfcLibrary/inc/Nfc.h>
}
Q_DECLARE_LOGGING_CATEGORY(PairingNFCLog)
class PairingNFC : public QThread
{
Q_OBJECT
public:
PairingNFC();
virtual void start();
virtual void stop();
signals:
void parsePairingJson(QString json);
private:
bool _exitThread = false; ///< true: signal thread to exit
// Override from QThread
virtual void run(void);
void task_nfc_reader(NxpNci_RfIntf_t RfIntf);
};
/**************************************************************************
* Copyright (C) 2015 Eff'Innov Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Developped by Eff'Innov Technologies : contact@effinnov.com
*
**************************************************************************/
#ifndef FRAMEWORK_ALLOCATOR_H
#define FRAMEWORK_ALLOCATOR_H
#include <stddef.h>
void* framework_AllocMem(size_t size);
void framework_FreeMem(void *ptr);
#endif //ndef FRAMEWORK_ALLOCATOR_H
/**************************************************************************
* Copyright (C) 2015 Eff'Innov Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Developped by Eff'Innov Technologies : contact@effinnov.com
*
**************************************************************************/
#ifndef FRAMEWORK_CONTAINER_H
#define FRAMEWORK_CONTAINER_H
#include "TML/inc/framework_Interface.h"
typedef enum CONTAINER_STATUS
{
CONTAINER_SUCCESS,
CONTAINER_FAILED,
CONTAINER_INVALID_PARAM,
CONTAINER_INVALID_CONTAINER
}CONTAINER_STATUS;
CONTAINER_STATUS container_create(void** lContainer, uint32_t size);
CONTAINER_STATUS container_delete(void* lContainer);
CONTAINER_STATUS container_add(void* pContainer, void* _ptr);
CONTAINER_STATUS container_set(void* pContainer, uint32_t index,void*_ptr, void** _old);
CONTAINER_STATUS container_remove(void* pContainer, uint32_t index, void** _old);
CONTAINER_STATUS container_get(void* pContainer, uint32_t index, void** _out);
CONTAINER_STATUS container_size(void* pContainer, uint32_t* size);
CONTAINER_STATUS container_clear(void* pContainer);
CONTAINER_STATUS container_flushMallocedContent(void* pContainer);
CONTAINER_STATUS container_removePtr(void* pContainer, void* ref, void** out);
#endif /* FRAMEWORK_CONTAINER_H*/
/**************************************************************************
* Copyright (C) 2015 Eff'Innov Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Developped by Eff'Innov Technologies : contact@effinnov.com
*
**************************************************************************/
#ifndef FRAMEWORK_INTERFACE_H
#define FRAMEWORK_INTERFACE_H
//typedef unsigned long long uint64_t;
#include <stdint.h>
typedef enum _eResult
{
FRAMEWORK_SUCCESS,
FRAMEWORK_FAILED
}eResult;
/**
* Create a thread using the given function in parameters
* @param threadHandle Obfuscated thread handle allocated by this function.
* @param threadedFunc function to start in new thread. ( void* myFunc(void* ctx) )
* @param ctx Parameters given to threadedFunc.
* @return SUCCESS if no error.
*/
eResult framework_CreateThread(void** threadHandle,void *(*threadedFunc)(void*),void *ctx);
/**
* Wait until the given thread finish to run.
* @param threadHandle Obfuscated thread handle allocated by framework_CreateThread()
*/
void framework_JoinThread(void* threadHandle);
/**
* Delete the given thread. NOTE : framework_JoinThread() will be called before this function. So
* the Thread is already stopped.
* @param threadHandle Obfuscated thread handle allocated by framework_CreateThread()
*/
void framework_DeleteThread(void* threadHandle);
/**
* Return the calling thread ID.
* @return thread id.
*/
void* framework_GetCurrentThreadId();
/**
* Get the thread id of the given thread handle.
* @param threadHandle Obfuscated thread handle allocated by framework_CreateThread()
* @return thread id.
*/
void* framework_GetThreadId(void* threadHandle);
/**
* Create a mutex object. To gain performances, do not implement this function using interprocess
* lock mechanism such as Semaphore.
* @param mutexHandle Obfuscated mutex handle allocated by this function.
* @return SUCCESS if no error.
*/
eResult framework_CreateMutex(void** mutexHandle);
/**
* Lock the mutex.
* @param mutexHandle Obfuscated mutex handle allocated by framework_CreateMutex().
*/
void framework_LockMutex(void* mutexHandle);
/**
* Unlock the mutex
* @param mutexHandle Obfuscated mutex handle allocated by framework_CreateMutex().
*/
void framework_UnlockMutex(void* mutexHandle);
/**
* Block the current thread until wake up by framework_NotifyMutex().
* The mutex need to be locked before blocking the thread. (needLock parameter can be used)
* @param mutexHandle Obfuscated mutex handle allocated by framework_CreateMutex().
* @param needLock Indicate if the mutex need to be locked internaly or not. This avoid to call lock();wait();unlock();
*/
void framework_WaitMutex(void* mutexHandle,uint8_t needLock);
/**
* Wake up a thread blocked by the mutex. The mutex must be locked before waking up another thread.
* The mutex need to be locked before waking up a thread. (needLock parameter can be used)
* @param mutexHandle Obfuscated mutex handle allocated by framework_CreateMutex().
* @param needLock Indicate if the mutex need to be locked internaly or not. This avoid to call lock();wait();unlock();
*/
void framework_NotifyMutex(void* mutexHandle,uint8_t needLock);
/**
* Delete the mutex. If the mutex is locked, any locked thread will be unlocked.
* @param mutexHandle Obfuscated mutex handle allocated by framework_CreateMutex().
*/
void framework_DeleteMutex(void* mutexHandle);
/**
* Cause the calling thread to sleep until ms milliseconds elapsed.
* @param ms Milliseconds to wait until wakeup.
*/
void framework_MilliSleep(uint32_t ms);
// **************************************** Generic/Portable function.
/**
* Create a Semaphore. This semaphore have a counter of 1.
* This implementation of Semaphore is supposed to be generic. It uses previous Mutex API.
* There is no need to reimplement it until you have a good reason.
* @param semaphoreHandle Obfuscated semaphore handle allocated by this function.
* @return
*/
eResult framework_CreateSemaphore(void** semaphoreHandle);
/**
* Wait semaphore. Block until a PostSemaphore get called.
* @param semaphoreHandle Obfuscated semaphore handle allocated by framework_CreateSemaphore();
*/
void framework_WaitSemaphore(void* semaphoreHandle);
/**
* Post semaphore. Unblock any waiting semaphore. If nobody wait for this semaphore, the next "waiter"
* will not be blocked.
* @param semaphoreHandle Obfuscated semaphore handle allocated by framework_CreateSemaphore();
*/
void framework_PostSemaphore(void* semaphoreHandle);
/**
* @param semaphoreHandle Obfuscated semaphore handle allocated by framework_CreateSemaphore();
*/
void framework_DeleteSemaphore(void* semaphoreHandle);
#endif // ndef FRAMEWORK_INTERFACE_H
/**************************************************************************
* Copyright (C) 2015 Eff'Innov Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Developped by Eff'Innov Technologies : contact@effinnov.com
*
**************************************************************************/
#ifndef MAP_H
#define MAP_H
typedef enum STATUS
{
SUCCESS,
FAILED,
NOT_FOUND,
INVALID_MAP,
INVALID_PARAM,
ALREADY_EXISTS
}STATUS;
STATUS map_create(void ** map);
STATUS map_destroy(void* map);
STATUS map_add(void * map, void* id, void* object);
STATUS map_remove(void* map, void* id);
STATUS map_get(void* map, void* id, void ** object);
STATUS map_getAll(void* map, void ** elements, int * lenght);
#endif /*MAP_H*/
/**************************************************************************
* Copyright (C) 2015 Eff'Innov Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Developped by Eff'Innov Technologies : contact@effinnov.com
*
**************************************************************************/
#ifndef FRAMEWORK_PARCEL_H
#define FRAMEWORK_PARCEL_H
#include "TML/inc/framework_Interface.h"
void framework_ParcelCreate(void **parcel);
void framework_ParcelDelete(void *parcel);
uint8_t framework_ParcelReadByte(void *parcel);
void framework_ParcelWriteByte(void *parcel,uint8_t i);
uint16_t framework_ParcelReadShort(void *parcel);
void framework_ParcelWriteShort(void *parcel,uint16_t i);
uint32_t framework_ParcelReadInt32(void *parcel);
void framework_ParcelWriteInt32(void *parcel,uint32_t i);
uint64_t framework_ParcelReadInt64(void *parcel);
void framework_ParcelWriteInt64(void *parcel,uint64_t i);
float framework_ParcelReadFloat(void *parcel);
void framework_ParcelWriteFloat(void *parcel,float f);
double framework_ParcelReadDouble(void *parcel);
void framework_ParcelWriteDouble(void *parcel,double d);
const char* framework_ParcelReadString(void *parcel);
void framework_ParcelWriteString(void *parcel,const char* s);
void framework_ParcelReadRaw(void *parcel,void* outBuffer, uint32_t len);
void framework_ParcelWriteRaw(void *parcel,const void* buffer, uint32_t len);
const uint8_t* framework_ParcelDataAtCurrentPosition(void *parcel);
uint32_t framework_ParcelGetRemainingDataSize(void *parcel);
const uint8_t *framework_ParcelGetData(void *parcel);
uint32_t framework_ParcelGetSize(void *parcel);
void framework_ParcelSetData(void *parcel,const uint8_t* data,uint32_t size);
void framework_ParcelRewind(void *parcel);
void framework_ParcelForward(void *parcel,uint32_t nbBytes);
void framework_ParcelClear(void *parcel);
void framework_ParcelSerialize(void *dstParcel,void *srcParcel);
void framework_ParcelDeserialize(void *dstParcel,void *srcParcel);
#endif // ndef FRAMEWORK_PARCEL_H
/**************************************************************************
* Copyright (C) 2015 Eff'Innov Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Developped by Eff'Innov Technologies : contact@effinnov.com
*
**************************************************************************/
#ifndef FRAMEWORK_TIMER_H
#define FRAMEWORK_TIMER_H
#include "TML/inc/framework_Interface.h"
typedef void (framework_TimerCallBack)(void*);
void framework_TimerCreate(void **timer);
void framework_TimerStart(void *timer,uint32_t delay,framework_TimerCallBack *cb,void *usercontext);
void framework_TimerStop(void *timer);
void framework_TimerDelete(void *timer);
#endif // ndef FRAMEWORK_TIMER_H
/**************************************************************************
* Copyright (C) 2015 Eff'Innov Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Developped by Eff'Innov Technologies : contact@effinnov.com
*
**************************************************************************/
#include "TML/inc/framework_Interface.h"
#include <stdlib.h>
/**
* Internal function, log a buffer to log output as Hexadecimal + ASCII display.
* @param buffer
* @param size
*/
void HexDump(const void * buffer, uint32_t size);
void framework_Error(const char* format, ...);
This diff is collapsed.
This diff is collapsed.
/*
* @brief Protocol definitions for LPCUSBSIO's I2C interface
*
* @note
* Copyright(C) NXP Semiconductors, 2013
* All rights reserved.
*
* @par
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* LPC products. This software is supplied "AS IS" without any warranties of
* any kind, and NXP Semiconductors and its licensor disclaim any and
* all warranties, express or implied, including all implied warranties of
* merchantability, fitness for a particular purpose and non-infringement of
* intellectual property rights. NXP Semiconductors assumes no responsibility
* or liability for the use of the software, conveys no license or rights under any
* patent, copyright, mask work right, or any other intellectual property rights in
* or to any products. NXP Semiconductors reserves the right to make changes
* in the software without notification. NXP Semiconductors also makes no
* representation or warranty that such application will be suitable for the
* specified use without further testing or modification.
*
* @par
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, under NXP Semiconductors' and its
* licensor's relevant copyrights in the software, without fee, provided that it
* is used in conjunction with NXP Semiconductors microcontrollers. This
* copyright, permission, and disclaimer notice must appear in all copies of
* this code.
*/
#ifndef __LPCUSBSIO_I2C_H_
#define __LPCUSBSIO_I2C_H_
#ifdef __cplusplus
extern "C"
{
#endif
#pragma pack(1)
/** @defgroup LPCUSBSIO_I2C LPCUSBSIO protocol definitions for I2C interface
* @ingroup LPCUSBSIO
* This package defines the LPCUSBSIO packet structure for I2C interface.
* Both the firmware and PC (host) libraries use this definitions to construct
* the I2C payloads.
* @{
*/
#define HID_I2C_MAX_PACKETS 4 /*!< Maximum packets allowed in processing queue */
#define HID_I2C_PACKET_SZ 64 /*!< Packet size of each I2C command packet */
#define HID_I2C_HEADER_SZ 5 /*!< Size of the header in I2C command packet */
/* HID_I2C Requests */
#define HID_I2C_REQ_RESET 0 /*!< Request to abort and flush all pending requests */
#define HID_I2C_REQ_INIT_PORT 1 /*!< Request to initialize the I2C port */
#define HID_I2C_REQ_DEINIT_PORT 2 /*!< Request to de-initialize the I2C port */
#define HID_I2C_REQ_DEVICE_WRITE 3 /*!< Request to write data to the I2C port */
#define HID_I2C_REQ_DEVICE_READ 4 /*!< Request to read data from the I2C port */
#define HID_I2C_REQ_DEVICE_XFER 5 /*!< Request to write and then read data from the I2C port */
/*AL ! Add GPIO Requests */
#define HID_GPIO_REQ_SET_VEN 6 /*!< Request to set the VEN GPIO State*/
#define HID_GPIO_REQ_SET_DWL 7 /*!< Request to set the DWL GPIO State*/
/**
* @brief HID to I2C bridge Request structure.
* Defines the structure of HID to I2C Request packet. This is same as
* HID OUT report.
*/
typedef struct __HIDI2C_OUT_REPORT {
uint16_t length; /*!< Length of the HID_I2C Request structure including cmd, transId and length fields. */
uint8_t transId; /*!< I2C_HID transaction identifier. Rolls over after 255. */
uint8_t sesId; /*!< I2C_HID session identifier. */
uint8_t req; /*!< I2C_HID Request */
uint8_t data[]; /*!< Data corresponding to the Request */
} HID_I2C_OUT_REPORT_T;
/** HID_I2C responses. The response code below 0x10 should match with I2CM_STATUS codes. */
#define HID_I2C_RES_OK 0x00 /*!< Requested Request was executed successfully. */
#define HID_I2C_RES_ERROR 0x01 /*!< Unknown error condition. */
#define HID_I2C_RES_NAK 0x02 /*!< No device responded for given slave address. */
#define HID_I2C_RES_BUS_ERROR 0x03 /*!< I2C bus error */
#define HID_I2C_RES_SLAVE_NAK 0x04 /*!< NAK received after SLA+W or SLA+R */
#define HID_I2C_RES_ARBLOST 0x05 /*!< Arbitration lost */
#define HID_I2C_RES_TIMEOUT 0x10 /*!< Transaction timed out. */
#define HID_I2C_RES_INVALID_CMD 0x11 /*!< Invalid HID_I2C Request or Request not supported in this version. */
#define HID_I2C_RES_INVALID_PARAM 0x12 /*!< Invalid parameters are provided for the given Request. */
#define HID_I2C_RES_PARTIAL_DATA 0x13 /*!< Partial transfer completed. */
/**
* @brief HID to I2C bridge response structure.
* Defines the structure of HID to I2C Request packet. This is same as
* HID OUT report.
*/
typedef struct __HIDI2C_IN_REPORT {
uint16_t length; /*!< Length of the HID_I2C response structure including resp, transId and length fields.*/
uint8_t transId; /*!< I2C_HID transaction identifier. */
uint8_t sesId; /*!< I2C_HID session identifier. */
uint8_t resp; /*!< I2C_HID reponse */
uint8_t data[]; /*!< Data corresponding to the response */
} HID_I2C_IN_REPORT_T;
/**
* @brief Port configuration information
*/
typedef struct __HIDI2C_PortConfig_t {
uint32_t busSpeed; /*!< I2C bus speed */
uint32_t Options; /*!< Configuration options */
} HID_I2C_PORTCONFIG_T;
/** I2C_IO_OPTIONS Options to I2C_DeviceWrite & I2C_DeviceRead routines
* @{
*/
/** Generate start condition before transmitting */
#define HID_I2C_TRANSFER_OPTIONS_START_BIT 0x0001
/** Generate stop condition at the end of transfer */
#define HID_I2C_TRANSFER_OPTIONS_STOP_BIT 0x0002
/** Continue transmitting data in bulk without caring about Ack or nAck from device if this bit is
not set. If this bit is set then stop transmitting the data in the buffer when the device nAcks*/
#define HID_I2C_TRANSFER_OPTIONS_BREAK_ON_NACK 0x0004
/** lpcusbsio-I2C generates an ACKs for every byte read. Some I2C slaves require the I2C
master to generate a nACK for the last data byte read. Setting this bit enables working with such
I2C slaves */
#define HID_I2C_TRANSFER_OPTIONS_NACK_LAST_BYTE 0x0008
/* Setting this bit would mean that the address field should be ignored.
The address is either a part of the data or this is a special I2C
frame that doesn't require an address. For example when transferring a
frame greater than the USB_HID packet this option can be used. */
#define HID_I2C_TRANSFER_OPTIONS_NO_ADDRESS 0x00000040
/** @} */
/**
* @brief HID to I2C bridge read and write transfer parameters structure.
* Defines the structure of HID to I2C read-write transfer parameters.
*/
typedef struct __HIDI2C_RW_PARAMS {
uint16_t length; /*!< Length of the transfer.*/
uint8_t options; /*!< check @ref I2C_IO_OPTIONS. */
uint8_t slaveAddr; /*!< I2C slave device address. */
uint8_t data[]; /*!< Data corresponding to the response */
} HID_I2C_RW_PARAMS_T;
/** I2C_FAST_XFER_OPTIONS I2C master faster transfer options
* @{
*/
/** Ignore NACK during data transfer. By default transfer is aborted. */
#define I2C_FAST_XFER_OPTION_IGNORE_NACK 0x01
/** ACK last byte received. By default we NACK last byte we receive per I2C spec. */
#define I2C_FAST_XFER_OPTION_LAST_RX_ACK 0x02
/**
* @}
*/
/**
* @brief HID to I2C bridge fast transfer parameters structure.
* Defines the parameters structure for HID_I2C_REQ_DEVICE_XFER command.
*/
typedef struct __HIDI2C_XFER_PARAMS {
uint8_t txLength; /*!< Length of the Tx transfer.*/
uint8_t rxLength; /*!< Length of the Rx transfer. */
uint8_t options; /*!< check @ref I2C_FAST_XFER_OPTIONS. */
uint8_t slaveAddr; /*!< I2C slave device address. */
uint8_t data[]; /*!< Data corresponding to the response */
} HID_I2C_XFER_PARAMS_T;
/**
* @}
*/
#pragma pack()
#ifdef __cplusplus
}
#endif
#endif /* __LPCUSBSIO_I2C_H_ */
/*
* 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 TIMEOUT_INFINITE 0
#define TIMEOUT_100MS 100
#define TIMEOUT_1S 1000
#define TIMEOUT_1200MS 1200
#define TIMEOUT_2S 2000
void tml_Connect(void);
void tml_Disconnect(void);
void tml_Send(uint8_t *pBuffer, uint16_t BufferLen, uint16_t *pBytesSent);
void tml_Receive(uint8_t *pBuffer, uint16_t BufferLen, uint16_t *pBytes, uint16_t timeout);
/*
* 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.
*/
int tml_hid_Connect(void);
void tml_hid_Disconnect(void);
void tml_hid_Send(uint8_t *pBuffer, uint16_t BufferLen, uint16_t *pBytesSent);
void tml_hid_Receive(uint8_t *pBuffer, uint16_t BufferLen, uint16_t *pBytes, uint16_t timeout);
void tml_hid_Cancel(void);
/*
* 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 <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <unistd.h>
#define Sleep(x) usleep(1000*x)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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.
*/
#include <stdint.h>
#include <TML/inc/tml_hid.h>
void tml_Connect(void) {
tml_hid_Connect();
}
void tml_Disconnect(void) {
tml_hid_Disconnect();
}
void tml_Send(uint8_t *pBuffer, uint16_t BufferLen, uint16_t *pBytesSent) {
tml_hid_Send(pBuffer, BufferLen, pBytesSent);
}
void tml_Receive(uint8_t *pBuffer, uint16_t BufferLen, uint16_t *pBytes,
uint16_t timeout) {
tml_hid_Receive(pBuffer, BufferLen, pBytes, timeout);
}
This diff is collapsed.
Markdown is supported
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