Skip to content

Commit

Permalink
Add module for NXP PN7160 NFC chip as token provider (#951)
Browse files Browse the repository at this point in the history
* Add module for PN7160 NFC reader

Signed-off-by: Christoph Burandt <[email protected]>

* Refactor Code to meet criteria of PR discussion:

Signed-off-by: Christoph Burandt <[email protected]>

* Add debug config option and log token discovery only in debug mode

Signed-off-by: Christoph Burandt <[email protected]>

* Set configuration file search path at runtime

Signed-off-by: Christoph Burandt <[email protected]>

---------

Signed-off-by: Christoph Burandt <[email protected]>
Signed-off-by: cburandt <[email protected]>
  • Loading branch information
cburandt authored Dec 20, 2024
1 parent d8db948 commit 6e669fd
Show file tree
Hide file tree
Showing 15 changed files with 803 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ else()

find_package(fsm REQUIRED)
find_package(slac REQUIRED)
find_package(libnfc-nci REQUIRED)

find_package(pugixml REQUIRED)
find_package(CURL 7.84.0 REQUIRED)
Expand Down
5 changes: 5 additions & 0 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ ext-mbedtls:
everest-utils:
git: https://github.com/EVerest/everest-utils.git
git_tag: v0.4.4
# linux_libnfc-nci for RFID
libnfc-nci:
git: https://github.com/EVerest/linux_libnfc-nci.git
git_tag: 2024.11.0
cmake_condition: "EVEREST_DEPENDENCY_ENABLED_LIBNFC_NCI"

# unit testing
gtest:
Expand Down
5 changes: 5 additions & 0 deletions module-dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ ev_define_dependency(
OUTPUT_VARIABLE_SUFFIX LIBISO15118
DEPENDENT_MODULES_LIST Evse15118D20)

ev_define_dependency(
DEPENDENCY_NAME libnfc-nci
OUTPUT_VARIABLE_SUFFIX LIBNFC_NCI
DEPENDENT_MODULES_LIST PN7160TokenProvider)

if(NOT everest-gpio IN_LIST EVEREST_EXCLUDE_DEPENDENCIES)
set(EVEREST_DEPENDENCY_ENABLED_EVEREST_GPIO ON)
else()
Expand Down
1 change: 1 addition & 0 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ev_add_module(OCPP201)
ev_add_module(PacketSniffer)
ev_add_module(PersistentStore)
ev_add_module(PN532TokenProvider)
ev_add_module(PN7160TokenProvider)
ev_add_module(PyEvJosev)
ev_add_module(Setup)
ev_add_module(SerialCommHub)
Expand Down
41 changes: 41 additions & 0 deletions modules/PN7160TokenProvider/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# AUTO GENERATED - MARKED REGIONS WILL BE KEPT
# template version 3
#

# module setup:
# - ${MODULE_NAME}: module name
ev_setup_cpp_module()

# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1

target_include_directories(${MODULE_NAME}
PRIVATE
"common"
)

target_sources(${MODULE_NAME}
PRIVATE
"main/libnfc_handler.cpp"
)

target_link_libraries(${MODULE_NAME}
PRIVATE
"libnfc_nci"
)
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1

target_sources(${MODULE_NAME}
PRIVATE
"main/auth_token_providerImpl.cpp"
)

# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1

install(FILES
"libnfc-nci_config/libnfc-nxp.conf"
"libnfc-nci_config/libnfc-nci.conf"
DESTINATION
"${CMAKE_INSTALL_SYSCONFDIR}/everest/libnfc_config/")

# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
15 changes: 15 additions & 0 deletions modules/PN7160TokenProvider/PN7160TokenProvider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2022 - 2024 Pionix GmbH and Contributors to EVerest
#include "PN7160TokenProvider.hpp"

namespace module {

void PN7160TokenProvider::init() {
invoke_init(*p_main);
}

void PN7160TokenProvider::ready() {
invoke_ready(*p_main);
}

} // namespace module
58 changes: 58 additions & 0 deletions modules/PN7160TokenProvider/PN7160TokenProvider.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef PN7160TOKEN_PROVIDER_HPP
#define PN7160TOKEN_PROVIDER_HPP

//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 2
//

#include "ld-ev.hpp"

// headers for provided interface implementations
#include <generated/interfaces/auth_token_provider/Implementation.hpp>

// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1

namespace module {

struct Conf {};

class PN7160TokenProvider : public Everest::ModuleBase {
public:
PN7160TokenProvider() = delete;
PN7160TokenProvider(const ModuleInfo& info, std::unique_ptr<auth_token_providerImplBase> p_main, Conf& config) :
ModuleBase(info), p_main(std::move(p_main)), config(config){};

const std::unique_ptr<auth_token_providerImplBase> p_main;
const Conf& config;

// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
// insert your public definitions here
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1

protected:
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
// insert your protected definitions here
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1

private:
friend class LdEverest;
void init();
void ready();

// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
// insert your private definitions here
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};

// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
// insert other definitions here
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1

} // namespace module

#endif // PN7160TOKEN_PROVIDER_HPP
27 changes: 27 additions & 0 deletions modules/PN7160TokenProvider/doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. _everest_modules_handwritten_PN7160TokenProvider:

*******************
PN7160TokenProvider
*******************

This module provides authentication tokens obtained from RFID cards via the NXP PN7160 NFC chip.

It uses a modified *libnfc-nci* as external dependency to interface the chip via I²C or SPI, either from user space or via a kernel module.

Hardware Interface Configuration
================================

Configuration of the hardware interface is possible at runtime.
The module installs two configuration files:

* ``libnfc-nci_config/libnfc-nci.conf``: define NFC options
* ``libnfc-nci_config/libnfc-nxp.conf``: choose the hardware interface (kernel module vs. userspace; I²C vs. SPI, ...)

Module Configuration
====================

The EVerest module can be adjusted in its behaviour as follows:

* ``token_debounce_interval_ms``: Publish tokens in minimum intervall of this timespan in order not to flood subscribers.
* ``disable_nfc_rfid``: Allows to load the module without actually initializing the hardware.

121 changes: 121 additions & 0 deletions modules/PN7160TokenProvider/libnfc-nci_config/libnfc-nci.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
##############################################################################
#
# Note by PIONIX GmbH
# ===================
#
# Original file distributed NXP
#
# 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.
#
##############################################################################

########################### PN7160 libnfc-nci.conf ############################

###############################################################################
# Application options
APPL_TRACE_LEVEL=0xFF
PROTOCOL_TRACE_LEVEL=0xFFFFFFFF

NFC_DEBUG_ENABLED=0x00

###############################################################################
# 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

###############################################################################
# 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=0xCF

###############################################################################
# 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

PRESERVE_STORAGE=0x01

###############################################################################
# AID_MATCHING constants
# AID_MATCHING_EXACT_ONLY 0x00
# AID_MATCHING_EXACT_OR_PREFIX 0x01
# AID_MATCHING_PREFIX_ONLY 0x02
# AID_MATCHING_EXACT_OR_SUBSET_OR_PREFIX 0x03
AID_MATCHING_MODE=0x03

###############################################################################
# Override the stack default for NFA_EE_MAX_EE_SUPPORTED set in nfc_target.h.
# Maximum EE supported number
NFA_MAX_EE_SUPPORTED=0x01

###############################################################################
#Set the OffHost AID supported power state:
OFFHOST_AID_ROUTE_PWR_STATE=0x3B

###############################################################################
# Vendor Specific Proprietary Protocol & Discovery Configuration
# Set to 0xFF if unsupported
# byte[0] NCI_PROTOCOL_18092_ACTIVE
# byte[1] NCI_PROTOCOL_B_PRIME
# byte[2] NCI_PROTOCOL_DUAL
# byte[3] NCI_PROTOCOL_15693
# byte[4] NCI_PROTOCOL_KOVIO
# byte[5] NCI_PROTOCOL_MIFARE
# byte[6] NCI_DISCOVERY_TYPE_POLL_KOVIO
# byte[7] NCI_DISCOVERY_TYPE_POLL_B_PRIME
# byte[8] NCI_DISCOVERY_TYPE_LISTEN_B_PRIME
NFA_PROPRIETARY_CFG={05:FF:FF:06:81:80:70:FF:FF}

###############################################################################
Loading

0 comments on commit 6e669fd

Please sign in to comment.