NXP PN7160 NCI Based NFC controllers Instructions
- September 18, 2024
- NXP
Table of Contents
PN7160 NCI Based NFC controllers
“`html
Specifications
- Product Name: PN7160/PN7220 NFC Controllers
- Manufacturer: NXP Semiconductors
- Interfaces: PN7160 – I2C or SPI, PN7220 – I2C
- Supported Platforms: Android 14 and above
Product Information
The PN7160/PN7220 NFC controllers from NXP Semiconductors are
designed to be integrated into an Android environment. These
controllers provide NFC functionality for various applications.
Usage Instructions
1. Integrating NFC Controllers into Android Environment
To integrate the PN7160/PN7220 NFC controllers into an Android
environment, follow these steps:
1.1 Installing Kernel Driver
Ensure you have the necessary kernel driver for the NFC
controller. The driver is exposed via the device node in
/dev/nxpnfc.
1.2 Driver Details
– PN7160 supports I2C or SPI physical interface, while PN7220
supports the I2C physical interface.
– Select the correct driver based on the chip type of PN7160 or
PN7220.
1.3 Getting the PN7160 Driver Source Code
To get the PN7160 driver source code, copy the
nfcandroid_platform_drivers/drivers/pn7160/nfc driver repository
into the kernel directory. Replace the existing implementation with
the new code.
2. Android Middleware Stack
The Android middleware stack for PN7160 and PN7220 NFC
controllers provides support for various functionalities including
EMVCo tasks.
Frequently Asked Questions (FAQ)
Q: What are the unsupported features of each NFC
controller?
A: From Android 14 onwards, P2P is not supported on PN7160.
Refer to Table 1 for more details on unsupported features.
“`
AN14430
PN7160/PN7220 Android 14 porting guide
Rev. 1.0 — 3 September 2024
Application note
Document information
Information
Content
Keywords
PN7160, PN7220, NCI, EMVCo, NFC Forum, Android, NFC
Abstract
This document describes how to port PN7160/PN7220 common middleware release to Android 14.
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
1 Introduction
This guide provides detailed instructions on how to integrate NXP NCI-based
NFC controllers, PN7160 and PN7220, into an Android environment. The process
involves installing the necessary kernel driver and configuration of MW (see
[1]). For further information, refer to the product page for PN7160 [2] and
PN7220 [3].
The Android Open Source Project (AOSP) has been updated to incorporate support
for both PN7160 and PN7220 NFC controllers.
The PN7220 comes in two configurations: single-host and dual-host. The stack
is generally the same for both. In dual-host mode, SMCU is added that means
that all EMVCo related tasks are executed on SMCU. In singlehost EMVCo is
executed in a dedicated EMVCo MW stack.
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 2 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
2 Android MW stack
Figure 1 illustrates the architecture of the PN7220 Android NFC stack.
Figure 1.PN7220 Android NFC stack
· The NXP I2C Driver is a kernel module that allows access to the hardware
resources of PN7220. · The HAL module is an implementation of the NXP NFC
controller-specific hardware abstraction layer. · LibNfc-Nci is a native
library that provides NFC functionality. · NFC JNI acts as a bridge between
Java and Native classes. · The NFC and EMVCo Framework is a module of the
application framework that allows access to NFC and
EMVCo functionalities.
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 3 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
Figure 2 shows the architecture of the PN7160 Android NFC stack.
Figure 2.PN7160 Android MW stack
· The NXP I2C Driver is a kernel module that allows access to the hardware
resources of PN7160. · The HAL module is an implementation of the NXP NFC
controller-specific hardware abstraction layer. · LibNfc-nci is a native
library that provides NFC functionality. · NFC JNI acts as a bridge between
Java and Native classes. · The NFC is a module of the application framework
that allows access to NFC functionalities. · The MW source code is the same
for PN7160 and PN7220, but there are a few limitations.
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 4 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
Table 1 shows unsupported features of each NFC controller.
Table 1.Unsupported features NFC controller PN7160
PN7220
Unsupported features
· EMVCo MW stack · SMCU · CT feature
· NFCEE_NDEF
Note: From Android 14 onwards P2P is also not supported on PN7160.
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 5 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
3 Kernel driver
To establish connection with the PN7220 or PN7160, the Android stack uses the
nxpnfc kernel driver. It can be found in [4].
3.1 Driver details
PN7220 supports I2C physical interface, while PN7160 supports I2C or SPI
physical interface. When installed into the kernel, the driver is exposed via
the device node in /dev/nxpnfc. Note: PN7160 and PN7220 use two different
drivers, selection of the correct driver is required based on the chip type.
3.2 Getting the PN7160 driver source code
Copy the nfcandroid_platform_drivers/drivers/pn7160/nfc driver repository into
the kernel directory, replacing the existing implementation. Refer to [4] for
the kernel files.
$rm -rf drivers/nfc $git clone “https://github.com/nxp-nfc-
infra/nfcandroid_platform_drivers.git” -b
br_ar_14_comm_infra_dev
This ends up with the folder drivers/nfc containing the following files: ·
README.md: repository information · Makefile: driver heading makefile ·
Kconfig: driver configuration file · License: driver licensing terms · nfc
subfolder containing:
commoc.c: generic driver implementation common.h: generic driver interface
definition i2c_drv.c: i2c specific driver implementation i2c_drv.h: i2c
specific driver interface definition spi_drv.c: spi specific driver
implementation spi_drv.h: spi specific driver interface definition
Makefile: makefile that is included in the makefile of the driver Kbuild =>
build file Kconfig => driver configuration file
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 6 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
3.3 Getting the PN7220 driver source code
Copy the nfcandroid_platform_drivers/drivers/pn7220cs/nfc (single-host
usecase) or nfcandroidplatform drivers/drivers/pn7220cms/nfc (dual-host
usecase) into the kernel directory drivers/nfc, replacing the existing driver.
Refer to [4] for the kernel files.
$rm -rf drivers/nfc $git clone “https://github.com/nxp-nfc-
infra/nfcandroid_platform_drivers.git” -b
br_ar_14_comm_infra_dev
Following this command, the folder drivers/nfc contains the following files: ·
README.md: repository information · Makefile: driver heading makefile ·
Kconfig: driver configuration file · License: driver licensing terms · nfc
subfolder containing:
commoc.c: generic driver implementation common.h: generic driver interface
definition i2c_drv.c: i2c specific driver implementation i2c_drv.h: i2c
specific driver interface definition Makefile: makefile that is included in
the makefile of the driver Kbuild => build file Kconfig => driver
configuration file
3.4 Building the driver
The devicetree is responsible for adding the driver to the kernel and loading
it on device boot.
After upgrading the devicetree specification, the platform-related devicetree
must be rebuilt. NXP recommends using kernel version 5.10 as it provides
comprehensive validation.
To build the driver, the following steps must be performed:
1. Get the kernel driver 2. Get the source code for the driver 3. Modify the
devicetree definition, which is unique to the device in use. 4. Build the
driver:
a. Through the menuconfig procedure, add the target driver into the build.
After rebuilding the completed kernel, the driver will be included in the
kernel image. All new kernel images must be copied into the AOSP build.
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 7 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
4 AOSP adaptation
NXP adds modifications to the AOSP code. This means that the AOSP code is used
as a foundation, but extended for NXP-specific features. [5] is the current
AOSP tag used by NXP. After obtaining the AOSP build, the existing AOSP code
must be replaced, and a number of patches must be applied.
Note: A different version of the AOSP code can be used, but additional
modifications must be performed.
4.1 AOSP build
1. Get AOSP source code.
$ repo init -u https://android.googlesource.com/platform/manifest -b
android-14.0.0_r2
$ repo sync
Note: The repo tool must be installed on the system. Refer to [6] for
instructions. 2. Build source code.
$cd Android_AROOT $source build/envsetup.sh $lunch select_target #target is DH
we want to use for example: evk_8mn-userdebug $make -j
3. Copy all NXP repositories into the target location.
Table 2.Branche for specific Android version Android version
Android 14
Branch br_ar_14_comm_infra_dev
Note: While cloning, it is important to select the correct branch.
Table 3.Clone repositories AOSP Repos
NXP GitHub Repos
“$ANDROID_ROOT”/packages/ https://github.com/nxp-nfc- infra/nxp_nci_hal_nfc/tree/br_ar_14_comm_infra_dev apps/Nfc
“$ANDROID_ROOT”/system/nfc https://github.com/nxp-nfc-infra /nxp_nci_hal_libnfc-nci/tree/br_ar_14_comm_infra_dev
“$ANDROID_ROOT”/hardware/ https://github.com/nxp-nfc- infra/nfcandroid_nfc_hidlimpl/tree/br_ar_14_comm_infra_dev nxp/nfc
“$ANDROID_ROOT”/vendor/nxp/ https://github.com/nxp-nfc- infra/nfcandroid_frameworks/tree/br_ar_14_comm_infra_dev frameworks
“$ANDROID_ROOT”/hardware/ https://github.com/nxp-nfc- infra/nfcandroid_emvco_aidlimpl/tree/
nxp/emvco
br_ar_14_comm_infra_dev
“$ANDROID_ROOT”
https://github.com/nxp-nfc-infra/nfcandroid_platform_reference/tree/ br_ar_14_comm_infra_dev
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 8 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
Table 4.Clone repositories for test applications and TDA support
Folder in GitHub
AOSP Repos
NXP GitHub
test_apps/SMCU_Switch
“$ANDROID_ROOT”/ packages/apps/
https://github.com/ nxp-nfc-infra/ nfcandroid_infra_test_apps
test_apps/EMVCoMode SwitchApp
“$ANDROID_ROOT”/ packages/apps/Nfc/
https://github.com/ nxp-nfc-infra/ nfcandroid_infra_test_apps
test_apps/Cockpit
“$ANDROID_ROOT”/ hardware/nxp/nfc/
https://github.com/ nxp-nfc-infra/ nfcandroid_infra_test_apps
test_apps/SelfTest
“$ANDROID_ROOT”/ hardware/nxp/nfc/
https://github.com/ nxp-nfc-infra/ nfcandroid_infra_test_apps
test_apps/SelfTest_pn7160 “$ANDROID_ROOT”/ hardware/nxp/nfc/
https://github.com/ nxp-nfc-infra/ nfcandroid_infra_test_apps
test_apps/load_unload
“$ANDROID_ROOT”/ hardware/nxp/nfc/
https://github.com/ nxp-nfc-infra/ nfcandroid_infra_test_apps
test_apps/SelfTestAidl
“$ANDROID_ROOT”/ hardware/nxp/nfc/
https://github.com/ nxp-nfc-infra/ nfcandroid_infra_test_apps
nfc_tda
“$ANDROID_ROOT”/system/ https://github.com/ nxp-nfc-infra/ nfcandroid_infra_comm_libs
emvco_tda
“$ANDROID_ROOT”/ hardware/nxp/emvco/
https://github.com/ nxp-nfc-infra/ nfcandroid_infra_comm_libs
emvco_tda_test
“$ANDROID_ROOT”/ hardware/nxp/emvco/
https://github.com/ nxp-nfc-infra/ nfcandroid_infra_comm_libs
NfcTdaTestApp
“$ANDROID_ROOT”/ packages/apps/Nfc/
https://github.com/ nxp-nfc-infra/ nfcandroid_infra_comm_libs
IC Supported PN7220 PN7220 PN7220 PN7220 PN7160 PN7220 PN7220 PN7220 PN7220 PN7220 PN7220
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 9 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
4. Apply patches.
Table 5.Apply patches
Location to apply
Patch to apply
Location of the patch
“$ANDROID_ROOT”/build/ AROOT_build_bazel.
bazel/
patch
https://github.com/nxp-nfc-infra/nfcandroid_platform_reference/ tree/br_ar_14_comm_infra_dev/build_cfg/build_pf_patches/
“$ANDROID_ROOT”/build/ AROOT_build_make.
make/
patch
https://github.com/nxp-nfc-infra/nfcandroid_platform_reference/ tree/br_ar_14_comm_infra_dev/build_cfg/build_pf_patches/
“$ANDROID_ROOT”/build/ AROOT_build_soong.
soong/
patch
https://github.com/nxp-nfc-infra/nfcandroid_platform_reference/ tree/br_ar_14_comm_infra_dev/build_cfg/build_pf_patches/
“$ANDROID_ROOT”/ frameworks/base/
AROOTframeworks base.patch
https://github.com/nxp-nfc-infra/nfcandroid_platform_reference/ tree/br_ar_14_comm_infra_dev/build_cfg/build_pf_patches/
“$ANDROID_ROOT”/ frameworks/native/
AROOTframeworks native.patch
https://github.com/nxp-nfc-infra/nfcandroid_platform_reference/ tree/br_ar_14_comm_infra_dev/build_cfg/build_pf_patches/
“$ANDROID_ROOT”/ system/logging/
AROOT_system_logging. https://github.com/nxp-nfc- infra/nfcandroid_platform_reference/
patch
tree/br_ar_14_comm_infra_dev/build_cfg/build_pf_patches/
“$ANDROID_ROOT”/ packages/modules/ Bluethooth/
AROOTpackages modules_Bluethooth. patch
https://github.com/nxp-nfc-infra/nfcandroid_platform_reference/ tree/br_ar_14_comm_infra_dev/build_cfg/build_pf_patches/
“$ANDROID_ROOT”/
AROOTframework
framework/proto_logging/ proto_logging.patch
https://github.com/nxp-nfc-infra/nfcandroid_platform_reference/ tree/br_ar_14_comm_infra_dev/build_cfg/build_pf_patches/
Note: Check the output after applying the patch, if any issue was observed during the patching. 5. Add FW libraries. Refer to [8] for FW. Note: Not mandatory. FW can always be updated. For PN7160:
$git clone https://github.com/NXP/nfc-NXPNFCC_FW.git $cp -r nfc- NXPNFCC_FW/InfraFW/pn7220/64-bit/libpn7160_fw.so AROOT/vendor/ nxp/7160/firmware/lib64/libpn7160_fw.so $cp -r nfc- NXPNFCC_FW/InfraFW/pn7220/32-bit/libpn7160_fw.so AROOT/vendor/ nxp/7160/firmware/lib/libpn7160_fw.so
For PN7220:
$git clone https://github.com/NXP/nfc-NXPNFCC_FW.git $cp -r nfc- NXPNFCC_FW/InfraFW/pn7220/64-bit/libpn7220_64bit.so AROOT/vendor/nxp/ pn7220/firmware/lib64/libpn72xx_fw.so
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 10 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
6. Adding NFC to the build In the device.mk makefile (for example,
device/brand/platform/device.mk), include specific makefiles:
$(call inherit-product, vendor/nxp/nfc/device-nfc.mk)
In the BoardConfig.mk makefile (for example,
device/brand/platform/BoardConfig.mk), include a specific makefile:
-include vendor/nxp/nfc/BoardConfigNfc.mk
7. Adding the DTA application
$git clone https://github.com/NXPNFCProject/NXPAndroidDTA.git $patch -p1 nfc-
dta.patch #located in https://github.com/nxp-nfc-infra/
nfcandroid_platform_reference/tree/br_ar_14_comm_infra_dev/build_cfg/
build_mw_patches/db845c $ cp -r nfc-dta /system/nfc-dta $
8. Build AOSP with changes:
$cd framework/base $mm $cd ../.. $cd vendor/nxp/frameworks $mm #after this
one, com.nxp.emvco.jar and com.nxp.nfc.jar should be inside out/
target/product/xxxx/system/framwework/ $cd ../../.. $cd hardware/nxp/nfc $mm
$cd ../../.. $make -j
Now, flash the device with new Android images.
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 11 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
4.2 Android NFC Apps and Lib on targets
After the build, the created libraries must be installed on the target device.
Section 4.2 specifies the project location, the corresponding library, and the
target device location where to be installed.
Note: EMVCo binaries are applicable only with PN7220.
Table 6.Compiled files with device target
Project location
Compiled Files
“$ANDROID_ROOT”/ packages/apps/Nfc
NfcNci.odex NfcNci.vdex lib/NfcNci.apk oat/libnfc_nci_jni.so
“$ANDROID_ROOT”/ system/nfc “$ANDROID_ROOT”/ system/nfc_tda” “$ANDROID_ROOT”/
hardware/nxp/nfc
“$ANDROID_ROOT/ hardware/interfaces/nfc”
“$ANDROID_ROOT”/ vendor/nxp/frameworks “$ANDROID_ROOT”/ hardware/nxp/emvco
“$ANDROID_ROOT/ hardware/nxp/emvco_tda”
libnfc_nci.so
nfc_tda.so
nfc_nci_nxp_pn72xx.so android.hardware.nfc_72xx@1.2-service
android.hardware.nfc_72xx@1.2-service.rc android.hardware.nfc@1.0.so
android.hardware.nfc@1.1.so android.hardware.nfc@1.2.so
vendor.nxp.nxpnfc@2.0.so vendor.nxp.nxpnfc@1.0.so
android.hardware.nfc-V1-ndk.so android.hardware.nfc@1.0.so
android.hardware.nfc@1.1.so android.hardware.nfc@1.2.so
android.hardware.nfc@1.0.so android.hardware.nfc@1.1.so
android.hardware.nfc@1.2.so
com.nxp.emvco.jar (PN7220) com.nxp.nfc.jar
emvco_poller.so (PN7220) vendor.nxp.emvco-V1-ndk.so vendor.nxp.emvco-V2-ndk.so
vendor.nxp.emvco-V2-ndk.so vendor.nxp.emvco-service vendor.nxp.emvco-
service.rc
emvco_tda.so
Comments
Location in target device
/system/app/NfcNci/ oat/arm64/ /system/app/NfcNci/ oat/arm64/
/system/app/NfcNci/ /system/lib64/
/system/lib64/
Applicable only for CT /system/lib64/ feature.
/vendor/lib64 /vendor/bin/hw/ /vendor/etc/init /system/lib64/ /system/lib64/
/system/lib64/ /vendor/lib64/ /vendor/lib64/
/system/ib64/ /system/lib64/ /system/lib64/ /system/lib64/ /vendor/lib64/
/vendor/lib64/ /vendor/lib64/
/system/framework /system/framework
/vendor/lib64/ /system/lib64/ /system/lib64/ /vendor/lib64/ /vendor/bin/hw/
/vendor/etc/init/
Applicable only for CT /vendor/lib64/ feature.
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 12 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
4.3 Block mapping
Mapping the block name from Section 1 to target location in AOSP code.
Table 7.Patch location in NFC Stack Block name NFC HAL and EMVCo HAL NFC Stack EMVCo L1 Data Exchange Layer = EMVCo Stack LibNfc-Nci NFC JNI NFC Service NFC Framework EMVCo Framework
Location in AOSP code hardware/interfaces/ hardware/nxp/nfc/ hardware/nxp/emvco/ system/nfc/ packages/apps/nfc/ packages/apps/nfc/ frameworks/base/ vendor/nxp/frameworks/
4.4 EMVCo API
PN7220 MW stack extends AOSP code with EMVCo MW stack. This section describes
the EMVCo APIs.
Note: APIs can be called only when using PN7220 IC. If calling it with PN7160
IC, the API does not work.
EMVCo Profile Discovery. Those APIs can be used with contact and contactless
profiles.
· registerEMVCoEventListener() ndk::ScopedAStatus registerEMVCoEventListener
( const std::shared_ptr< INxpEmvcoClientCallback > & in_clientCallback, bool
in_aidl_return )
Description: Register EMVCo callback function to receive the events from a
listener device Note: This function is must to ball before invoking any
other api. Parameters:
[in] in_clientCallback: has EMVCo client HAL callback [in]
in_aidl_return: indicates register status in return to caller Returns
boolean returns true, if success and returns false, if failed to register ·
getCurrentDiscoveryMode() ndk::ScopedAStatus
getCurrentDiscoveryMode(::aidl::vendor::nxp::emvco::NxpDiscoveryMode
_aidl_return)
Description: returns the current active profile type. Returns
NxpDiscoveryMode – NFC/EMVCo/Unknown
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 13 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
· onNfcStateChange() ndk::ScopedAStatus onNfcStateChange(NxpNfcState
in_nfcState)
Description: updated NFC state to EMVCo HAL. Parameters:
[in] in_nfcState: specifies the NFC state Returns:
void · registerNFCStateChangeCallback()
ndk::ScopedAStatus registerNFCStateChangeCallback ( const std::shared_ptr<
::aidl::vendor::nxp::emvco::INxpNfcStateChangeRequestCallback > &
in_nfcStateChangeRequestCallback,
bool _aidl_return )
Description: Register an NFC callback function to receive the events from a
listener device. Note: This function is must call before invoking any other
api. Parameters:
[in] in_nfcStateChangeCallback: INxpNfcStateChangeRequestCallback the event
callback function to be passed by the caller. It should implement to turn
ON/OFF NFC based on the request received.
Returns: boolean returns true, if success and returns false, if failed to
register. · setByteConfig()
ndk::ScopedAStatus setByteConfig ( ::aidl::vendor::nxp::emvco::NxpConfigType
in_type, int32_t in_length, int8_t in_value,
::aidl::vendor::nxp::emvco::NxpEmvcoStatus _aidl_return
)
· setEMVCoMode()
ndk::ScopedAStatus setEMVCoMode ( int8_t in_disc_mask, bool in_isStartEMVCo
)
Description: Starts the EMVCo mode with the Device-Controller. Once the
Application Data Channel is established, the Application may send start the
EMVCo mode with the Device-Controller.
Parameters: [in] in_disc_mask EMVCo: polling technologies are configured
through this parameter [in]in_isStartEMVCo: specifies to start or stop the
EMVCo mode
Returns: void
· setLed()
ndk::ScopedAStatus setLed ( ::aidl::vendor::nxp::emvco::NxpLedControl
in_ledControl, ::aidl::vendor::nxp::emvco::NxpEmvcoStatus * emvco_status
)
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 14 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
For Contact EMVCo, the following APIs can be used on top of the previous ones.
· closeTDA()
ndk::ScopedAStatus closeTDA ( int8_t in_tdaID, bool in_standBy )
Description: Closes the smart card connected over TDA Parameters:
[in] tdaID: id of the tda slot to be closed Exceptions:
EMVCO_STATUS_INVALID_PARAMETER, if provided tdaID is in-valid
EMVCO_STATUS_FEATURE_NOT_SUPPORTED when the contact card feature is not
supported. Returns: void
· discoverTDA()
ndk::ScopedAStatus discoverTDA (
std::vector<::aidl::vendor::nxp::emvco::NxpEmvcoTDAInfo > emvcoTDAInfo )
Description: discoverTDA provides all the details of smart card connected over
TDA Parameters:
[in]in_clientCallback: provides EMVCo state and TDA state as callback
Exceptions:
EMVCO_STATUS_FEATURE_NOT_SUPPORTED when the contact card feature is not
supported. Returns:
NxpEmvcoTDAInfo[] returns all the smart card connected over TDA. valid
emvcoTDAInfo is received only when the status is EMVCO_STATUS_OK
· openTDA()
ndk::ScopedAStatus openTDA ( int8_t in_tdaID, bool in_standBy, int8_t *
out_connID )
Description: opens the smart card connected over TDA Parameters:
[in]tdaID: tda id of the smart card received through discoverTDA
Exceptions:
EMVCO_STATUS_INVALID_PARAMETER, if provided tdaID is in-valid
EMVCO_STATUS_FEATURE_NOT_SUPPORTED when the contact card feature is not
supported. Returns: byte returns the connection id of the smart card.
valid connection id received only when status is
EMVCO_STATUS_OK
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 15 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
· registerEMVCoCTListener()
ndk::ScopedAStatus registerEMVCoCTListener ( const
std::shared_ptr<::aidl::vendor::nxp::emvco::INxpEmvcoTDACallback > &
in_in_clientCallback,
bool _aidl_return )
Description: registers the EMVCoCT callback to the EMVCo stack Parameters:
[in]in_in_clientCallback: provides EMVCo state and TDA state as callback
Returns:
void
· transceive()
ndk::ScopedAStatus transceive ( const std::vector< uint8_t > & in_cmd_data,
std::vector< uint8_t > out_rsp_data )
Description: sends application data with the Device-Controller and receives
response data from the controller
Note: connection id of the TDA should be added as part of the NCI header.
Parameters:
[in]in_cmd_data: Application command data buffer Exceptions:
EMVCO_STATUS_INVALID_PARAMETER, if provided connection id is in-valid
EMVCO_STATUS_FEATURE_NOT_SUPPORTED when the contact card feature is not
supported. Returns: Response APDU received from controller. valid Response
APDU received only when status is
EMVCO_STATUS_OK
For EMVCo contactless, the following APIs can be called:
· registerEMVCoEventListener()
ndk::ScopedAStatus registerEMVCoEventListener ( const std::shared_ptr<
INxpEmvcoClientCallback > & in_clientCallback,
bool _aidl_return )
Description: Register an EMVCo callback function to receive the events from
a listener device. Note: This function is must call before invoking any
other api. Parameters:
[in]in_clientCallback: has EMVCo client HAL callback [in]in_aidl_return:
indicates register status in return to caller Returns: boolean returns
true, if success and returns false, if failed to register
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 16 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
· setEMVCoMode()
ndk::ScopedAStatus setEMVCoMode ( int8_t in_config, bool in_isStartEMVCo )
Description: Starts the EMVCo mode with the Device-Controller. Once the
Application Data Channel is established, the Application may send start the
EMVCo mode with the Device-Controller.
Parameters: [in]in_config: EMVCo polling technologies are configured
through this parameter [in]in_isStartEMVCo: specifies to start or stop the
EMVCo mode
Returns: void
· stopRFDisovery()
ndk::ScopedAStatus stopRFDisovery (
::aidl::vendor::nxp::emvco::NxpDeactivationType in_deactivationType,
::aidl::vendor::nxp::emvco::NxpEmvcoStatus emvco_status )
Description: stops the RF field and moves in to the specified deactivation
state. Parameters:
[in]in_deactivationType: specifies the state to be in after RF deactivation
Returns:
NxpEmvcoStatus returns EMVCO_STATUS_OK if command processed successfully and
returns EMVCO_STATUS_FAILED, if command is not processed due to in-valid
state. EMVCo mode should be ON to call this API
· transceive()
ndk::ScopedAStatus transceive ( const std::vector< uint8_t > & in_data,
int32_t _aidl_return )
Description: send application data with the Device-Controller. Note: In
case if send data is failed, the Application shall again invoke open() before
invoking this API. Parameters:
[in]in_data: Application data buffer Returns:
NxpEmvcoStatus indicating execution status
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 17 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
4.5 Configuration files PN7160
For PN7160, there are two different configuration files. 1. libnfc-nci.conf 2.
libnfc-nxp.conf
Note: Configuration files provided by NXP are examples related to the NFC
controller demo board. These files must be adopted according to the targeted
integration.
Configuration files must be placed in the target location (see Table 8).
Table 8.Locations of configuration files Name of configuration file libnfc- nci.conf libnfc-nxp.conf
Location in device system/etc vendor/etc
To get more informations on the configuration files, see [9].
4.6 Configuration files PN7220
For PN7220, there are five different configuration files.
1. libemvco-nxp.conf 2. libnfc-nci.conf 3. libnfc-nxp.conf 4. libnfc-nxp-
eeprom.conf 5. libnfc-nxp-rfExt.conf
Note: Configuration files provided by NXP are examples related to the NFC
controller demo board. These files must be adopted according to the targeted
integration.
Configuration files need to be placed in the target location (see Table 9).
Table 9.Locations of configuration files Name of configuration file libemvco- nxp.conf libnfc-nci.conf libnfc-nxp.conf libnfc-nxp-eeprom.conf libnfc- nxprfExt.conf
Location in device vendor/etc system/etc vendor/etc vendor/etc vendor/etc
To get more informations on the configuration files, see [9].
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 18 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
4.7 DTA application
To allow NFC Forum certification testing, a device test application is
provided. It is composed of several components in the different Android
layers, which must be built and included in the Android image.
To push the DTA application, the following steps must be executed:
1. Copy all DTA files to one location
$cp -rf “out/target/product/hikey960/system/lib64/libosal.so” /DTA-PN7220 $cp
-rf “out/target/product/hikey960/system/lib64/libmwif.so” /DTA-PN7220 $cp -rf
“out/target/product/hikey960/system/lib64/libdta.so” /DTA-PN7220 $cp -rf
“out/target/product/hikey960/system/lib64/libdta_jni.so” /DTA-PN7220 $cp -rf
“out/target/product/hikey960/system/app/NxpDTA/NxpDTA.apk” /DTAPN7220
2. Push the binaries to the device as bellow
adb shell mkdir /system/app/NxpDTA/ adb push libosal.so /system/lib64/ adb
push libdta.so /system/lib64/ adb push libdta_jni.so /system/lib64/ adb push
libmwif.so /system/lib64/ adb push NxpDTA.apk /system/app/NxpDTA/
After flashing the target, the DTA application should then be present in the
list of installed applications. Refer to [7] for a detailed description of how
to use the application.
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 19 / 28
NXP Semiconductors
5 Abbreviations
Table 10.Abbreviations
Acronym
Description
APDU
application protocol data unit
AOSP
Android Open Source Project
DH
device host
HAL
hardware abstraction layer
FW
firmware
I2C
Inter-Integrated Circuit
LPCD
lower powered card detection
NCI
NFC controller interface
NFC
near-field communication
MW
middleware
PLL
phase-locked loop
P2P
peer to peer
RF
radio frequency
SDA
serial data
SMCU
secure microcontroller
SW
software
AN14430
PN7160/PN7220 Android 14 porting guide
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 20 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
6 References
[1] GitHub repository PN7160 and PN7220 Common MW: (link) [2] Web page
PN7160 NFC Plug and Play Controller with Integrated Firmware and NCI
Interface (link) [3] Web page PN7220 EMV L1 Compliant NFC Controller with
NCI Interface Supporting EMV and NFC
Forum Applications (link) [4] GitHub repository PN7160 and PN7220 kernel
driver: (link) [5] Resources AOSP r2 tag (link) [6] Resources Source
control tools (link) [7] User guide UG10068 PN7220 Quick start guide
(link) [8] GitHub repository PN7160 and PN7220 FW location: (link) [9]
Application note AN14431 PN7160/PN7220 configuration files (link)
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 21 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
7 Note about the source code in the document
Example code shown in this document has the following copyright and
BSD-3-Clause license:
Copyright 2024 NXP Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials must be provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 22 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
8 Revision history
Table 11.Revision history Document ID
AN14430 v.1.0
Release date
Description
03 September 2024 · Initial version
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 23 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
Legal information
Definitions
Draft — A draft status on a document indicates that the content is still under
internal review and subject to formal approval, which may result in
modifications or additions. NXP Semiconductors does not give any
representations or warranties as to the accuracy or completeness of
information included in a draft version of a document and shall have no
liability for the consequences of use of such information.
Disclaimers
Limited warranty and liability — Information in this document is believed to
be accurate and reliable. However, NXP Semiconductors does not give any
representations or warranties, expressed or implied, as to the accuracy or
completeness of such information and shall have no liability for the
consequences of use of such information. NXP Semiconductors takes no
responsibility for the content in this document if provided by an information
source outside of NXP Semiconductors. In no event shall NXP Semiconductors be
liable for any indirect, incidental, punitive, special or consequential
damages (including – without limitation lost profits, lost savings, business
interruption, costs related to the removal or replacement of any products or
rework charges) whether or not such damages are based on tort (including
negligence), warranty, breach of contract or any other legal theory.
Notwithstanding any damages that customer might incur for any reason
whatsoever, NXP Semiconductors’ aggregate and cumulative liability towards
customer for the products described herein shall be limited in accordance with
the Terms and conditions of commercial sale of NXP Semiconductors.
Right to make changes — NXP Semiconductors reserves the right to make changes
to information published in this document, including without limitation
specifications and product descriptions, at any time and without notice. This
document supersedes and replaces all information supplied prior to the
publication hereof.
Suitability for use — NXP Semiconductors products are not designed, authorized
or warranted to be suitable for use in life support, life-critical or safety-
critical systems or equipment, nor in applications where failure or
malfunction of an NXP Semiconductors product can reasonably be expected to
result in personal injury, death or severe property or environmental damage.
NXP Semiconductors and its suppliers accept no liability for inclusion and/or
use of NXP Semiconductors products in such equipment or applications and
therefore such inclusion and/or use is at the customer’s own risk.
Applications — Applications that are described herein for any of these
products are for illustrative purposes only. NXP Semiconductors makes no
representation or warranty that such applications will be suitable for the
specified use without further testing or modification. Customers are
responsible for the design and operation of their applications and products
using NXP Semiconductors products, and NXP Semiconductors accepts no liability
for any assistance with applications or customer product design. It is
customer’s sole responsibility to determine whether the NXP Semiconductors
product is suitable and fit for the customer’s applications and products
planned, as well as for the planned application and use of customer’s third
party customer(s). Customers should provide appropriate design and operating
safeguards to minimize the risks associated with their applications and
products. NXP Semiconductors does not accept any liability related to any
default, damage, costs or problem which is based on any weakness or default in
the customer’s applications or products, or the application or use by
customer’s third party customer(s). Customer is responsible for doing all
necessary testing for the customer’s applications and products using NXP
Semiconductors products in order to avoid a default of the applications and
the products or of the application or use by customer’s third party
customer(s). NXP does not accept any liability in this respect.
Terms and conditions of commercial sale — NXP Semiconductors products are sold
subject to the general terms and conditions of commercial sale, as published
at https://www.nxp.com/profile/terms, unless otherwise agreed in a valid
written individual agreement. In case an individual agreement is concluded
only the terms and conditions of the respective agreement shall apply. NXP
Semiconductors hereby expressly objects to applying the customer’s general
terms and conditions with regard to the purchase of NXP Semiconductors
products by customer.
Export control — This document as well as the item(s) described herein may be
subject to export control regulations. Export might require a prior
authorization from competent authorities.
Suitability for use in non-automotive qualified products — Unless this
document expressly states that this specific NXP Semiconductors product is
automotive qualified, the product is not suitable for automotive use. It is
neither qualified nor tested in accordance with automotive testing or
application requirements. NXP Semiconductors accepts no liability for
inclusion and/or use of non-automotive qualified products in automotive
equipment or applications. In the event that customer uses the product for
design-in and use in automotive applications to automotive specifications and
standards, customer (a) shall use the product without NXP Semiconductors’
warranty of the product for such automotive applications, use and
specifications, and (b) whenever customer uses the product for automotive
applications beyond NXP Semiconductors’ specifications such use shall be
solely at customer’s own risk, and (c) customer fully indemnifies NXP
Semiconductors for any liability, damages or failed product claims resulting
from customer design and use of the product for automotive applications beyond
NXP Semiconductors’ standard warranty and NXP Semiconductors’ product
specifications.
HTML publications — An HTML version, if available, of this document is
provided as a courtesy. Definitive information is contained in the applicable
document in PDF format. If there is a discrepancy between the HTML document
and the PDF document, the PDF document has priority.
Translations — A non-English (translated) version of a document, including the
legal information in that document, is for reference only. The English version
shall prevail in case of any discrepancy between the translated and English
versions.
Security — Customer understands that all NXP products may be subject to
unidentified vulnerabilities or may support established security standards or
specifications with known limitations. Customer is responsible for the design
and operation of its applications and products throughout their lifecycles to
reduce the effect of these vulnerabilities on customer’s applications and
products. Customer’s responsibility also extends to other open and/or
proprietary technologies supported by NXP products for use in customer’s
applications. NXP accepts no liability for any vulnerability. Customer should
regularly check security updates from NXP and follow up appropriately.
Customer shall select products with security features that best meet rules,
regulations, and standards of the intended application and make the ultimate
design decisions regarding its products and is solely responsible for
compliance with all legal, regulatory, and security related requirements
concerning its products, regardless of any information or support that may be
provided by NXP. NXP has a Product Security Incident Response Team (PSIRT)
(reachable at PSIRT@nxp.com) that manages the investigation, reporting, and
solution release to security vulnerabilities of NXP products.
NXP B.V. — NXP B.V. is not an operating company and it does not distribute or
sell products.
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 24 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
Licenses
Purchase of NXP ICs with NFC technology — Purchase of an NXP Semiconductors IC
that complies with one of the Near Field Communication (NFC) standards ISO/IEC
18092 and ISO/IEC 21481 does not convey an implied license under any patent
right infringed by implementation of any of those standards. Purchase of NXP
Semiconductors IC does not include a license to any NXP patent (or other IP
right) covering combinations of those products with other products, whether
hardware or software.
Trademarks
Notice: All referenced brands, product names, service names, and trademarks
are the property of their respective owners. NXP — wordmark and logo are
trademarks of NXP B.V. I2C-bus — logo is a trademark of NXP B.V.
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 25 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
Tables
Tab. 1. Tab. 2. Tab. 3. Tab. 4.
Tab. 5.
Unsupported features ………………………………….5 Branche for specific Android version ……………..8 Clone repositories ……………………………………… 8 Clone repositories for test applications and TDA support ……………………………………………… 9 Apply patches …………………………………………..10
Tab. 6. Tab. 7. Tab. 8. Tab. 9. Tab. 10. Tab. 11.
Compiled files with device target …………………12 Patch location in NFC Stack ……………………… 13 Locations of configuration files ……………………18 Locations of configuration files ……………………18 Abbreviations ……………………………………………20 Revision history ………………………………………..23
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 26 / 28
NXP Semiconductors
AN14430
PN7160/PN7220 Android 14 porting guide
Figures
Fig. 1. PN7220 Android NFC stack ………………………… 3 Fig. 2. PN7160 Android MW stack
………………………….4
AN14430
Application note
All information provided in this document is subject to legal disclaimers.
Rev. 1.0 — 3 September 2024
© 2024 NXP B.V. All rights reserved.
Document feedback 27 / 28
NXP Semiconductors
Contents
1
Introduction ……………………………………………… 2
2
Android MW stack ……………………………………. 3
3
Kernel driver ……………………………………………. 6
3.1
Driver details ………………………………………………6
3.2
Getting the PN7160 driver source code ………….6
3.3
Getting the PN7220 driver source code ………….7
3.4
Building the driver ……………………………………….7
4
AOSP adaptation ……………………………………… 8
4.1
AOSP build ……………………………………………….. 8
4.2
Android NFC Apps and Lib on targets …………. 12
4.3
Block mapping …………………………………………. 13
4.4
EMVCo API …………………………………………….. 13
4.5
Configuration files PN7160 ………………………… 18
4.6
Configuration files PN7220 ………………………… 18
4.7
DTA application …………………………………………19
5
Abbreviations …………………………………………. 20
6
References ………………………………………………21
7
Note about the source code in the
document ………………………………………………..22
8
Revision history ………………………………………23
Legal information …………………………………….24
AN14430
PN7160/PN7220 Android 14 porting guide
Please be aware that important notices concerning this document and the product(s) described herein, have been included in section ‘Legal information’.
© 2024 NXP B.V.
All rights reserved.
For more information, please visit: https://www.nxp.com
Document feedback
Date of release: 3 September 2024 Document identifier: AN14430
References
- Today I Learned for programmers - Tiloid
- platform/manifest - Git at Google
- GitHub: Let’s build from here · GitHub
- nxp-nfc-infra · GitHub
- GitHub - nxp-nfc-infra/nfcandroid_platform_drivers: DB845C and Hikey board and linux I2C client drivers and patches
- GitHub - nxp-nfc-infra/nfcandroid_platform_reference: DB845C and linux Kernal patches
- GitHub - NXPNFCProject/NXPAndroidDTA: NXPAndroidDTA
Read User Manual Online (PDF format)
Read User Manual Online (PDF format) >>