Add support for NFC 1.1

Supresses the following denials:
denied  { add } for interface=vendor.nxp.nxpnfc::INxpNfc pid=5675 scontext=u:r:hal_nfc_default:s0
tcontext=u:object_r:default_android_hwservice:s0 tclass=hwservice_manager permissive=0

denied  { find } for interface=vendor.nxp.nxpese::INxpEse pid=5675 scontext=u:r:hal_nfc_default:s0
tcontext=u:object_r:default_android_hwservice:s0 tclass=hwservice_manager permissive=0

Test: Enable/Disable NFC, Tag reading
Bug: 75980364
Merged-In: I337810ff89d61f796cb213cd931a7b665870029e
Change-Id: I337810ff89d61f796cb213cd931a7b665870029e
(cherry picked from commit 847e28f86e226e49bb9253823df9d238bf10e31f)
diff --git a/device.mk b/device.mk
index e3e80c9..bb1fc98 100755
--- a/device.mk
+++ b/device.mk
@@ -322,11 +322,12 @@
 
 # NFC packages
 PRODUCT_PACKAGES += \
-    nfc_nci.msm8998 \
     NfcNci \
     Tag \
-    android.hardware.nfc@1.0-impl \
-    android.hardware.nfc@1.0-service
+    android.hardware.nfc@1.1-service \
+
+PRODUCT_PACKAGES += \
+    SecureElement
 
 PRODUCT_COPY_FILES += \
     device/google/wahoo/nfc/libnfc-nci.conf:$(TARGET_COPY_OUT_SYSTEM)/etc/libnfc-nci.conf \
diff --git a/manifest.xml b/manifest.xml
index 0eee081..3466562 100644
--- a/manifest.xml
+++ b/manifest.xml
@@ -203,7 +203,7 @@
     <hal format="hidl">
         <name>android.hardware.nfc</name>
         <transport>hwbinder</transport>
-        <version>1.0</version>
+        <version>1.1</version>
         <interface>
             <name>INfc</name>
             <instance>default</instance>
diff --git a/nfc/libnfc-nci.conf b/nfc/libnfc-nci.conf
index c1ba35a..3db7084 100644
--- a/nfc/libnfc-nci.conf
+++ b/nfc/libnfc-nci.conf
@@ -1,180 +1,24 @@
-###################### Start of libnfc-brcm.conf #######################
-
 ###############################################################################
 # Application options
 NFC_DEBUG_ENABLED=0
 
 ###############################################################################
-# performance measurement
-# Change this setting to control how often USERIAL log the performance (throughput)
-# data on read/write/poll
-# defailt is to log performance dara for every 100 read or write
-#REPORT_PERFORMANCE_MEASURE=100
-
-###############################################################################
 # File used for NFA storage
 NFA_STORAGE="/data/nfc"
 
 ###############################################################################
-# Snooze Mode Settings
-#
-#  By default snooze mode is enabled.  Set SNOOZE_MODE_CFG byte[0] to 0
-#  to disable.
-#
-#  If SNOOZE_MODE_CFG is not provided, the default settings are used:
-#  They are as follows:
-#       8             Sleep Mode (0=Disabled 1=UART 8=SPI/I2C)
-#       0             Idle Threshold Host
-#       0             Idle Threshold HC
-#       0             NFC Wake active mode (0=ActiveLow 1=ActiveHigh)
-#       1             Host Wake active mode (0=ActiveLow 1=ActiveHigh)
-#
-#SNOOZE_MODE_CFG={08:00:00:00:01}
-
-###############################################################################
-# Insert a delay in milliseconds after NFC_WAKE and before write to NFCC
-#NFC_WAKE_DELAY=20
-
-###############################################################################
-# Various Delay settings (in ms) used in USERIAL
-#  POWER_ON_DELAY
-#    Delay after turning on chip, before writing to transport (default 300)
-#  PRE_POWER_OFF_DELAY
-#    Delay after deasserting NFC-Wake before turn off chip (default 0)
-#  POST_POWER_OFF_DELAY
-#    Delay after turning off chip, before USERIAL_close returns (default 0)
-#
-#POWER_ON_DELAY=300
-#PRE_POWER_OFF_DELAY=0
-#POST_POWER_OFF_DELAY=0
-
-###############################################################################
-# Maximum time (ms) to wait for RESET NTF after setting REG_PU to high
-# The default is 1000.
-#NFCC_ENABLE_TIMEOUT=0
-
-###############################################################################
-# LPTD mode configuration
-#  byte[0] is the length of the remaining bytes in this value
-#     if set to 0, LPTD params will NOT be sent to NFCC (i.e. disabled).
-#  byte[1] is the param id it should be set to B9.
-#  byte[2] is the length of the LPTD parameters
-#  byte[3] indicates if LPTD is enabled
-#     if set to 0, LPTD will be disabled (parameters will still be sent).
-#  byte[4-n] are the LPTD parameters.
-#  By default, LPTD is enabled and default settings are used.
-#  See nfc_hal_dm_cfg.c for defaults
-#LPTD_CFG={23:B9:21:01:02:FF:FF:04:A0:0F:40:00:80:02:02:10:00:00:00:31:0C:30:00:00:00:00:00:00:00:00:00:00:00:00:00:00}
-
-###############################################################################
-# Startup Configuration (100 bytes maximum)
-#
-# For the 0xCA parameter, byte[9] (marked by 'AA') is for UICC0, and byte[10] (marked by BB) is
-#    for UICC1.  The values are defined as:
-#   0 : UICCx only supports ISO_DEP in low power mode.
-#   2 : UICCx only supports Mifare in low power mode.
-#   3 : UICCx supports both ISO_DEP and Mifare in low power mode.
-#
-#                                                                          AA BB
-#NFA_DM_START_UP_CFG={1F:CB:01:01:A5:01:01:CA:14:00:00:00:00:06:E8:03:00:00:00:00:00:00:00:00:00:00:00:00:00:80:01:01}
-
-###############################################################################
-# Startup Vendor Specific Configuration (100 bytes maximum);
-#  byte[0] TLV total len = 0x5
-#  byte[1] NCI_MTS_CMD|NCI_GID_PROP = 0x2f
-#  byte[2] NCI_MSG_FRAME_LOG = 0x9
-#  byte[3] 2
-#  byte[4] 0=turn off RF frame logging; 1=turn on
-#  byte[5] 0=turn off SWP frame logging; 1=turn on
-#  NFA_DM_START_UP_VSC_CFG={05:2F:09:02:01:01}
-
-###############################################################################
-# Antenna Configuration - This data is used when setting 0xC8 config item
-# at startup (before discovery is started).  If not used, no value is sent.
-#
-# The settings for this value are documented here:
-# http://wcgbu.broadcom.com/wpan/PM/Project%20Document%20Library/bcm20791B0/
-#   Design/Doc/PHY%20register%20settings/BCM20791-B2-1027-02_PHY_Recommended_Reg_Settings.xlsx
-# This document is maintained by Paul Forshaw.
-#
-# The values marked as ?? should be tweaked per antenna or customer/app:
-# {20:C8:1E:06:??:00:??:??:??:00:??:24:00:1C:00:75:00:77:00:76:00:1C:00:03:00:0A:00:??:01:00:00:40:04}
-# array[0] = 0x20 is length of the payload from array[1] to the end
-# array[1] = 0xC8 is PREINIT_DSP_CFG
-#PREINIT_DSP_CFG={20:C8:1E:06:1F:00:0F:03:3C:00:04:24:00:1C:00:75:00:77:00:76:00:1C:00:03:00:0A:00:48:01:00:00:40:04}
-
-###############################################################################
-# Configure crystal frequency when internal LPO can't detect the frequency.
-#XTAL_FREQUENCY=0
-###############################################################################
-# Configure the default Destination Gate used by HCI (the default is 4, which
-# is the ETSI loopback gate.
-NFA_HCI_DEFAULT_DEST_GATE=0xF0
-
-###############################################################################
-# Configure the single default SE to use.  The default is to use the first
-# SE that is detected by the stack.  This value might be used when the phone
-# supports multiple SE (e.g. 0xF3 and 0xF4) but you want to force it to use
-# one of them (e.g. 0xF4).
-#ACTIVE_SE=0xF3
-
-###############################################################################
-# Configure the default NfcA/IsoDep techology and protocol route. Can be
-# either a secure element (e.g. 0xF4) or the host (0x00)
-#DEFAULT_ISODEP_ROUTE=0x00
-
-###############################################################################
-# Configure the NFC Extras to open and use a static pipe.  If the value is
-# not set or set to 0, then the default is use a dynamic pipe based on a
-# destination gate (see NFA_HCI_DEFAULT_DEST_GATE).  Note there is a value
-# for each UICC (where F3="UICC0" and F4="UICC1")
-#NFA_HCI_STATIC_PIPE_ID_F3=0x70
-#NFA_HCI_STATIC_PIPE_ID_01=0x19
-NFA_HCI_STATIC_PIPE_ID_C0=0x19
-###############################################################################
-# When disconnecting from Oberthur secure element, perform a warm-reset of
-# the secure element to deselect the applet.
-# The default hex value of the command is 0x3.  If this variable is undefined,
-# then this feature is not used.
-#OBERTHUR_WARM_RESET_COMMAND=0x03
-
-###############################################################################
 # Force UICC to only listen to 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
 UICC_LISTEN_TECH_MASK=0x07
 
 ###############################################################################
-# Force HOST listen feature enable or disable.
-# 0: Disable
-# 1: Enable
-HOST_LISTEN_ENABLE=0x01
-
-###############################################################################
-# Enabling/Disabling Forward functionality
-# Disable           0x00
-# Enable            0x01
-NXP_FWD_FUNCTIONALITY_ENABLE=0x01
-
-###############################################################################
-# Allow UICC to be powered off if there is no traffic.
-# Timeout is in ms. If set to 0, then UICC will not be powered off.
-#UICC_IDLE_TIMEOUT=30000
-UICC_IDLE_TIMEOUT=0
-
-###############################################################################
 # AID for Empty Select command
 # If specified, this AID will be substituted when an Empty SELECT command is
 # detected.  The first byte is the length of the AID.  Maximum length is 16.
 AID_FOR_EMPTY_SELECT={08:A0:00:00:01:51:00:00:00}
 
 ###############################################################################
-# This setting allows you to disable registering the T4t Virtual SE that causes
-# the NFCC to send PPSE requests to the DH.
-# The default setting is enabled (i.e. T4t Virtual SE is registered).
-#REGISTER_VIRTUAL_SE=1
-
-###############################################################################
 # When screen is turned off, specify the desired power state of the controller.
 # 0: power-off-sleep state; DEFAULT
 # 1: full-power state
@@ -182,120 +26,6 @@
 SCREEN_OFF_POWER_STATE=1
 
 ###############################################################################
-# Firmware patch file
-#  If the value is not set then patch download is disabled.
-#FW_PATCH="/vendor/firmware/bcm2079x_firmware.ncd"
-
-###############################################################################
-# Firmware pre-patch file (sent before the above patch file)
-#  If the value is not set then pre-patch is not used.
-#FW_PRE_PATCH="/vendor/firmware/bcm2079x_pre_firmware.ncd"
-
-###############################################################################
-# Firmware patch format
-#   1 = HCD
-#   2 = NCD (default)
-#NFA_CONFIG_FORMAT=2
-
-###############################################################################
-# SPD Debug mode
-#  If set to 1, any failure of downloading a patch will trigger a hard-stop
-#SPD_DEBUG=0
-
-###############################################################################
-# SPD Max Retry Count
-#  The number of attempts to download a patch before giving up (defualt is 3).
-#  Note, this resets after a power-cycle.
-#SPD_MAX_RETRY_COUNT=3
-
-###############################################################################
-# transport driver
-#
-# TRANSPORT_DRIVER=<driver>
-#
-#  where <driver> can be, for example:
-#    "/dev/ttyS"        (UART)
-#    "/dev/bcmi2cnfc"   (I2C)
-#    "hwtun"            (HW Tunnel)
-#    "/dev/bcmspinfc"   (SPI)
-#    "/dev/btusb0"      (BT USB)
-#TRANSPORT_DRIVER="/dev/bcm2079x-i2c"
-
-###############################################################################
-# power control driver
-# Specify a kernel driver that support ioctl commands to control NFC_EN and
-# NFC_WAKE gpio signals.
-#
-# POWER_CONTRL_DRIVER=<driver>
-#  where <driver> can be, for example:
-#    "/dev/nfcpower"
-#    "/dev/bcmi2cnfc"   (I2C)
-#    "/dev/bcmspinfc"   (SPI)
-#    i2c and spi driver may be used to control NFC_EN and NFC_WAKE signal
-#POWER_CONTROL_DRIVER="/dev/bcm2079x-i2c"
-
-###############################################################################
-# I2C transport driver options
-# Mako does not support 10-bit I2C addresses
-# Revert to 7-bit address
-#BCMI2CNFC_ADDRESS=0x77
-
-###############################################################################
-# I2C transport driver try to read multiple packets in read() if data is available
-# remove the comment below to enable this feature
-#READ_MULTIPLE_PACKETS=1
-
-###############################################################################
-# SPI transport driver options
-#SPI_NEGOTIATION={0A:F0:00:01:00:00:00:FF:FF:00:00}
-
-###############################################################################
-# UART transport driver options
-#
-# PORT=1,2,3,...
-# BAUD=115200, 19200, 9600, 4800,
-# DATABITS=8, 7, 6, 5
-# PARITY="even" | "odd" | "none"
-# STOPBITS="0" | "1" | "1.5" | "2"
-
-#UART_PORT=2
-#UART_BAUD=115200
-#UART_DATABITS=8
-#UART_PARITY="none"
-#UART_STOPBITS="1"
-
-###############################################################################
-# Insert a delay in microseconds per byte after a write to NFCC.
-# after writing a block of data to the NFCC, delay this an amopunt of time before
-# writing next block of data.  the delay is calculated as below
-#   NFC_WRITE_DELAY * (number of byte written) / 1000 milliseconds
-# e.g. after 259 bytes is written, delay (259 * 20 / 1000) 5 ms before next write
-#NFC_WRITE_DELAY=20
-
-###############################################################################
-# Maximum Number of Credits to be allowed by the NFCC
-#   This value overrides what the NFCC specifices allowing the host to have
-#   the control to work-around transport limitations.  If this value does
-#   not exist or is set to 0, the NFCC will provide the number of credits.
-MAX_RF_DATA_CREDITS=1
-
-###############################################################################
-# Default poll duration (in ms)
-#  The defualt is 500ms if not set (see nfc_target.h)
-#NFA_DM_DISC_DURATION_POLL=333
-
-###############################################################################
-# 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
-# 5  NFA_RW_PRES_CHK_ISO_DEP_NAK; Type - 4 tag protocol iso-dep nak presence check
-#    command is sent waiting for rsp and ntf.
-PRESENCE_CHECK_ALGORITHM=5
-
-###############################################################################
 # 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 |
@@ -331,7 +61,6 @@
 # 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.
-
 # Maximum EE supported number
 # NXP PN547C2 0x02
 # NXP PN65T 0x03
@@ -340,49 +69,9 @@
 NFA_MAX_EE_SUPPORTED=0x02
 
 ###############################################################################
-# NCI Hal Module name
-NCI_HAL_MODULE="nfc_nci"
-
-##############################################################################
-# Deactivate notification wait time out in seconds used in ETSI Reader mode
-# 0 - Infinite wait
-#NFA_DM_DISC_NTF_TIMEOUT=0
-
-###############################################################################
 # 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
-
-###############################################################################
-# Default Secure Element route id
-DEFAULT_OFFHOST_ROUTE=0x02
-
-###############################################################################
-# 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}
-
-###############################################################################
-# Bail out mode
-#  If set to 1, NFCC is using bail out mode for either Type A or Type B poll.
-NFA_POLL_BAIL_OUT_MODE=0x01
-###############################################################################
-# Enable/Disable Block Route feature.
-# Block Route will restrict routing to first matched rule
-# Block Route enable   0x01
-# Block Route disable  0x00
-NFA_BLOCK_ROUTE=0x00
-# Extended APDU length for ISO_DEP
-ISO_DEP_MAX_TRANSCEIVE=0xFEFF
diff --git a/sepolicy/vendor/hal_nfc_default.te b/sepolicy/vendor/hal_nfc_default.te
index 3044f1d..7367b5a 100644
--- a/sepolicy/vendor/hal_nfc_default.te
+++ b/sepolicy/vendor/hal_nfc_default.te
@@ -1,3 +1,6 @@
 # Data file accesses.
 allow hal_nfc_default nfc_vendor_data_file:dir create_dir_perms;
 allow hal_nfc_default nfc_vendor_data_file:file create_file_perms;
+
+dontaudit hal_nfc_default nxpese_hwservice:hwservice_manager find;
+dontaudit hal_nfc_default nxpnfc_hwservice:hwservice_manager add;
diff --git a/sepolicy/vendor/hwservice.te b/sepolicy/vendor/hwservice.te
index 4e13ddb..18fbc44 100644
--- a/sepolicy/vendor/hwservice.te
+++ b/sepolicy/vendor/hwservice.te
@@ -3,3 +3,5 @@
 type vnd_atcmdfwd_hwservice, hwservice_manager_type;
 type hal_imsrtp_hwservice, hwservice_manager_type;
 type hal_ipacm_hwservice, hwservice_manager_type;
+type nxpnfc_hwservice, hwservice_manager_type;
+type nxpese_hwservice, hwservice_manager_type;
diff --git a/sepolicy/vendor/hwservice_contexts b/sepolicy/vendor/hwservice_contexts
index 89f7510..50ab774 100644
--- a/sepolicy/vendor/hwservice_contexts
+++ b/sepolicy/vendor/hwservice_contexts
@@ -8,3 +8,5 @@
 android.hardware.tetheroffload.control::IOffloadControl         u:object_r:hal_tetheroffload_hwservice:s0
 com.quicinc.cne.api::IApiService                                u:object_r:hal_cne_hwservice:s0
 com.quicinc.cne.server::IServer                                 u:object_r:hal_cne_hwservice:s0
+vendor.nxp.nxpnfc::INxpNfc                                      u:object_r:nxpnfc_hwservice:s0
+vendor.nxp.nxpese::INxpEse                                      u:object_r:nxpese_hwservice:s0