-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0a3f950
Showing
13 changed files
with
687 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
LOCAL_PATH := $(call my-dir) | ||
include $(CLEAR_VARS) | ||
LOCAL_MODULE := NfcFactoryTestApp | ||
LOCAL_SRC_FILES := NfcFactoryTestApp.c | ||
include $(BUILD_EXECUTABLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <sys/ioctl.h> | ||
|
||
#if 0 | ||
#define PRINT_BUF(x,y,z) {int loop; printf(x); \ | ||
for(loop=0;loop<z;loop++) printf("%.2x ", y[loop]); \ | ||
printf("\n");} | ||
#else | ||
#define PRINT_BUF(x,y,z) | ||
#endif | ||
|
||
static char gNfcController_generation = 0; | ||
|
||
static int openNfc(int * handle) | ||
{ | ||
*handle = open((char const *)"/dev/pn544", O_RDWR); | ||
if (*handle < 0) return -1; | ||
return 0; | ||
} | ||
|
||
static void closeNfc(int handle) | ||
{ | ||
close(handle); | ||
} | ||
|
||
static void reset(int handle) | ||
{ | ||
ioctl(handle, _IOW(0xE9, 0x01, unsigned long), 0); | ||
usleep(10 * 1000); | ||
ioctl(handle, _IOW(0xE9, 0x01, unsigned long), 1); | ||
} | ||
|
||
static int send(int handle, char *pBuff, int buffLen) | ||
{ | ||
int ret = write(handle, pBuff, buffLen); | ||
if(ret <= 0) { | ||
/* retry to handle standby mode */ | ||
ret = write(handle, pBuff, buffLen); | ||
if(ret <= 0) return 0; | ||
} | ||
PRINT_BUF(">> ", pBuff, ret); | ||
return ret; | ||
} | ||
|
||
static int receive(int handle, char *pBuff, int buffLen) | ||
{ | ||
int numRead; | ||
struct timeval tv; | ||
fd_set rfds; | ||
int ret; | ||
|
||
FD_ZERO(&rfds); | ||
FD_SET(handle, &rfds); | ||
tv.tv_sec = 2; | ||
tv.tv_usec = 1; | ||
ret = select(handle+1, &rfds, NULL, NULL, &tv); | ||
if(ret <= 0) return 0; | ||
|
||
ret = read(handle, pBuff, 3); | ||
if (ret <= 0) return 0; | ||
numRead = 3; | ||
if(pBuff[2] + 3 > buffLen) return 0; | ||
|
||
ret = read(handle, &pBuff[3], pBuff[2]); | ||
if (ret <= 0) return 0; | ||
numRead += ret; | ||
|
||
PRINT_BUF("<< ", pBuff, numRead); | ||
|
||
return numRead; | ||
} | ||
|
||
static int transceive(int handle, char *pTx, int TxLen, char *pRx, int RxLen) | ||
{ | ||
if(send(handle, pTx, TxLen) == 0) return 0; | ||
return receive(handle, pRx, RxLen); | ||
} | ||
|
||
static void RfOn (int handle) | ||
{ | ||
char NCIStartDiscovery[] = {0x21, 0x03, 0x09, 0x04, 0x00, 0x01, 0x01, 0x01, 0x02, 0x01, 0x06, 0x01}; | ||
char NCIRfOn[] = {0x2F, 0x3D, 0x02, 0x20, 0x01}; | ||
char Answer[256]; | ||
int NbBytes = 0; | ||
|
||
if (gNfcController_generation == 1) { | ||
printf("Continuous RF ON test - please tap a card\n"); | ||
NbBytes = transceive(handle, NCIStartDiscovery, sizeof(NCIStartDiscovery), Answer, sizeof(Answer)); | ||
if((Answer[0] != 0x41) || (Answer[1] != 0x03) || (Answer[3] != 0x00)) { | ||
printf("Cannot start discovery loop\n"); | ||
return; | ||
} | ||
do { | ||
NbBytes = receive(handle, Answer, sizeof(Answer)); | ||
} while ((Answer[0] != 0x61) || ((Answer[1] != 0x05) && (Answer[1] != 0x03))); | ||
} | ||
else { | ||
printf("Continuous RF ON test\n"); | ||
NbBytes = transceive(handle, NCIRfOn, sizeof(NCIRfOn), Answer, sizeof(Answer)); | ||
} | ||
printf("NFC Controller is now in continuous RF ON mode - Press enter to stop\n"); | ||
fgets(Answer, sizeof(Answer), stdin); | ||
} | ||
|
||
static void Prbs (int handle) | ||
{ | ||
char NCIPrbsPN7120[] = {0x2F, 0x30, 0x04, 0x00, 0x00, 0x01, 0x01}; | ||
char NCIPrbsPN7150[] = {0x2F, 0x30, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}; | ||
char Answer[256]; | ||
int NbBytes = 0; | ||
int tech, bitrate; | ||
|
||
printf("PRBS test:\n"); | ||
printf(" Select technology (A=0, B=1, F=2: "); | ||
scanf("%d", &tech); | ||
printf(" Select bitrate (106=0, 212=1, 424=2, 848=3: "); | ||
scanf("%d", &bitrate); | ||
|
||
if (gNfcController_generation == 1) { | ||
NCIPrbsPN7120[3] = tech; | ||
NCIPrbsPN7120[4] = bitrate; | ||
NbBytes = transceive(handle, NCIPrbsPN7120, sizeof(NCIPrbsPN7120), Answer, sizeof(Answer)); | ||
} | ||
else { | ||
NCIPrbsPN7150[5] = tech; | ||
NCIPrbsPN7150[6] = bitrate; | ||
NbBytes = transceive(handle, NCIPrbsPN7150, sizeof(NCIPrbsPN7150), Answer, sizeof(Answer)); | ||
} | ||
printf("NFC Controller is now in PRBS mode - Press enter to stop\n"); | ||
fgets(Answer, sizeof(Answer), stdin); | ||
} | ||
|
||
int main() | ||
{ | ||
int nHandle; | ||
char NCICoreReset[] = {0x20, 0x00, 0x01, 0x01}; | ||
char NCICoreInit[] = {0x20, 0x01, 0x00}; | ||
char NCIDisableStandby[] = {0x2F, 0x00, 0x01, 0x00}; | ||
char Answer[256]; | ||
int NbBytes = 0; | ||
|
||
printf("\n----------------------------\n"); | ||
printf("NFC Factory Test Application\n"); | ||
printf("----------------------------\n"); | ||
|
||
if(openNfc(&nHandle) != 0) { | ||
printf("Cannot connect to PN71xx NFC controller\n"); | ||
return -1; | ||
} | ||
|
||
reset(nHandle); | ||
|
||
NbBytes = transceive(nHandle, NCICoreReset, sizeof(NCICoreReset), Answer, sizeof(Answer)); | ||
NbBytes = transceive(nHandle, NCICoreInit, sizeof(NCICoreInit), Answer, sizeof(Answer)); | ||
if((NbBytes < 19) || (Answer[0] != 0x40) || (Answer[1] != 0x01) || (Answer[3] != 0x00)) { | ||
printf("Error communicating with PN71xx NFC Controller\n"); | ||
return -1; | ||
} | ||
/* Retrieve NXP-NCI NFC Controller generation */ | ||
if (Answer[17+Answer[8]] == 0x08) { | ||
printf("PN7120 NFC controller detected\n"); | ||
gNfcController_generation = 1; | ||
} | ||
else if (Answer[17+Answer[8]] == 0x10) { | ||
printf("PN7150 NFC controller detected\n"); | ||
gNfcController_generation = 2; | ||
} | ||
else { | ||
printf("Wrong NFC controller detected\n"); | ||
return -1; | ||
} | ||
|
||
NbBytes = transceive(nHandle, NCIDisableStandby, sizeof(NCIDisableStandby), Answer, sizeof(Answer)); | ||
|
||
printf("Select the test to run:\n"); | ||
printf("\t 1. Continuous RF ON\n"); | ||
printf("\t 2. PRBS\n"); | ||
printf("Your choice: "); | ||
scanf("%d", &NbBytes); | ||
|
||
switch(NbBytes) { | ||
case 1: RfOn(nHandle); break; | ||
case 2: Prbs(nHandle); break; | ||
default: printf("Wrong choice\n"); break; | ||
} | ||
|
||
fgets(Answer, sizeof(Answer), stdin); | ||
|
||
reset(nHandle); | ||
closeNfc(nHandle); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# nxpnfc_android_nougat | ||
|
||
This repository contains the files allowing to patch 8.1.0 Oreo version of AOSP source in order to add support for PN7150 NXP-NCI NFC controller to an Android based system. | ||
It only applies to Oreo Android versions (for other releases see appropriate repository: https://wiki.codeaurora.org/xwiki/bin/NCI+NFC+Controller+SW+resources/). | ||
|
||
Information about NXP NFC Controller can be found on [NXP website](http://www.nxp.com/products/identification_and_security/nfc_and_reader_ics/nfc_controller_solutions/#overview). | ||
|
||
Further details about the stack and integration guidelines [here](https://www.nxp.com/docs/en/application-note/AN11690.pdf). | ||
|
||
Any question ? see [NXP Community](https://community.nxp.com/community/identification-security/nfc/content). | ||
|
||
Release version | ||
--------------- | ||
* R1.0: Initial release based on NFC_NCIHALx_AR0054.8.3.0_O_OpnSrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
########################### PN7150 libnfc-brcm.conf ########################### | ||
|
||
############################################################################### | ||
# Log levels for libnfc-nci. Suggested value for debugging is 0xFF. | ||
APPL_TRACE_LEVEL=0xFF | ||
PROTOCOL_TRACE_LEVEL=0xFF | ||
|
||
############################################################################### | ||
# File used for NFA storage | ||
NFA_STORAGE="/data/vendor/nfc" | ||
|
||
############################################################################### | ||
# Forcing HOST to listen for a selected protocol | ||
# 0x00 : Disable Host Listen | ||
# 0x01 : Enable Host to Listen (A) for ISO-DEP tech A | ||
# 0x02 : Enable Host to Listen (B) for ISO-DEP tech B | ||
# 0x04 : Enable Host to Listen (F) for T3T Tag Type Protocol tech F | ||
# 0x07 : Enable Host to Listen (ABF)for ISO-DEP tech AB & T3T Tag Type Protocol tech F | ||
HOST_LISTEN_TECH_MASK=0x07 | ||
|
||
############################################################################### | ||
# When screen is turned off, specify the desired power state of the controller. | ||
# 0: power-off-sleep state; DEFAULT | ||
# 1: full-power state | ||
# 2: screen-off card-emulation (CE4/CE3/CE1 modes are used) | ||
SCREEN_OFF_POWER_STATE=1 | ||
|
||
############################################################################### | ||
# Choose the presence-check algorithm for type-4 tag. If not defined, the default value is 1. | ||
# 0 NFA_RW_PRES_CHK_DEFAULT; Let stack selects an algorithm | ||
# 1 NFA_RW_PRES_CHK_I_BLOCK; ISO-DEP protocol's empty I-block | ||
# 2 NFA_RW_PRES_CHK_RESET; Deactivate to Sleep, then re-activate | ||
# 3 NFA_RW_PRES_CHK_RB_CH0; Type-4 tag protocol's ReadBinary command on channel 0 | ||
# 4 NFA_RW_PRES_CHK_RB_CH3; Type-4 tag protocol's ReadBinary command on channel 3 | ||
PRESENCE_CHECK_ALGORITHM=1 | ||
|
||
############################################################################### | ||
# NCI Hal Module name | ||
NCI_HAL_MODULE="nfc_nci.pn54x" | ||
|
||
############################################################################### | ||
# Force tag polling for the following technology(s). | ||
# The bits are defined as tNFA_TECHNOLOGY_MASK in nfa_api.h. | ||
# Default is NFA_TECHNOLOGY_MASK_A | NFA_TECHNOLOGY_MASK_B | | ||
# NFA_TECHNOLOGY_MASK_F | NFA_TECHNOLOGY_MASK_ISO15693 | | ||
# NFA_TECHNOLOGY_MASK_KOVIO | NFA_TECHNOLOGY_MASK_A_ACTIVE | | ||
# NFA_TECHNOLOGY_MASK_F_ACTIVE | ||
# | ||
# Notable bits: | ||
# NFA_TECHNOLOGY_MASK_A 0x01 /* NFC Technology A */ | ||
# NFA_TECHNOLOGY_MASK_B 0x02 /* NFC Technology B */ | ||
# NFA_TECHNOLOGY_MASK_F 0x04 /* NFC Technology F */ | ||
# NFA_TECHNOLOGY_MASK_ISO15693 0x08 /* Proprietary Technology */ | ||
# NFA_TECHNOLOGY_MASK_KOVIO 0x20 /* Proprietary Technology */ | ||
# NFA_TECHNOLOGY_MASK_A_ACTIVE 0x40 /* NFC Technology A active mode */ | ||
# NFA_TECHNOLOGY_MASK_F_ACTIVE 0x80 /* NFC Technology F active mode */ | ||
# This flag when set to zero will disable Reader mode. | ||
POLLING_TECH_MASK=0xEF | ||
|
||
############################################################################### | ||
# Force P2P to only listen for the following technology(s). | ||
# The bits are defined as tNFA_TECHNOLOGY_MASK in nfa_api.h. | ||
# Default is NFA_TECHNOLOGY_MASK_A | NFA_TECHNOLOGY_MASK_F | | ||
# NFA_TECHNOLOGY_MASK_A_ACTIVE | NFA_TECHNOLOGY_MASK_F_ACTIVE | ||
# | ||
# Notable bits: | ||
# NFA_TECHNOLOGY_MASK_A 0x01 /* NFC Technology A */ | ||
# NFA_TECHNOLOGY_MASK_F 0x04 /* NFC Technology F */ | ||
# NFA_TECHNOLOGY_MASK_A_ACTIVE 0x40 /* NFC Technology A active mode */ | ||
# NFA_TECHNOLOGY_MASK_F_ACTIVE 0x80 /* NFC Technology F active mode */ | ||
# This flag when set to zero will disable P2P Listen mode. | ||
P2P_LISTEN_TECH_MASK=0xC5 | ||
|
||
############################################################################### | ||
# Override the stack default for NFA_EE_MAX_EE_SUPPORTED set in nfc_target.h. | ||
# The value is set to 3 by default as it assumes we will discover 0xF2, | ||
# 0xF3, and 0xF4. If a platform will exclude and SE, this value can be reduced | ||
# so that the stack will not wait any longer than necessary. | ||
# | ||
# For NXP PN7150 value must be fixed to 0x01 | ||
NFA_MAX_EE_SUPPORTED=0x01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
########################### PN7150 libnfc-nxp.conf ############################ | ||
|
||
############################################################################### | ||
# Logging Levels. Suggested value for debugging is 0x03. | ||
# NXPLOG_EXTNS_LOGLEVEL - Configuration for extns logging level | ||
# NXPLOG_NCIX_LOGLEVEL - Configuration for enabling logging of NCI TX packets | ||
# NXPLOG_NCIR_LOGLEVEL - Configuration for enabling logging of NCI RX packets | ||
# NXPLOG_FWDNLD_LOGLEVEL - Configuration for enabling logging of FW download functionality | ||
# NXPLOG_TML_LOGLEVEL - Configuration for enabling logging of TML | ||
# NXPLOG_NCIHAL_LOGLEVEL - Configuration for enabling logging of HAL | ||
NXPLOG_EXTNS_LOGLEVEL=0x03 | ||
NXPLOG_NCIX_LOGLEVEL=0x03 | ||
NXPLOG_NCIR_LOGLEVEL=0x03 | ||
NXPLOG_FWDNLD_LOGLEVEL=0x03 | ||
NXPLOG_TML_LOGLEVEL=0x03 | ||
NXPLOG_NCIHAL_LOGLEVEL=0x03 | ||
|
||
############################################################################### | ||
# Nfc Device Node name | ||
NXP_NFC_DEV_NODE="/dev/pn544" | ||
|
||
############################################################################### | ||
# Extension for Mifare reader enable | ||
MIFARE_READER_ENABLE=0x01 | ||
|
||
############################################################################### | ||
# System clock source selection configuration | ||
#define CLK_SRC_XTAL 0x01 | ||
#define CLK_SRC_PLL 0x02 | ||
NXP_SYS_CLK_SRC_SEL=0x01 | ||
|
||
############################################################################### | ||
# System clock frequency selection configuration. | ||
# Only valid in case of PLL clock source. | ||
#define CLK_FREQ_13MHZ 1 | ||
#define CLK_FREQ_19_2MHZ 2 | ||
#define CLK_FREQ_24MHZ 3 | ||
#define CLK_FREQ_26MHZ 4 | ||
#define CLK_FREQ_38_4MHZ 5 | ||
#define CLK_FREQ_52MHZ 6 | ||
NXP_SYS_CLK_FREQ_SEL=0x00 | ||
|
||
############################################################################### | ||
# The timeout value to be used for clock request acknowledgment | ||
# min value = 0x01 to max = 0x1A | ||
# Only valid in case of PLL clock source. | ||
NXP_SYS_CLOCK_TO_CFG=0x01 | ||
|
||
############################################################################### | ||
# NXP proprietary settings to enable NXP Proprietary features | ||
# | ||
# For NXP NFC Controller value must be fixed to {2F, 02, 00} | ||
NXP_ACT_PROP_EXTN={2F, 02, 00} | ||
|
||
############################################################################### | ||
# NFC forum profile settings. | ||
# For more details refer to the POLL_PROFILE_SEL_ CFG parameter definition from NFC Controller User Manual | ||
NXP_NFC_PROFILE_EXTN={20, 02, 05, 01, A0, 44, 01, 00} | ||
|
||
############################################################################### | ||
# Standby enable settings. (disable=2F 00 01 00, enable=2F 00 01 01) | ||
NXP_CORE_STANDBY={2F, 00, 01, 01} | ||
|
||
############################################################################### | ||
# TVDD configurations settings | ||
# Allow NFCC to configure External TVDD | ||
# There are two possible configurations (0x01 or 0x02): | ||
# CFG1: Vbat is used to generate the VDD(TX) through TXLDO | ||
# CFG2: external 5V is used to generate the VDD(TX) through TXLDO | ||
NXP_EXT_TVDD_CFG=0x02 | ||
|
||
# CFG1: 3.3V for both Reader and Card modes | ||
NXP_EXT_TVDD_CFG_1={20, 02, 07, 01, A0, 0E, 03, 02, 09, 00} | ||
|
||
# CFG2: VBAT2 to 5V and 4.7V for both Reader and Card modes | ||
NXP_EXT_TVDD_CFG_2={20, 02, 07, 01, A0, 0E, 03, 06, 64, 00} | ||
|
||
############################################################################### | ||
## Set configuration optimization decision setting | ||
## Enable = 0x01 | ||
## Disable = 0x00 | ||
NXP_SET_CONFIG_ALWAYS=0x00 | ||
|
||
############################################################################### | ||
# To enable i2c fragmentation set i2c fragmentation enable 0x01 to disable set to 0x00 | ||
NXP_I2C_FRAGMENTATION_ENABLED=0x00 |
Oops, something went wrong.