Граф коммитов

182 Коммитов

Автор SHA1 Сообщение Дата
Chris Gunn 88c9d92185 Adding support for ETSI12.
(Changes provided by NXP.)
2017-07-24 16:16:07 -07:00
Chris Gunn 184c6dc59f Adding LibNFC changes to support eSE.
(Changes provided by NXP.)
2017-07-24 16:16:07 -07:00
Chris Gunn e0ae9d605e Add support for SE wired mode to the NFC Class Extension.
1. Remove 'phLibNfc_SE_ActModeApdu' value from '', as it doesn't do
anything.

2. Delete the 'phLibNfc_SE_LowPowerMode_t' enum. This enum is not used
in LibNFC, so it has no business being part of that lib.

3. Add the ability to turn on/off wired mode for the SE. This includes
ensuring the SE is enabled if either wired mode or Card Emulation is
enabled. And disabling the SE otherwise.
2017-07-24 16:16:07 -07:00
Ivan Cherniukh 3c6e25d0ec Fix issue that blocks USB NFC Controller from entering D2 low power mode. 2017-07-24 15:32:13 -07:00
cwize1 59cf58b062 Ensure the correct ATR is returned from the smartcard interface. (#26)
The ATR of a NFC tag can be provided during different stages of the NFC
discovery sequence, depending on the type of tag being read. Currently
NfcCx only ever caches ATRs retrieved during device discovery. This
change ensures that NfcCx also caches ATRs retrieved during device
connect.
2017-07-03 11:33:00 -07:00
pchaisson 42df60bc12 Fix Type 1 tag CC version check (#25)
When attempting to write and NDEF to a Type 1 (Topaz) tag, the stack is
checking the capability container (CC) version (byte 1) has a value of
0x10 (i.e. version 1.0). However, a type 1 tag could also be version 1.1
or 1.2 at this point in time. A version 1.x tag will be compatible with
a stack using 1.0 features. Therefore, the version check should ignore
minor version and only validate the major version is 1.
2017-06-30 09:55:27 -07:00
Chris Gunn af85357cca Handle STATUS_PENDING status code when calling 'WdfDeviceStopIdle'.
The 'WdfDeviceStopIdle' function returns STATUS_PENDING when the device
is booting up asynchronously. As STATUS_PENDING is a success code (not
an error code) this generally doesn't cause too many problems. However
STATUS_PENDING does have a special meaning in some circumstances. So to
be safe, we should convert it to STATUS_SUCCESS.
2017-06-28 18:09:34 -07:00
Chris Gunn 91d145f8ff Fix PreFast error in NfcCxDTA.cpp. 2017-06-28 18:04:14 -07:00
Chris Gunn 87876bca0f Allow clients to pass FunctionTable smaller then NfcCx exports list.
In order to be backward-compatible with old client drivers which were built
before the new functions (like NfcCxEvtReleaseHardwareControl and
NfcCxEvtReacquireHardwareControl) were introduced to NfcCx, it should allow
to bind to only first FunctionTableCount functions in the NfcCx export list.
In particular, this will change will allow RS1 NFC Client drivers to use
RS2+ NfcCx.dll.
2017-06-28 17:58:36 -07:00
Chris Gunn b0baf5a3ed Allow the NFC radio to turn off if there aren't any pending smartcard
IOCTLs.

Currently the NFC radio is kept on whenever there is an open smartcard
handle. This change changes this to only requiring either a pending
IOCTL or a connected smartcard (i.e. a card in the NFC radio field).

The IOCTLs that are of interest are IS_ABSENT, IS_PRESENT and TRANSMIT.
All the other IOCTLs don't require the NFC radio. In addition, TRANSMIT
already has its own power management logic and this doesn't need to be
changed.

IS_ABSENT and IS_PRESENT used to use a WdfIoQueue to both track the
pending IOCTL requests and to automatically handle request cancelation.
However to be able to be handle power references correctly, without race
conditions, I needed to change this to manually track the requests and
cancelation.

As part of this change, a de-bounce was added to powering down the RF.
This was added to prevent powering on and off the RF quickly within a
short timeframe.

In addition, this change simplifies the way the RF Interface receives
the desired state of the RF from the Power Manager. This was done to
remove race conditions and improve performance.

Miscellanious changes:
- Removed the NCI_POWER_POLICY type, as it was just adding unneccessary
boilerplate.
2017-06-20 17:45:40 -07:00
Chris Gunn 215a625a87 Cleanup Power Manager class.
This change gives the Power Management class its own struct, instead of having all
its variables part of the NFCCX_FDO_CONTEXT. This change also ensures that all
resources owned by the Power Manager class are initialized by the Power Manager
class.
2017-06-20 17:43:14 -07:00
Chris Gunn 9f956d495f Cancel pending callback before closing threadpool work
When RFInterface is deinitializing, there might be pending/running WorkCallbacks in rfInterface->tpTagPrescenceWork. They can continue running after deinitialization in this case.

This change will ensure that there are not running/pending callbacks before CloseThreadpoolWork() call.
2017-06-20 17:40:25 -07:00
Ivan Cherniukh 4adbf5b8f4 Merge pull request #24 from Microsoft/ese-nci20-integration
Ese nci20 integration
2017-06-02 12:18:59 -07:00
Ivan Cherniukh f848ad7525 Fix incorrect handling of data after TLV data 2017-06-02 12:14:55 -07:00
Ivan Cherniukh 11f9a6f891 add delay timer for completing HCI init sequence in NCI2.0 2017-06-02 12:14:27 -07:00
Ivan Cherniukh a16095aae5 whitespaces+invalid character fix 2017-05-24 16:45:18 -07:00
Ivan Cherniukh 96e411d204 improvements to code clearness 2017-05-24 16:42:11 -07:00
Ivan Cherniukh 63922032b0 TLV validation code simplification 2017-05-23 22:27:35 -07:00
Ivan Cherniukh 36132848d6 Extend NFC status success values range to handle MifareClk properly in NCI2.0 2017-05-23 22:18:39 -07:00
Ivan Cherniukh 084d2bebf0 update LibNfc/Nci to treat (pSeHandle == NULL) as a valid state NCI2.0 2017-05-23 22:18:39 -07:00
Christophe Ricard 4bd131584c Once NFCEE initialization is complete reflect eSE_ActivationMode state
Once NFCEE initialization is complete reflect eSE_ActivationMode state so
that in next step of enumeration, the SE is detected as activated.
This will fix the behavior of NfcCxRFInterfaceDisableSecureElements called
during secure elements enumeration where the secure elements states were
not reflected correctly.
2017-05-23 22:18:39 -07:00
Christophe Ricard 585c1fbcb5 Add correct NCI_NFCEE_DISCOVER_CMD support for NCI2.0
No parameter are supported for NFCEE_DISCOVER_CMD in NCI2.0
2017-05-15 18:22:36 -07:00
Christophe Ricard b3e5e422a2 Add support for NCI2.0 NCI_NFCEE_STATUS_NTF
NFCEE_STATUS_NTF is giving indication on the NFCEE.
2 status are giving indication about the NFCEE activation states:
- NFCEE Initialization sequence started
- NFCEE Initialization sequence completed
2017-05-15 18:22:36 -07:00
Christophe Ricard ee261fcf4d Adding NCI_NFCEE_SET_NTF NCI2.0 OID support 2017-05-15 18:22:36 -07:00
Christophe Ricard 95753addb1 Add phLibNfc_HciLaunchDevInitSequenceNci2x function
In NCI2.0, the hci network is now with a static connId.
The Hci initialization sequence Nci 2.0 is different from the Nci 1.0
2017-05-15 18:22:36 -07:00
Christophe Ricard 76ff73a4a1 Improve hci host id to support nci 1.0 and nci 2.0 specification
NCI2.0 brings a different way to manage NFCEE Id. An NFCEE has an
ID defined for NCI and an ID on the HCI network potentially different.
2017-05-15 18:22:36 -07:00
Christophe Ricard bd171a4aa0 Improve the way a TLV length is calculated in a NFCEE_DISCOVER_NTF
In NCI2.0, the TLV length is not exactly the remaining data length after
the supported nfcee protocols. An additional parameter has been added:
NFCEE Power Supply.
2017-05-15 18:22:36 -07:00
Christophe Ricard d5891c77a6 Add TlvInfoLen field in phNciNfc_NfceeDeviceInfo structure 2017-05-15 18:22:36 -07:00
Christophe Ricard 7c68957eba Add phLibNfc_HciOpenAdmPipeNci2x for Nci 2.0 hci network initialization
In NCI2.0, The logical channel for HCI communication is static (it is 1).
2017-05-15 18:22:36 -07:00
Christophe Ricard 0f74563ad0 Rename phLibNfc_HciLaunchDevInitSequence phLibNfc_HciLaunchDevInitSequenceNci1x
A different HCI initialization network sequence might be needed in NCI2.0
2017-05-15 18:22:36 -07:00
Christophe Ricard c8be5f27a7 Update destination information for the static hci connection
Once HCI static connection is created in the NfcCx update with
the handle.
2017-05-15 18:22:36 -07:00
Christophe Ricard 07e5b900e9 NCI2.0: No NFCEE_DISCOVER_NTF is generated for the static HCI network
No NFCEE_DISCOVER_NTF is generated as a consequence no SeHandle with
information about nfcee status, nfceeid are created.

Create a Dummy pSeHandle for next processing.
2017-05-15 18:22:36 -07:00
Christophe Ricard c69222e69b Check pHciContext is correctly allocated before creation
Make sure pHciContext is not null before usage.
2017-05-15 18:22:35 -07:00
Ivan Cherniukh 93c4c6b7f8 Fix bug preventing NFC polling to resume when device wakes from sleep 2017-05-15 17:58:45 -07:00
Ivan Cherniukh 738d2ee491 Protocol selection code style tunes 2017-05-15 17:56:53 -07:00
Ivan Cherniukh 59177d657d Reuse NCI notification timer if it has been created before 2017-05-15 17:47:43 -07:00
Christophe Ricard 059de4e0c7 bugfixes after NCI2.0 implementation commits
* Fix dwNfcTimerId life cycle management

NCI: Handle NCI_RESET_RSP and NCI_RESET_NTF to manage NCI1.x and NCI2.x
ff56ba3701

is introducing a regression in the dwNfcTimerId life cycle management.
Messages like:
- "Deactivate ntf timer start FAILED" or "Timer Create had failed"
in nfc/libs/NfcCoreLib/lib/Nci/phNciNfc_Discovery.c
function phNciNfc_CompleteDeactivate.
- "IsoDep Chk Pres ntf timer start FAILED" or "Timer Create had failed"
in nfc/libs/NfcCoreLib/lib/Nci/phNciNfc.c
function phNciNfc_CompleteIsoDepPresChkSequence.

Are now raised because it is deleted and zeroed improperly. It may give
instable behavior.

* Rework CORE_RESET_NTF Callback (phNciNfc_ResetNtfCb)

This rework fix the way CORE_RESET_NTF is handled.
A CORE_RESET_NTF (in NCI1x or NCI2x) can be raised by the NFC Controller
any time in the NCI state machine (i.e: In case of CLF error, if the NFCC
was powered on (NCI2x), if a CORE_RESET_CMD was received...).
In any case, the overall state machine needs to be resetted (NCI state
machine, IoQueue...).

* Revert "NCI2.0: RF_ISO_DEP_NAK_PRESENCE and CORE_SET_POWER_SUB_STATE_CMD are NCI2.0 command"

This reverts commit 6ea83f8e09.

This will allow IHV to still use NFC_CX_DRIVER_ISODEP_RNAK_PRESENCE_CHK_SUPPORTED
or NFC_CX_DRIVER_RF_ROUTING_POWER_SUB_STATES_SUPPORTED in an accurate way
even if using NCI2.0.
For instance the NCI1.x way of doing the equivalent of an RNAK_PRESENCE_CHK
is also a valid alternative in NCI2.0.

* Add missing NCI2.0 RF_DEACTIVATE_NTF Deactivation Reason

Adding a missing deactivation reasons "DH request failed due to error"
specified in NCI2.0 specification Table 81.

We are following conditions described in 5.2.5 State RFST_POLL_ACTIVE for
"DH request failed due to error" Deactivation Reason

- "In this state the DH MAY send RF_DEACTIVATE_CMD (Sleep Mode or Sleep_AF
Mode) to deactivate communication with the Remote NFC Endpoint.
The NFCC SHALL send RF_DEACTIVATE_RSP with STATUS_OK. Depending on the
activated interface and protocol, the NFCC might need to issue RF commands
to put the Remote NFC Endpoint into sleep state. If there was an error in
executing the protocol deactivation procedures defined by the RF Interface,
the NFCC SHALL notify the DH by sending RF_DEACTIVATE_NTF (Sleep Mode or
Sleep_AF Mode, DH request failed due to error), and the state will remain
RFST_POLL_ACTIVE."

- "In this state the DH MAY send RF_DEACTIVATE_CMD (Idle Mode) to
deactivate communication with the Remote NFC Endpoint and stop RF Discovery.
The NFCC SHALL send RF_DEACTIVATE_RSP with STATUS_OK and, depending on the
activated interface and protocol, might issue RF commands to deactivate the
Remote NFC Endpoint. If there was an error in executing the protocol
deactivation procedures defined by the RF Interface, the NFCC SHALL notify
the DH by sending RF_DEACTIVATE_NTF (Idle Mode, DH request failed due
to error)."

* Fix sequence executed after receiving a DISCOVER_TARGET_ACTIVATION_FAILED error

In NCI1x or NCI2x we can receive
CORE_GENERIC_ERROR_NTF(DISCOVER_TARGET_ACTIVATION_FAILED) in 2 states:
- RFST_DISCOVERY (in this case the current code is fine).
- RFST_W4_HOST_SELECT (in this case the current code does not restart the
polling loop).

Following the 5.2 State machine and the NfcCx commands exchanges when using
a tag (for instance in our tests Mifare Ultralight):

- in RFST_DISCOVERY state: when approching a tag a RF_INTF_ACTIVATED_NTF will
change the current state to RFST_POLL_ACTIVE.

- In RFST_POLL_ACTIVE state: the NfcCx send a RF_DEACTIVATE_CMD(Sleep Mode).
This is changing the state to RFST_W4_HOST_SELECT.

- In RFST_W4_HOST_SELECT: A CORE_GENERIC_ERROR_NTF(DISCOVER_TARGET_ACTIVATION_FAILED)
may happen.
According to 5.2.4:
"If the activation was not successful, the NFCC SHALL send CORE_ERROR_NTF to
the DH with a Status of DISCOVERY_TARGET_ACTIVATION_FAILED and the state will
remain as RFST_W4_HOST_SELECT"
"If the DH sends RF_DEACTIVATE_CMD,
the NFCC SHALL ignore the Deactivation Type parameter, stop the RF Discovery
Process and send RF_DEACTIVATE_RSP. The state will then change to RFST_IDLE."

- In RFST_IDLE: no field is generated until the NCI state machine is change
to RFST_DISCOVERY.

In order to consider both cases we are now sending the NFC controller in
RFST_IDLE state and move to RFST_DISCOVERY with a RF_DISCOVER_CMD.

* Fix event log messages

* Fix PHNFCINFC_CORE_RESET_NTF_MIN_LEN_2x mispelling

Rename PHNFCINFC_CORE_RESET_NTF_MIN_LEN_2x PHNCINFC_CORE_RESET_NTF_MIN_LEN_2x

* Adding comments on conditions when checking CORE_RESET_NTF parameters.

Nci Version is only available in Nci2.0 CORE_RESET_NTF frame.
Furthermore Nci1.x CORE_RESET_NTF frame is only 2 bytes long
(Reason code(1 byte) and Configuration status(1 byte).
We are assuming here that a CORE_RESET_NTF with a size longer
or egal to PHNCINFC_CORE_RESET_NTF_MIN_LEN_2x(5) is a NCI2x frame.

* Adding missing brackets

* Be more explicit when resetting dwNtfTimerId

PH_OSALNFC_TIMER_ID_INVALID is 0, reset the current line so that it is
more explicit to reader.

* Add Warning if dwNtfTimerId != PH_OSALNFC_TIMER_ID_INVALID before phOsalNfc_Timer_Create call

For debug purpose, log a warning message if dwNtfTimerId is not in reset
state (or when dwNtfTimerId != PH_OSALNFC_TIMER_ID_INVALID) before its
creation.
2017-02-07 20:13:19 -08:00
Ivan Cherniukh 9c18ae8f08 Multiprotocol tags support and new attributes: integration, various code optimizations and simplifications 2017-01-17 11:29:41 -08:00
HariomKesh 5267a218eb Multiprotocol tag support & new SCARD_ATTR added 2017-01-17 11:29:41 -08:00
Ivan Cherniukh a057446367 Merge pull request #5 from Microsoft/integration
Integration of NCI2.0 proposed changes
2016-12-19 18:02:16 -08:00
Ivan Cherniukh 46abd3ca0a Tracelogging fixes and minor code style adjustments 2016-12-19 17:56:29 -08:00
Christophe Ricard 3fd8d742ca Added error message in ResetNtfDelayCb in case phNciNfc_GenericSequence ends with an error
For debug purpose, log phNciNfc_GenericSequence error.
2016-12-02 16:37:21 -08:00
Christophe Ricard 574f7bb6ec Handle error case in case phOsalNfc_GetMemory return NULL
Set wStatus to NFCSTATUS_FAILED if phOsalNfc_GetMemory return NULL
2016-12-02 16:37:21 -08:00
Christophe Ricard 09189166b8 NCI2.x: Document PHNCINFC_CORE_RESET_NTF_MIN_LEN
Added details to explain PHNFCNFC_CORE_RESET_NTF_MIN_LEN value including
reference to specification.
2016-12-02 16:37:21 -08:00
Christophe Ricard c650d2d639 NCI2x: Add additionnal comment to explain how bufferred is checked
phNciNfc_TlvUtilsGetNxtTlv used to extract the Rf Interfaces information.
In case of invalid TLV, phNciNfc_TlvUtilsGetNxtTlv will return an error
code.
2016-12-02 16:37:21 -08:00
Christophe Ricard 3eecbfd3a5 NCI1x: Add additionnal check in order to avoid buffer overrun
Check the minimal core init response length + the number of rf interfaces
== pNciContext->RspBuffInfo.wLen.
2016-12-02 16:37:21 -08:00
Christophe Ricard f21e4d9f69 NCI2x: Fix theoritical minimum CORE_INIT_RSP_LEN
Also there was an error in the naming, we changed from
CORE_RESET_RSP_LEN_xxx to CORE_INIT_RSP_LEN_xxx.

Note: PH_NCINFC_MIN_CORE_RESET_RSP_LEN got removed.
2016-12-02 16:37:21 -08:00
Christophe Ricard af1863b2ea NCI1x: Fix theoritical minimum CORE_INIT_RSP_LEN
Also there was an error in the naming, we changed from
CORE_RESET_RSP_LEN_xxx to CORE_INIT_RSP_LEN_xxx.

Note: PH_NCINFC_MIN_CORE_RESET_RSP_LEN is kept to keep the compiler happy
and will be removed when add the equivalent macro for NCI2x.
2016-12-02 16:37:21 -08:00
Christophe Ricard 23914f97db Return NFCSTATUS_INVALID_PARAMETER in case the NCI version in invalid 2016-12-02 16:37:21 -08:00
Christophe Ricard 5d2508f47b NCI2.0: make sure that the HCI network context is created
As the HCI connection id is static in NCI2.0, make sure to create and
configure its related context
2016-12-02 16:37:21 -08:00