├── Cx ├── NfcCxPch.cpp ├── NfcCx │ ├── common.props │ └── Readme.txt ├── NfcCxTraceLogging.h ├── NfcCxSNEP.h ├── NfcCxSCPresentAbsentDispatcher.h ├── NfcCxSCCommon.h ├── NfcCxLLCP.h ├── NfcCxSequence.h ├── device.h └── NfcCxTml.h ├── libs ├── NfcCoreLib │ ├── inc │ │ ├── phNfcConfig.h │ │ ├── phNfcHalTypes2.h │ │ ├── phLibNfc_ioctl.h │ │ ├── phNfcCompId.h │ │ └── phNfcLlcpTypes.h │ └── lib │ │ ├── Fri │ │ ├── phFriNfc_MapTools.c │ │ ├── phFriNfc_FelicaMap.c │ │ ├── phFriNfc_LlcpMacNfcip.h │ │ ├── phFriNfc_ISO15693Format.h │ │ ├── phFriNfc_TopazFormat.h │ │ ├── phFriNfc_IntNdefMap.h │ │ ├── phFriNfc_Pch.h │ │ ├── phFriNfc_LlcpTransport_Connectionless.h │ │ ├── phFriNfc_MapTools.h │ │ └── phFriNfc_SnepProtocolUtility.h │ │ ├── LibNfc │ │ ├── phHciNfc_Pipe.h │ │ ├── phLibNfc_Init.h │ │ ├── phLibNfc_Deactivate.h │ │ ├── phLibNfc_Iso15693.h │ │ ├── phLibNfc_Initiator.h │ │ ├── phLibNfc_Type1Tag.h │ │ ├── phHciNfc_CoreRxMemMgr.h │ │ ├── phLibNfc_Target.h │ │ ├── phLibNfc_CeHost.h │ │ ├── phLibNfc_IoctlUtils.h │ │ ├── phLibNfc_Hci.h │ │ ├── phLibNfc_Deactivate.c │ │ ├── phLibNfc_Llcp.h │ │ ├── phLibNfc_ndef_raw.h │ │ ├── phLibNfc_Sequence.h │ │ ├── phLibNfc_Discovery.h │ │ ├── phLibNfc_Pch.h │ │ ├── phLibNfc_Se.h │ │ └── phLibNfc_ContextMgmt.h │ │ ├── Nci │ │ ├── phNciNfc_Common.h │ │ ├── phNciNfc_Init.h │ │ ├── phNciNfc_ListenIsoDep.h │ │ ├── phNciNfc_RFReaderB.h │ │ ├── phNciNfc_RFReaderA.h │ │ ├── phNciNfc_PollMgmt.h │ │ ├── phNciNfc_RFReader4A.h │ │ ├── phNciNfc_RFReaderMifare.h │ │ ├── phNciNfc_RFReader4B.h │ │ ├── phNciNfc_RFReaderIso15693.h │ │ ├── phNciNfc_Jewel.h │ │ ├── phNciNfc_ListenMgmt.h │ │ ├── phNciNfc_ListenNfcDep.h │ │ ├── phNciNfc_Utils.h │ │ ├── phNciNfc_PollNfcDep.h │ │ ├── phNciNfc_LogicalConn.h │ │ ├── phNciNfc_Sequence.h │ │ ├── phNciNfc_NfcIMgmt.h │ │ ├── phNciNfc_RFReader.h │ │ ├── phNciNfc_PollMgmt.c │ │ ├── phNciNfc_Pch.h │ │ ├── phNciNfc_RFReaderFelica.h │ │ ├── phNciNfc_Context.c │ │ ├── phNciNfc_ListenIsoDep.c │ │ └── phNciNfc_NfceeMgmt.h │ │ ├── Osal │ │ ├── phOsalNfc_Pch.h │ │ ├── NfcCoreOsal │ │ │ └── NfcCoreOsal.vcxproj.filters │ │ └── phOsalNfc_Internal.h │ │ └── NciCore │ │ ├── phNciNfc_CoreMemMgr.h │ │ ├── phNciNfc_CoreUtils.h │ │ ├── phNciNfc_CorePch.h │ │ ├── phNciNfc_State.h │ │ ├── phNciNfc_CoreRecvMgr.h │ │ ├── phNciNfc_CoreSend.h │ │ └── phNciNfc_CoreRecv.h ├── NciParsers │ ├── NciParsersLibPch.h │ └── NciParsers │ │ └── NciParsers.vcxproj.filters ├── Proximity │ └── lib │ │ ├── Pch.h │ │ └── NfcProximity │ │ └── NfcProximity.vcxproj.filters └── SmartCard │ ├── lib │ ├── Pch.h │ └── NfcSmartCard │ │ └── NfcSmartCard.vcxproj.filters │ └── inc │ └── StorageClassLoadKey.h ├── Test ├── NfcCxTestDeviceDriver │ └── Driver │ │ ├── NfcCxTestDeviceDriver.inf │ │ ├── Precomp.h │ │ ├── NfcCxTestDeviceDriver.rc │ │ ├── NfcCxTestDeviceDriver.vcxproj.filters │ │ ├── FileObject.h │ │ ├── Trace.h │ │ ├── Driver.cpp │ │ ├── ApiCallbacksManager.h │ │ └── Device.h ├── NfcCxTests │ ├── SimulationSequences │ │ ├── Precomp.h │ │ ├── RfDiscoverySequences.h │ │ ├── Type5TagSequences.h │ │ ├── TagSequences.h │ │ └── InitSequences.h │ ├── Simulation │ │ ├── TagPayloads.h │ │ ├── Precomp.h │ │ ├── NciPacket.cpp │ │ ├── TagPayloads.cpp │ │ ├── ApduSamples.h │ │ ├── NciDataPacket.h │ │ ├── TestDeviceInstall.h │ │ ├── NciPacket.h │ │ ├── VerifyHelpers.h │ │ ├── NciControlPacket.h │ │ ├── ApduOverNciHciGenerator.h │ │ ├── ApduSamples.cpp │ │ ├── SimSequenceView.cpp │ │ ├── NciDataPacket.cpp │ │ ├── SimSequenceView.h │ │ ├── VerifyHelpers.cpp │ │ ├── SimSequenceRunner.h │ │ ├── SimSequenceStep.h │ │ ├── NciControlPacket.cpp │ │ ├── SimSequenceStep.cpp │ │ ├── NciSimConnector.h │ │ └── TestDeviceInstall.cpp │ ├── Tests │ │ ├── Precomp.h │ │ ├── TestLogging.h │ │ ├── TestLogging.cpp │ │ └── Module.h │ └── IOHelpers │ │ ├── Precomp.h │ │ ├── SmartcardIo.h │ │ ├── RadioManager.h │ │ ├── UniqueHandle.h │ │ ├── DriverHandleFactory.h │ │ ├── UniqueHandle.cpp │ │ ├── IoOperation.h │ │ ├── DeviceQuery.h │ │ ├── SmartcardIo.cpp │ │ ├── RadioManager.cpp │ │ ├── DriverHandleFactory.cpp │ │ └── IoOperation.cpp └── README.md ├── inc ├── NciParsersLib.h ├── NfcRadioDev.h └── WdfCxProxy.h ├── license.txt ├── README.md └── SECURITY.md /Cx/NfcCxPch.cpp: -------------------------------------------------------------------------------- 1 | #include "NfcCxPch.h" 2 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/inc/phNfcConfig.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/NFC-Class-Extension-Driver/HEAD/libs/NfcCoreLib/inc/phNfcConfig.h -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Fri/phFriNfc_MapTools.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/NFC-Class-Extension-Driver/HEAD/libs/NfcCoreLib/lib/Fri/phFriNfc_MapTools.c -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phHciNfc_Pipe.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/NFC-Class-Extension-Driver/HEAD/libs/NfcCoreLib/lib/LibNfc/phHciNfc_Pipe.h -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_Common.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/NFC-Class-Extension-Driver/HEAD/libs/NfcCoreLib/lib/Nci/phNciNfc_Common.h -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Fri/phFriNfc_FelicaMap.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/NFC-Class-Extension-Driver/HEAD/libs/NfcCoreLib/lib/Fri/phFriNfc_FelicaMap.c -------------------------------------------------------------------------------- /Test/NfcCxTestDeviceDriver/Driver/NfcCxTestDeviceDriver.inf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/NFC-Class-Extension-Driver/HEAD/Test/NfcCxTestDeviceDriver/Driver/NfcCxTestDeviceDriver.inf -------------------------------------------------------------------------------- /Test/NfcCxTests/SimulationSequences/Precomp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #define WIN32_NO_STATUS 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/TagPayloads.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | struct TagPayloads 11 | { 12 | // NDEF message for http://www.bing.com 13 | static const uint8_t NdefBingUri[13]; 14 | }; 15 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/Precomp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #define WIN32_NO_STATUS 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_Init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phLibNfc_Sequence.h" 10 | 11 | extern 12 | phLibNfc_Sequence_t gphLibNfc_InitializeSequence[]; 13 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_Deactivate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phLibNfc_Sequence.h" 10 | 11 | extern 12 | phLibNfc_Sequence_t gphLibNfc_DeactivateSequence[]; 13 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_Iso15693.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phLibNfc_Sequence.h" 10 | 11 | extern 12 | phLibNfc_Sequence_t gphLibNfc_Iso15693GetSysInfoSeq[]; 13 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_Initiator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfcTypes.h" 10 | 11 | void phLibNfc_P2pConfigParamsCb(void* pContext,NFCSTATUS status,void* pInfo); 12 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Tests/Precomp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #define WIN32_NO_STATUS 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/inc/phNfcHalTypes2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/NciPacket.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include "NciPacket.h" 8 | 9 | const void* NciPacket::PacketBytes() const 10 | { 11 | return static_cast(&_NciPacket); 12 | } 13 | 14 | uint32_t NciPacket::PacketBytesLength() const 15 | { 16 | return _NciPacketLength; 17 | } 18 | -------------------------------------------------------------------------------- /Test/NfcCxTests/IOHelpers/Precomp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #define WIN32_NO_STATUS 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_Init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | extern phNciNfc_SequenceP_t gphNciNfc_InitSequence[]; 12 | extern phNciNfc_SequenceP_t gphNciNfc_ReleaseSequence[]; 13 | extern phNciNfc_SequenceP_t gphNciNfc_NfccResetSequence[]; 14 | -------------------------------------------------------------------------------- /Test/NfcCxTestDeviceDriver/Driver/Precomp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #include "Trace.h" 22 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/TagPayloads.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include "TagPayloads.h" 8 | 9 | // NFC Forum, NFC Data Exchange Format (NDEF), Version 1.0, Section 3 10 | // NFC Forum, URI Record Type Definition, Version 1.0, Section 3 11 | const uint8_t TagPayloads::NdefBingUri[13] = { 0xD1, 0x01, 0x09, 0x55, 0x01, 0x62, 0x69, 0x6E, 0x67, 0x2E, 0x63, 0x6F, 0x6D }; 12 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Fri/phFriNfc_LlcpMacNfcip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | NFCSTATUS 15 | phFriNfc_LlcpMac_Nfcip_Register( 16 | _Inout_ phFriNfc_LlcpMac_t *LlcpMac 17 | ); 18 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_ListenIsoDep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | extern 10 | NFCSTATUS 11 | phNciNfc_NfcIsoLstnRdrInit( 12 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 13 | uint8_t *pBuff, 14 | uint16_t wLen 15 | ); 16 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_RFReaderB.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfcTypes.h" 10 | 11 | extern NFCSTATUS 12 | phNciNfc_RdrBInit( 13 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 14 | uint8_t *pBuff, 15 | uint16_t wLen 16 | ); 17 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_RFReaderA.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfcTypes.h" 10 | 11 | extern 12 | NFCSTATUS 13 | phNciNfc_RdrAInit( 14 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 15 | uint8_t *pBuff, 16 | uint16_t wLen 17 | ); 18 | -------------------------------------------------------------------------------- /Cx/NfcCx/common.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(SolutionDir)..\..\ 5 | 6 | 7 | $(RootDir)$(Platform)\$(Configuration)\ 8 | $(Platform)\$(Configuration)\ 9 | false 10 | 11 | 12 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_Type1Tag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phLibNfc_Sequence.h" 10 | 11 | #define PHLIBNFC_RID_RESP_LEN (0x06) /** Length of RID Response from NFCC */ 12 | #define PHLIBNFC_UID_LEN (0x04) /** Length of UID of Type 1 Tag from NFCC */ 13 | 14 | extern 15 | phLibNfc_Sequence_t gphLibNfc_T1tGetUidSequence[]; 16 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Fri/phFriNfc_ISO15693Format.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | void 10 | phFriNfc_ISO15693_FmtReset ( 11 | phFriNfc_sNdefSmtCrdFmt_t *psNdefSmtCrdFmt); 12 | 13 | NFCSTATUS 14 | phFriNfc_ISO15693_Format ( 15 | phFriNfc_sNdefSmtCrdFmt_t *psNdefSmtCrdFmt); 16 | 17 | void 18 | phFriNfc_ISO15693_FmtProcess ( 19 | void *pContext, 20 | NFCSTATUS Status); 21 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_PollMgmt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfcTypes.h" 10 | #include "phNciNfc.h" 11 | 12 | extern 13 | NFCSTATUS 14 | phNciNfc_PollMgmt( 15 | void *psContext, 16 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 17 | uint8_t *pBuff, 18 | uint16_t wLen 19 | ); 20 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/ApduSamples.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | struct ApduSamples 11 | { 12 | static const uint8_t GetDataCommand[5]; 13 | static const uint8_t GetDataResponse[11]; 14 | 15 | // A pseduo command/response that tests extended APDUs 16 | static std::vector GenerateExtendedApduCommand(uint16_t payloadLength); 17 | static std::vector GenerateExtendedApduResponse(uint32_t payloadLength); 18 | }; 19 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_RFReader4A.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNfcTypes.h" 10 | 11 | extern 12 | NFCSTATUS 13 | phNciNfc_Send4AData( 14 | void *psContext 15 | ); 16 | 17 | extern 18 | NFCSTATUS 19 | phNciNfc_Recv4AResp( 20 | void *psContext, 21 | NFCSTATUS wStatus 22 | ); 23 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_RFReaderMifare.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNfcTypes.h" 10 | 11 | extern 12 | NFCSTATUS 13 | phNciNfc_SendMfReq( 14 | void *psContext 15 | ); 16 | 17 | 18 | extern 19 | NFCSTATUS 20 | phNciNfc_RecvMfResp( 21 | void *psContext, 22 | NFCSTATUS wStatus 23 | ); 24 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_RFReader4B.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNfcTypes.h" 10 | 11 | extern 12 | NFCSTATUS 13 | phNciNfc_Send4BData( 14 | void *psContext 15 | ); 16 | 17 | extern 18 | NFCSTATUS 19 | phNciNfc_Recv4BResp( 20 | void *psContext, 21 | NFCSTATUS wStatus 22 | ); 23 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Tests/TestLogging.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #define LOG_COMMENT(fmt, ...) ::WEX::Logging::Log::Comment(::WEX::Common::String().Format(fmt, __VA_ARGS__)) 8 | #define LOG_ERROR(fmt, ...) ::WEX::Logging::Log::Error(::WEX::Common::String().Format(fmt, __VA_ARGS__)) 9 | #define VERIFY_FAIL_MSG(fmt, ...) VERIFY_FAIL(::WEX::Common::String().Format(fmt, __VA_ARGS__)) 10 | 11 | void LogByteBuffer( 12 | _In_ PCWSTR bufferName, 13 | _In_reads_bytes_(bufferLength) const void* buffer, 14 | _In_ size_t bufferLength); 15 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phHciNfc_CoreRxMemMgr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | extern pphHciNfc_sCoreRecvBuff_List_t 10 | phHciNfc_CoreGetNewNode(phHciNfc_HciCoreContext_t *pCoreCtx, 11 | uint16_t wLenOfPkt); 12 | 13 | extern NFCSTATUS 14 | phHciNfc_HciCoreExtractData(phHciNfc_HciCoreContext_t *pCoreCtx, 15 | phHciNfc_ReceiveParams_t *pHciNfcRxdParams); 16 | 17 | extern void phHciNfc_CoreDeleteList(phHciNfc_HciCoreContext_t *pCoreCtx); 18 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_RFReaderIso15693.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfcTypes.h" 10 | 11 | extern NFCSTATUS 12 | phNciNfc_RdrIso15693Init(pphNciNfc_RemoteDevInformation_t pRemDevInf, 13 | uint8_t *pBuff, 14 | uint16_t wLen); 15 | 16 | extern NFCSTATUS 17 | phNciNfc_Iso15693Send(void *psContext); 18 | 19 | extern NFCSTATUS 20 | phNciNfc_Iso15693Receive(void *psContext, 21 | NFCSTATUS wStatus); 22 | 23 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_Jewel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNfcTypes.h" 10 | 11 | extern 12 | NFCSTATUS 13 | phNciNfc_JewelInit(uint8_t *pSensRes); 14 | 15 | extern 16 | NFCSTATUS 17 | phNciNfc_SendJewelReq( 18 | void *psContext 19 | ); 20 | 21 | extern 22 | NFCSTATUS 23 | phNciNfc_RecvJewelResp( 24 | void *psContext, 25 | NFCSTATUS wStatus 26 | ); 27 | -------------------------------------------------------------------------------- /Test/NfcCxTests/IOHelpers/SmartcardIo.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | #include "AsyncTask.h" 11 | 12 | struct IoApduResult 13 | { 14 | DWORD ErrorCode = ERROR_SUCCESS; 15 | std::vector ApduResponse; 16 | }; 17 | 18 | class SmartcardIo 19 | { 20 | public: 21 | static std::shared_ptr<::Async::AsyncTaskBase> SendApdu( 22 | _In_ HANDLE smartcardInterface, 23 | _In_reads_bytes_(apduCommandLength) const void* apduCommand, 24 | _In_ DWORD apduCommandLength, 25 | _In_ DWORD apduResponseLength); 26 | }; 27 | -------------------------------------------------------------------------------- /Test/NfcCxTestDeviceDriver/Driver/NfcCxTestDeviceDriver.rc: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | // NfcCx.rc 3 | // 4 | // Copyright (c) Microsoft Corporation, All Rights Reserved 5 | //--------------------------------------------------------------------------- 6 | 7 | #include 8 | #include 9 | 10 | #define VER_FILETYPE VFT_DLL 11 | #define VER_FILESUBTYPE VFT_UNKNOWN 12 | #define VER_FILEDESCRIPTION_STR "NFC CX Test Device Driver" 13 | #define VER_INTERNALNAME_STR "NfcCxTestDeviceDriver" 14 | #define VER_ORIGINALFILENAME_STR "NfcCxTestDeviceDriver.dll" 15 | 16 | #include "common.ver" 17 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/inc/phLibNfc_ioctl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | /** 12 | * \ingroup grp_lib_ioctl 13 | * \brief Allows to enable DTA mode. 14 | */ 15 | #define PHLIBNFC_ENABLE_DTA_MODE (0xDAU) 16 | 17 | /** 18 | * \ingroup grp_lib_ioctl 19 | * \brief Allows to disable DTA mode. 20 | */ 21 | #define PHLIBNFC_DISABLE_DTA_MODE (0xDBU) 22 | 23 | /** 24 | * \ingroup grp_lib_ioctl 25 | * \brief Allows RAW access to NFCC. 26 | */ 27 | #define PHLIBNFC_SET_RAW_CONFIG (0xDCU) 28 | 29 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_Target.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfcTypes.h" 10 | 11 | extern NFCSTATUS phLibNfc_Discovered2Recv(void *pContext, void *Param1, void *Param2, void *Param3); 12 | extern NFCSTATUS phLibNfc_Recv2Send(void *pContext, void *Param1, void *Param2, void *Param3); 13 | 14 | /** Send 2 receive function is same as discovered to receive function */ 15 | #define phLibNfc_Send2Recv phLibNfc_Discovered2Recv 16 | #define phLibNfc_SEListen2Send phLibNfc_Recv2Send 17 | #define phLibNfc_SEListen2Recv phLibNfc_Discovered2Recv 18 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Fri/phFriNfc_TopazFormat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include "phFriNfc_SmtCrdFmt.h" 12 | 13 | NFCSTATUS 14 | phFriNfc_TopazFormat_Format(phFriNfc_sNdefSmtCrdFmt_t* NdefSmtCrdFmt); 15 | 16 | void 17 | phFriNfc_TopazFormat_Process(void* Context, 18 | NFCSTATUS Status); 19 | 20 | NFCSTATUS 21 | phFriNfc_TopazDynamicFormat_Format(phFriNfc_sNdefSmtCrdFmt_t* NdefSmtCrdFmt); 22 | 23 | void 24 | phFriNfc_TopazDynamicFormat_Process(void* Context, 25 | NFCSTATUS Status); 26 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_CeHost.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | NFCSTATUS phLibNfc_MapRemoteDevCeHost(phNfc_sIso14443AInfo_t *pNfcAInfo, 16 | pphNciNfc_RemoteDevInformation_t pNciDevInfo); 17 | 18 | /*Register for the callback to receive the first data buffer 19 | Once the first data buffer arrives, the HCE activation is intimated to DH*/ 20 | NFCSTATUS phLibNfc_RegisterForHceActivation(void); 21 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_ListenMgmt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfcTypes.h" 10 | 11 | extern 12 | NFCSTATUS 13 | phNciNfc_ListenMgmt( 14 | void *psContext, 15 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 16 | uint8_t *pBuff, 17 | uint16_t wLen 18 | ); 19 | 20 | extern 21 | void 22 | phNciNfc_ListenMgmt_DeActivate(void* pContext, 23 | pphNciNfc_RemoteDevInformation_t pRemDevInfo); 24 | 25 | extern NFCSTATUS 26 | phNciNfc_ReceiveCb(void* pContext, void *pInfo, NFCSTATUS wStatus); 27 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_ListenNfcDep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNfcTypes.h" 10 | #include "phNciNfc.h" 11 | 12 | extern 13 | NFCSTATUS 14 | phNciNfc_NfcDepLstnRdrAInit( 15 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 16 | uint8_t *pBuff, 17 | uint16_t wLen 18 | ); 19 | 20 | extern 21 | NFCSTATUS 22 | phNciNfc_NfcDepLstnRdrFInit( 23 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 24 | uint8_t *pBuff, 25 | uint16_t wLen 26 | ); 27 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Tests/TestLogging.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include "TestLogging.h" 8 | 9 | void LogByteBuffer( 10 | _In_ PCWSTR bufferName, 11 | _In_reads_bytes_(bufferLength) const void* buffer, 12 | _In_ size_t bufferLength) 13 | { 14 | std::wstring result = bufferName; 15 | result += L": "; 16 | 17 | const uint8_t* bufferAsBytes = reinterpret_cast(buffer); 18 | for (const uint8_t* itr = bufferAsBytes; itr != bufferAsBytes + bufferLength; itr++) 19 | { 20 | WCHAR sz[4]; // provide enough space for "0xXX " strings. 21 | swprintf_s(sz, L"%02X ", *itr); 22 | result += sz; 23 | } 24 | 25 | WEX::Logging::Log::Comment(result.c_str()); 26 | } 27 | -------------------------------------------------------------------------------- /Test/NfcCxTests/IOHelpers/RadioManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include "UniqueHandle.h" 8 | 9 | // Helper class for calling the NFC radio manager driver interface. 10 | class RadioManager 11 | { 12 | public: 13 | RadioManager(_In_ PCWSTR deviceName); 14 | 15 | // Gets the current state of the NFC radio switch. 16 | bool GetNfcRadioState(); 17 | 18 | // Sets the current state of the NFC radio switch. 19 | void SetNfcRadioState(bool enableNfcRadio); 20 | 21 | // Sets the current state of the airplane mode switch. 22 | void SetAirplaneMode(bool enableAirplaneMode); 23 | 24 | private: 25 | void SetRadioState(bool isSystemUpdate, bool enableRadio); 26 | 27 | UniqueHandle _DeviceInterface; 28 | }; 29 | -------------------------------------------------------------------------------- /Test/NfcCxTests/IOHelpers/UniqueHandle.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | // An RAII type for Win32 HANDLEs. 10 | class UniqueHandle 11 | { 12 | public: 13 | UniqueHandle() = default; 14 | UniqueHandle(HANDLE handle); 15 | UniqueHandle(const UniqueHandle& other) = delete; 16 | UniqueHandle(UniqueHandle&& other); 17 | 18 | ~UniqueHandle(); 19 | 20 | UniqueHandle& operator=(const UniqueHandle& other) = delete; 21 | UniqueHandle& operator=(UniqueHandle&& other); 22 | UniqueHandle& operator=(std::nullptr_t); 23 | 24 | void Reset(); 25 | void Reset(HANDLE handle); 26 | HANDLE Release(); 27 | 28 | HANDLE Get(); 29 | 30 | private: 31 | HANDLE _Handle = nullptr; 32 | }; 33 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_IoctlUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | /**< Min length of input buffer */ 12 | #define PHLIBNFC_INPUT_BUFF_MIN_LEN (4U) 13 | 14 | typedef struct 15 | { 16 | void *pCliCntx; /** 10 | #include "phNciNfc.h" 11 | 12 | extern uint8_t phNciNfc_ValidateRfInterface(phNciNfc_RfInterfaces_t eRfInterface); 13 | extern uint8_t phNciNfc_ValidateRfProtocol(phNciNfc_RfProtocols_t eRfProtocol); 14 | extern uint8_t phNciNfc_ValidateRfTechMode(phNciNfc_RfTechMode_t eRfTechmode); 15 | extern NFCSTATUS phNciNfc_ValidateIntfActvdNtf(uint8_t *pNtf, uint16_t bSize); 16 | 17 | extern void phNciNfc_GetRfDevType(uint8_t bRespVal, uint8_t bRespLen, 18 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 19 | phNciNfc_RFDevType_t *pDevType); 20 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/NciDataPacket.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | #include "NciPacket.h" 10 | 11 | // NFC Controller Interface (NCI), Version 1.1, Section 3.4.3, Format of Data Packets 12 | class NciDataPacket : 13 | public NciPacket 14 | { 15 | public: 16 | NciDataPacket( 17 | _In_ uint8_t connectionId, 18 | _In_ std::initializer_list payload); 19 | 20 | NciDataPacket( 21 | _In_ uint8_t connectionId, 22 | _In_ std::initializer_list payload, 23 | _In_ bool packetBoundary); 24 | 25 | NciDataPacket( 26 | _In_ uint8_t connectionId, 27 | _In_reads_(payloadLength) const uint8_t* payload, 28 | _In_ uint8_t payloadLength, 29 | _In_ bool packetBoundary); 30 | }; 31 | -------------------------------------------------------------------------------- /Test/NfcCxTestDeviceDriver/Driver/NfcCxTestDeviceDriver.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Osal/phOsalNfc_Pch.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2012 Microsoft Corporation 4 | 5 | Module Name: 6 | phOsalNfc_Pch.h 7 | 8 | Abstract: 9 | This module contains the precompiled headers for the OSAL component 10 | 11 | Environment: 12 | User mode. 13 | 14 | --*/ 15 | 16 | #pragma once 17 | 18 | #include 19 | #include 20 | #include "phOsalNfc_Internal.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | #include "NfcCoreLibTracing.h" 40 | 41 | _Analysis_mode_(_Analysis_code_type_user_driver_) 42 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/TestDeviceInstall.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | class TestDeviceInstall 13 | { 14 | public: 15 | TestDeviceInstall(); 16 | ~TestDeviceInstall(); 17 | 18 | private: 19 | static void WINAPI DeviceCreatedCallback( 20 | _In_ HSWDEVICE hSwDevice, 21 | _In_ HRESULT CreateResult, 22 | _In_opt_ void* pContext, 23 | _In_opt_ PCWSTR pszDeviceInstanceId); 24 | void DeviceCreated( 25 | _In_ HSWDEVICE hSwDevice, 26 | _In_ HRESULT CreateResult, 27 | _In_opt_ PCWSTR pszDeviceInstanceId); 28 | static void VerifyHresultSucceeded(HRESULT hr); 29 | 30 | HSWDEVICE _Device = nullptr; 31 | std::wstring _DeviceInstanceId; 32 | std::atomic _CreateResult = E_PENDING; 33 | }; 34 | -------------------------------------------------------------------------------- /Cx/NfcCxTraceLogging.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All Rights Reserved 4 | 5 | Module Name: 6 | 7 | NfcCxTraceLogging.h 8 | 9 | Abstract: 10 | 11 | This module defines the trace logging macros for the NfcCx driver 12 | 13 | Environment: 14 | 15 | 16 | --*/ 17 | 18 | #pragma once 19 | 20 | #ifdef TELEMETRY 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define LOG_BUFFER_LENGTH 1024 29 | 30 | // Declare provider 31 | TRACELOGGING_DECLARE_PROVIDER(g_hNfcCxProvider); 32 | 33 | #else 34 | 35 | #define TraceLoggingWrite(hProvider, eventName, ...) 36 | #define TlgAggregateWrite(hProvider, eventName, ...) 37 | #define MICROSOFT_TELEMETRY_ASSERT(_exp) 38 | #define MICROSOFT_TELEMETRY_ASSERT_MSG(_exp, _msg) 39 | 40 | #endif // TELEMETRY 41 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/NciPacket.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | // NFC Controller Interface (NCI), Version 1.1, Section 3.4, Packet Formats 10 | #pragma pack(push,1) 11 | struct NciPacketRaw 12 | { 13 | static constexpr uint32_t HeaderBytes = 2; 14 | static constexpr uint32_t TotalHeaderLength = HeaderBytes + 1; // include 'PayloadLength' byte 15 | static constexpr uint32_t MaxPayloadLength = 255; 16 | static constexpr uint32_t MaxLength = TotalHeaderLength + MaxPayloadLength; 17 | 18 | uint8_t Header[HeaderBytes]; 19 | uint8_t PayloadLength; 20 | uint8_t Payload[MaxPayloadLength]; 21 | }; 22 | #pragma pack(pop) 23 | 24 | class NciPacket 25 | { 26 | public: 27 | const void* PacketBytes() const; 28 | uint32_t PacketBytesLength() const; 29 | 30 | protected: 31 | NciPacketRaw _NciPacket = {}; 32 | uint32_t _NciPacketLength = 0; 33 | }; 34 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/VerifyHelpers.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | #include "NciControlPacket.h" 10 | #include "NciSimConnector.h" 11 | 12 | void VerifyArraysAreEqual( 13 | _In_ PCWSTR name, 14 | _In_reads_bytes_(arrayALength) const void* arrayA, 15 | _In_ size_t arrayALength, 16 | _In_reads_bytes_(arrayBLength) const void* arrayB, 17 | _In_ size_t arrayBLength); 18 | 19 | bool AreArraysEqual( 20 | _In_reads_bytes_(arrayALength) const void* arrayA, 21 | _In_ size_t arrayALength, 22 | _In_reads_bytes_(arrayBLength) const void* arrayB, 23 | _In_ size_t arrayBLength); 24 | 25 | void VerifyProximitySubscribeMessage( 26 | _In_reads_bytes_(ioResultLength) const void* ioResult, 27 | _In_ size_t ioResultLength, 28 | _In_reads_bytes_(expectedMessageLength) const void* expectedMessage, 29 | _In_ size_t expectedMessageLength 30 | ); 31 | -------------------------------------------------------------------------------- /libs/NciParsers/NciParsersLibPch.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Module Name: 6 | 7 | NciParsersLibPch.h 8 | 9 | Abstract: 10 | 11 | This module is the precompiled header for the Nci Parser library. 12 | 13 | --*/ 14 | 15 | #include 16 | 17 | #include "NciDef.h" 18 | #include "NciParsersLib.h" 19 | 20 | // 21 | // 22 | // Define the Control GUID and a DUMMY flag. 23 | // The DUMMY flag is just needed as an entry point into the WPP control 24 | // structures. ETW levels are used instead of WPP flags. 25 | // 9d97cb90-8dee-42b8-b553-d1816be6fb9e 26 | // 27 | #define WPP_CONTROL_GUIDS \ 28 | WPP_DEFINE_CONTROL_GUID( \ 29 | NciParsersTraceControl, (9d97cb90, 8dee, 42b8, b553, d1816be6fb9e), \ 30 | WPP_DEFINE_BIT(DUMMY) \ 31 | ) 32 | 33 | #include "tracecommon.h" -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/NciCore/phNciNfc_CoreMemMgr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include "phNciNfc_Core.h" 12 | 13 | extern void phNciNfc_CoreRemoveLastChainedNode(pphNciNfc_CoreContext_t pCoreCtx); 14 | 15 | extern pphNciNfc_sCoreRecvBuff_List_t phNciNfc_CoreGetNewNode(pphNciNfc_CoreContext_t pCoreCtx); 16 | 17 | extern NFCSTATUS phNciNfc_CoreGetDataLength( 18 | pphNciNfc_CoreContext_t pCoreCtx, 19 | uint16_t *pDataLen, 20 | uint16_t *wNumOfNode 21 | ); 22 | 23 | extern NFCSTATUS phNciNfc_CoreGetData(pphNciNfc_CoreContext_t pCoreCtx, 24 | uint8_t *pBuff, 25 | uint16_t wLen 26 | ); 27 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_PollNfcDep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNfcTypes.h" 10 | #include "phNciNfc.h" 11 | 12 | extern 13 | NFCSTATUS 14 | phNciNfc_P2P_TransceiveSend( 15 | void *psContext 16 | ); 17 | extern NFCSTATUS 18 | phNciNfc_P2P_TransceiveReceive(void *psContext, 19 | NFCSTATUS wStatus); 20 | 21 | extern 22 | NFCSTATUS 23 | phNciNfc_NfcDepPollRdrAInit( 24 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 25 | uint8_t *pBuff, 26 | uint16_t wLen 27 | ); 28 | 29 | extern 30 | NFCSTATUS 31 | phNciNfc_NfcDepPollRdrFInit( 32 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 33 | uint8_t *pBuff, 34 | uint16_t wLen 35 | ); 36 | -------------------------------------------------------------------------------- /inc/NciParsersLib.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2012 Microsoft Corporation 4 | 5 | Module Name: 6 | 7 | NciParsersLib.h 8 | 9 | Abstract: 10 | 11 | NciParsers Library declarations 12 | 13 | Environment: 14 | 15 | User mode 16 | 17 | --*/ 18 | 19 | #pragma once 20 | 21 | // 22 | // All NCI Packets are at least 3 bytes 23 | // 24 | #define NCI_PACKET_HEADER_LENGTH (0x3) 25 | 26 | typedef struct _NCI_PACKET_HEADER { 27 | UCHAR MessageType; 28 | UCHAR PBF; 29 | union { 30 | struct { 31 | UCHAR Gid; 32 | UCHAR Oid; 33 | } ControlPacket; 34 | 35 | struct { 36 | UCHAR ConnId; 37 | } DataPacket; 38 | } Header; 39 | UCHAR PayloadLength; 40 | } NCI_PACKET_HEADER, *PNCI_PACKET_HEADER; 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | BOOLEAN 47 | NciPacketHeaderGetFromBuffer( 48 | _In_bytecount_(BufferLength) PUCHAR Buffer, 49 | _In_ UINT BufferLength, 50 | _Out_ PNCI_PACKET_HEADER NciPacketHeader 51 | ); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_LogicalConn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfc_RFReader.h" 10 | #include "phNciNfc_Core.h" 11 | #include "phNciNfc_Common.h" 12 | 13 | extern 14 | NFCSTATUS 15 | phNciNfc_LogConnInit( 16 | phNciNfc_Context_t *psNciContext 17 | ); 18 | 19 | extern 20 | NFCSTATUS 21 | phNciNfc_LogConnCreate( 22 | void *psContext, 23 | phNciNfc_Dest_Info_t *pDestination, 24 | pphNciNfc_IfNotificationCb_t pNotify, 25 | void *pContext 26 | ); 27 | 28 | extern 29 | NFCSTATUS 30 | phNciNfc_LogConnClose( 31 | void *psContext, 32 | uint8_t bDestId, 33 | phNciNfc_DestType_t tDestType, 34 | pphNciNfc_IfNotificationCb_t pNotify, 35 | void *pContext 36 | ); 37 | 38 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Windows Near Field Communication (NFC) Class Extension Driver 2 | Copyright (c) Microsoft Corporation 3 | All rights reserved. 4 | MIT License 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /Test/NfcCxTestDeviceDriver/Driver/FileObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | class FileObjectContext 8 | { 9 | public: 10 | enum class Type 11 | { 12 | Unknown, 13 | NciSim, 14 | }; 15 | 16 | static void DeviceInit( 17 | _Inout_ PWDFDEVICE_INIT DeviceInit 18 | ); 19 | 20 | Type GetType(); 21 | 22 | private: 23 | static void CreateCallback( 24 | _In_ WDFDEVICE Device, 25 | _In_ WDFREQUEST Request, 26 | _In_ WDFFILEOBJECT FileObject 27 | ); 28 | NTSTATUS Create( 29 | ); 30 | static void CloseCallback( 31 | _In_ WDFFILEOBJECT FileObject 32 | ); 33 | void Close( 34 | ); 35 | static void DestroyCallback( 36 | _In_ WDFOBJECT Object 37 | ); 38 | 39 | FileObjectContext() = default; 40 | ~FileObjectContext() = default; 41 | 42 | WDFFILEOBJECT _FileObject = nullptr; 43 | DeviceContext* _DeviceContext = nullptr; 44 | Type _Type = Type::Unknown; 45 | }; 46 | 47 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FileObjectContext, FileObjectGetContext); 48 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_Hci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | extern void phLibNfc_HciDeInit(void ); 10 | 11 | extern NFCSTATUS phLibNfc_HciSetSessionIdentity(void* pContext,NFCSTATUS status,void* pInfo); 12 | extern NFCSTATUS phLibNfc_HciSetSessionIdentityProc(void* pContext,NFCSTATUS status,void* pInfo); 13 | 14 | extern NFCSTATUS phLibNfc_HciLaunchDevInitSequence(void *pContext); 15 | extern NFCSTATUS phLibNfc_HciLaunchChildDevInitSequence(void *pContext, phLibNfc_SE_Index_t bIndex); 16 | 17 | #define PH_LIBNFC_INCR_DELAY_ESE_DELAY (20) 18 | #define PH_LIBNFC_INCR_DELAY_ESE_DELAY_TIMEOUT (240) 19 | 20 | /** 21 | * \ingroup grp_hci_core 22 | * 23 | * \brief This function shall process events received on a APDU pipe 24 | * 25 | * \param[in] pContext - pointer to the HCI context 26 | * \param[in] wStatus - Receive Status 27 | * \param[in] pInfo - Received data to be read 28 | * \return Nfc status 29 | */ 30 | extern void phHciNfc_ProcessEventsOnApduPipe(void *pContext, NFCSTATUS wStatus, void *pInfo); 31 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/NciControlPacket.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | #include "NciPacket.h" 10 | 11 | // NFC Controller Interface (NCI), Version 1.1, Section 3.4.2, Format of Control Packets 12 | class NciControlPacket : 13 | public NciPacket 14 | { 15 | public: 16 | NciControlPacket( 17 | _In_ uint8_t type, 18 | _In_ uint8_t groupId, 19 | _In_ uint8_t opcodeId); 20 | 21 | NciControlPacket( 22 | _In_ uint8_t type, 23 | _In_ uint8_t groupId, 24 | _In_ uint8_t opcodeId, 25 | _In_ std::initializer_list payload); 26 | 27 | NciControlPacket( 28 | _In_ uint8_t type, 29 | _In_ uint8_t groupId, 30 | _In_ uint8_t opcodeId, 31 | _In_ std::initializer_list payload, 32 | _In_ bool packetBoundary); 33 | 34 | NciControlPacket( 35 | _In_ uint8_t type, 36 | _In_ uint8_t groupId, 37 | _In_ uint8_t opcodeId, 38 | _In_reads_(payloadLength) const uint8_t* payload, 39 | _In_ uint8_t payloadLength, 40 | _In_ bool packetBoundary); 41 | }; 42 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_Deactivate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #include "phLibNfc_Pch.h" 8 | 9 | #include "phLibNfc_Deactivate.h" 10 | #include "phLibNfc_Discovery.h" 11 | 12 | #include "phLibNfc_Deactivate.tmh" 13 | 14 | static NFCSTATUS phLibNfc_DeactivateComplete(void *pContext,NFCSTATUS status,void *pInfo); 15 | 16 | phLibNfc_Sequence_t gphLibNfc_DeactivateSequence[] = { 17 | {&phLibNfc_SendDeactDiscCmd, &phLibNfc_ProcessDeactResp}, 18 | {NULL, &phLibNfc_DeactivateComplete} 19 | }; 20 | 21 | static NFCSTATUS phLibNfc_DeactivateComplete(void *pContext,NFCSTATUS status,void *pInfo) 22 | { 23 | NFCSTATUS wStatus = status; 24 | pphLibNfc_LibContext_t pLibContext = (pphLibNfc_LibContext_t)pContext; 25 | phLibNfc_Event_t TrigEvent = phLibNfc_EventReqCompleted; 26 | 27 | PH_LOG_LIBNFC_FUNC_ENTRY(); 28 | if((NULL != pLibContext) && (NFCSTATUS_FAILED != status)) 29 | { 30 | wStatus = phLibNfc_StateHandler(pContext, TrigEvent, pInfo, NULL, NULL); 31 | } 32 | 33 | PH_LOG_LIBNFC_FUNC_EXIT(); 34 | return wStatus; 35 | } 36 | -------------------------------------------------------------------------------- /libs/NciParsers/NciParsers/NciParsers.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | 23 | 24 | Header Files 25 | 26 | 27 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/NciCore/phNciNfc_CoreUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include "phNciNfc_Core.h" 11 | #include "phNciNfc_CoreStatus.h" 12 | 13 | #define PH_NCINFC_UTILS_PAYLOAD_SIZE_0BYTES (0) 14 | #define PH_NCINFC_UTILS_PAYLOAD_SIZE_1BYTE (1) 15 | #define PH_NCINFC_UTILS_PAYLOAD_SIZE_2BYTES (2) 16 | #define PH_NCINFC_UTILS_PAYLOAD_SIZE_3BYTES (3) 17 | #define PH_NCINFC_UTILS_PAYLOAD_SIZE_4BYTES (4) 18 | 19 | NFCSTATUS phNciNfc_CoreUtilsUpdatePktInfo(pphNciNfc_CoreContext_t pNciCoreCtx, uint8_t *pBuff, 20 | uint16_t wLength); 21 | 22 | extern NFCSTATUS 23 | phNciNfc_CoreUtilsValidateGID( 24 | uint8_t bGID 25 | ); 26 | 27 | extern NFCSTATUS 28 | phNciNfc_CoreUtilsValidateCtrlPktOID( 29 | uint8_t bMT, 30 | uint8_t bGID, 31 | uint8_t bOID 32 | ); 33 | -------------------------------------------------------------------------------- /Test/NfcCxTests/IOHelpers/DriverHandleFactory.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include "AsyncTask.h" 13 | #include "UniqueHandle.h" 14 | 15 | class DriverHandleFactory 16 | { 17 | public: 18 | static std::wstring FindProximityInterfaceForDevice(_In_ PCWSTR deviceName); 19 | static std::wstring FindSmartcardInterfaceForDevice( 20 | _In_ PCWSTR deviceName, 21 | _In_ ::winrt::Windows::Devices::SmartCards::SmartCardReaderKind readerKind); 22 | static UniqueHandle OpenSubscriptionHandle(_In_ PCWSTR deviceName, _In_ PCWSTR messageType); 23 | static UniqueHandle OpenSmartcardHandle( 24 | _In_ PCWSTR deviceName, 25 | _In_ ::winrt::Windows::Devices::SmartCards::SmartCardReaderKind readerKind); 26 | static std::shared_ptr<::Async::AsyncTaskBase> OpenSmartcardHandleAsync( 27 | _In_ PCWSTR deviceName, 28 | _In_ ::winrt::Windows::Devices::SmartCards::SmartCardReaderKind readerKind); 29 | static std::shared_ptr<::Async::AsyncTaskBase> CloseHandleAsync(UniqueHandle&& obj); 30 | }; 31 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Tests/Module.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | #include 10 | 11 | static PCWSTR ProximityServicesNames[] = 12 | { 13 | L"ProximitySvc", 14 | L"SCardSvr", 15 | L"ScDeviceEnum", 16 | L"SEMgrSvc", 17 | L"ShellHWDetection", 18 | }; 19 | 20 | static constexpr size_t ProximityServicesCount = ARRAYSIZE(ProximityServicesNames); 21 | 22 | struct ServiceState 23 | { 24 | SC_HANDLE ServiceHandle; 25 | DWORD StartType; 26 | }; 27 | 28 | class Module 29 | { 30 | public: 31 | bool Setup(); 32 | bool Cleanup(); 33 | 34 | private: 35 | bool StopAndDisableServices(); 36 | void ResumeServices(); 37 | bool GetServiceConfig(_In_ SC_HANDLE serviceHandle, _Inout_ std::unique_ptr* config); 38 | bool ChangeServiceStartType( 39 | _In_ SC_HANDLE serviceHandle, 40 | _In_ DWORD startType); 41 | bool StopService(_In_ SC_HANDLE serviceHandle); 42 | 43 | SC_HANDLE _SCManager = nullptr; 44 | ServiceState _ServiceStateCache[ProximityServicesCount]; 45 | std::optional _TestDeviceInstall; 46 | }; 47 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/ApduOverNciHciGenerator.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "NciHciDataPacket.h" 12 | #include "SimSequenceStep.h" 13 | 14 | class ApduOverNciHciGenerator 15 | { 16 | public: 17 | static std::vector CreateCommandSequence( 18 | _In_ PCWSTR name, 19 | _In_ uint8_t connectionId, 20 | _In_ uint8_t pipeId, 21 | _In_reads_bytes_(apduCommandLength) const void* apduCommand, 22 | _In_ DWORD apduCommandLength); 23 | 24 | static std::vector CreateResponseSequence( 25 | _In_ PCWSTR name, 26 | _In_ uint8_t connectionId, 27 | _In_ uint8_t pipeId, 28 | _In_reads_bytes_(apduResponseLength) const void* apduResponse, 29 | _In_ DWORD apduResponseLength); 30 | 31 | private: 32 | static std::vector CreateSequence( 33 | _In_ PCWSTR name, 34 | _In_ uint8_t connectionId, 35 | _In_ uint8_t pipeId, 36 | _In_ bool isCommand, 37 | _In_reads_bytes_(apduLength) const void* apdu, 38 | _In_ DWORD apduLength); 39 | }; 40 | -------------------------------------------------------------------------------- /libs/Proximity/lib/Pch.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Module Name: 6 | 7 | Pch.h 8 | 9 | Abstract: 10 | 11 | This module is the precompiled header for the proximity library 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | // 25 | // LibNfc Headers 26 | // 27 | extern "C" { 28 | #include 29 | #include 30 | #include 31 | } 32 | 33 | #include "NfcProximityBuffer.h" 34 | 35 | // 36 | // Define the Control GUID and a DUMMY flag. 37 | // The DUMMY flag is just needed as an entry point into the WPP control 38 | // structures. ETW levels are used instead of WPP flags. 39 | // 4EB7CC58-145C-4a79-9418-68CD290DD9D4 40 | // 41 | #define WPP_CONTROL_GUIDS \ 42 | WPP_DEFINE_CONTROL_GUID( \ 43 | NfcProximityTraceControl, (4EB7CC58, 145C, 4a79, 9418, 68CD290DD9D4), \ 44 | WPP_DEFINE_BIT(DUMMY) \ 45 | ) 46 | 47 | #include "tracecommon.h" 48 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_Llcp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "phLibNfc_ndef_raw.h" 18 | 19 | #include 20 | #include 21 | #include "phLibNfc_State.h" 22 | 23 | 24 | typedef struct phLibNfc_LlcpInfo 25 | { 26 | /* Local parameters for LLC, given upon config 27 | * and used upon detection. 28 | */ 29 | phLibNfc_Llcp_sLinkParameters_t sLocalParams; 30 | 31 | /* LLCP compliance flag */ 32 | bool_t bIsLlcp; 33 | 34 | /* Monitor structure for LLCP Transport */ 35 | phFriNfc_LlcpTransport_t sLlcpTransportContext; 36 | 37 | /* Monitor structure for LLCP LLC */ 38 | phFriNfc_Llcp_t sLlcpContext; 39 | 40 | /* LLC Rx buffer */ 41 | uint8_t pRxBuffer[PHFRINFC_LLCP_PACKET_MAX_SIZE]; 42 | 43 | /* LLC Tx buffer */ 44 | uint8_t pTxBuffer[PHFRINFC_LLCP_PACKET_MAX_SIZE]; 45 | 46 | } phLibNfc_LlcpInfo_t; 47 | 48 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/NciCore/phNciNfc_CorePch.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2012 Microsoft Corporation 4 | 5 | Module Name: 6 | phNciNfc_CorePch.h 7 | 8 | Abstract: 9 | This module contains the precompiled headers for the NCI CORE component 10 | 11 | Environment: 12 | User mode. 13 | 14 | --*/ 15 | 16 | #pragma once 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "phNciNfcTypes.h" 33 | #include "phNciNfc_Core.h" 34 | #include "phNciNfc_CoreIf.h" 35 | #include "phNciNfc_CoreStatus.h" 36 | #include "phNciNfc_CoreMemMgr.h" 37 | #include "phNciNfc_CoreUtils.h" 38 | #include "phNciNfc_CoreRecvMgr.h" 39 | #include "phNciNfc_DbgDescription.h" 40 | #include "phNciNfc_LoglConnMgmt.h" 41 | #include "phNciNfc_TlvUtils.h" 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #include "NfcCoreLibTracing.h" 51 | 52 | _Analysis_mode_(_Analysis_code_type_user_driver_) 53 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/NciCore/phNciNfc_State.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNfcTypes.h" 10 | 11 | typedef NFCSTATUS (*phNciNfc_StateEntry_t)(void *pContext); 12 | typedef NFCSTATUS (*phNciNfc_StateTransition_t)(void *pContext); 13 | typedef NFCSTATUS (*phNciNfc_StateExit_t)(void *pContext); 14 | typedef uint8_t (*phNciNfc_Connector_t)(void *pContext); 15 | 16 | typedef struct phNciNfc_StateFunction 17 | { 18 | phNciNfc_StateEntry_t pfEntry; /**< Entry function to be called before entering to the new state*/ 19 | phNciNfc_StateExit_t pfExit;/**< to be performed before exit from the current state*/ 20 | }phNciNfc_StateFunction_t, *pphNciNfc_StateFunction_t; 21 | 22 | typedef struct phNciNfc_StateContext 23 | { 24 | uint8_t CurrState; /**< Current state*/ 25 | uint8_t TransitionFlag; /**< Acting on event*/ 26 | uint8_t CurrEvt;/**< Current event in */ 27 | /*Event Queue may be required to handle if more than event occurs and needs to be processed*/ 28 | phNciNfc_StateFunction_t pfStateHandler;/**< Entry and Exit function handlres for state*/ 29 | phNciNfc_Connector_t pfConnectors; /**< Connectors for state*/ 30 | }phNciNfc_StateContext_t; 31 | -------------------------------------------------------------------------------- /libs/Proximity/lib/NfcProximity/NfcProximity.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | 23 | 24 | Header Files 25 | 26 | 27 | Header Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /Test/NfcCxTests/IOHelpers/UniqueHandle.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include "UniqueHandle.h" 8 | 9 | UniqueHandle::UniqueHandle(HANDLE handle) : 10 | _Handle(handle) 11 | { 12 | } 13 | 14 | UniqueHandle::UniqueHandle(UniqueHandle&& other) : 15 | _Handle(other._Handle) 16 | { 17 | other._Handle = nullptr; 18 | } 19 | 20 | UniqueHandle::~UniqueHandle() 21 | { 22 | Reset(); 23 | } 24 | 25 | UniqueHandle& UniqueHandle::operator=(UniqueHandle&& other) 26 | { 27 | if (this != std::addressof(other)) 28 | { 29 | Reset(other.Release()); 30 | } 31 | 32 | return *this; 33 | } 34 | 35 | UniqueHandle& UniqueHandle::operator=(std::nullptr_t) 36 | { 37 | Reset(); 38 | return *this; 39 | } 40 | 41 | void UniqueHandle::Reset() 42 | { 43 | if (_Handle && _Handle != INVALID_HANDLE_VALUE) 44 | { 45 | CloseHandle(_Handle); 46 | } 47 | 48 | _Handle = nullptr; 49 | } 50 | 51 | void UniqueHandle::Reset(HANDLE handle) 52 | { 53 | if (handle != _Handle) 54 | { 55 | Reset(); 56 | _Handle = handle; 57 | } 58 | } 59 | 60 | HANDLE UniqueHandle::Release() 61 | { 62 | HANDLE handle = _Handle; 63 | _Handle = nullptr; 64 | return handle; 65 | } 66 | 67 | HANDLE UniqueHandle::Get() 68 | { 69 | return _Handle; 70 | } 71 | -------------------------------------------------------------------------------- /Test/NfcCxTests/SimulationSequences/RfDiscoverySequences.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | // Standard NCI command/response sequences relating to NCI discovery. 11 | struct RfDiscoverySequences 12 | { 13 | struct DiscoveryStart 14 | { 15 | static const SimSequenceStep PreDiscoveryStart; 16 | static const SimSequenceStep GetConfigCommand; 17 | static const SimSequenceStep GetConfigResponse; 18 | static const SimSequenceStep DiscoverCommand_Nci1; 19 | static const SimSequenceStep DiscoverCommand_Nci2; 20 | static const SimSequenceStep DiscoverResponse; 21 | static const SimSequenceStep DiscoverStartComplete; 22 | 23 | static const SimSequenceStep Sequence_Nci1[6]; 24 | static const SimSequenceStep Sequence_Nci2[6]; 25 | static const SimSequenceView Sequence(bool isNci2); 26 | }; 27 | 28 | struct DiscoveryStop 29 | { 30 | static const SimSequenceStep PreDiscoverStop; 31 | static const SimSequenceStep DeactivateCommand; 32 | static const SimSequenceStep DeactivateResponse; 33 | static const SimSequenceStep DiscoverStopComplete; 34 | 35 | static const SimSequenceStep Sequence[4]; 36 | }; 37 | }; 38 | -------------------------------------------------------------------------------- /libs/SmartCard/lib/Pch.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Module Name: 6 | 7 | Pch.h 8 | 9 | Abstract: 10 | 11 | This module is the precompiled header for the smart card library 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | // 24 | // LibNfc Headers 25 | // 26 | extern "C" { 27 | #include 28 | #include 29 | #include 30 | } 31 | 32 | #include "StorageClass.h" 33 | #include "StorageClassLoadKey.h" 34 | #include "StorageClassJewel.h" 35 | #include "StorageClassMifare.h" 36 | #include "StorageClassMifareStd.h" 37 | #include "StorageClassFelica.h" 38 | #include "StorageClassISO15693.h" 39 | 40 | // 41 | // Define the Control GUID and a DUMMY flag. 42 | // The DUMMY flag is just needed as an entry point into the WPP control 43 | // structures. ETW levels are used instead of WPP flags. 44 | // D976D933-B88B-4227-95F8-00513C0986DE 45 | // 46 | #define WPP_CONTROL_GUIDS \ 47 | WPP_DEFINE_CONTROL_GUID( \ 48 | NfcSmartCardTraceControl, (D976D933, B88B, 4227, 95F8, 00513C0986DE), \ 49 | WPP_DEFINE_BIT(DUMMY) \ 50 | ) 51 | 52 | #include "tracecommon.h" 53 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_Sequence.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNfcTypes.h" 10 | 11 | typedef NFCSTATUS (*NciSequenceEntry)(void *pContext); 12 | typedef NFCSTATUS (*NciSequenceExit)(void *pContext, NFCSTATUS wStatus); 13 | 14 | typedef struct phNciNfc_SequenceParams 15 | { 16 | NciSequenceEntry SequnceInitiate; /**< To initiate sequence, generally it sends command/data*/ 17 | NciSequenceExit SequenceProcess; /**< To Process sequence, generally it completes command/data*/ 18 | }phNciNfc_SequenceP_t; 19 | 20 | NFCSTATUS phNciNfc_SeqHandler(void *pNciCtx, NFCSTATUS Status); 21 | 22 | extern uint8_t phNciNfc_getSequenceLength(const phNciNfc_SequenceP_t * sequence); 23 | 24 | extern uint8_t phNciNfc_RepeatSequenceSeq(void *pNciCtx, 25 | phNciNfc_SequenceP_t *pReqSeq, 26 | uint8_t bValue); 27 | 28 | extern uint8_t phNciNfc_SkipSequenceSeq(void *pNciCtx, 29 | phNciNfc_SequenceP_t *pReqSeq, 30 | uint8_t bValue); 31 | 32 | #define PHNCINFC_INIT_SEQUENCE(CONTEXT,SEQUENCE) \ 33 | (CONTEXT)->pSeqHandler = (SEQUENCE);\ 34 | (CONTEXT)->SeqNext = 0;\ 35 | (CONTEXT)->SeqMax = phNciNfc_getSequenceLength((SEQUENCE)) 36 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Fri/phFriNfc_IntNdefMap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define PH_FRINFC_NDEFMAP_TLVLEN_ZERO 0 15 | 16 | /* NFC Device Major and Minor Version numbers*/ 17 | /* !!CAUTION!! these needs to be updated periodically.Major and Minor version numbers 18 | should be compatible to the version number of currently implemented mapping document. 19 | Example : NFC Device version Number : 1.0 , specifies 20 | Major VNo is 1, 21 | Minor VNo is 0 */ 22 | #define PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM 0x01 23 | #define PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM 0x00 24 | 25 | /* Macros to find major and minor TAG : Ex:Type1/Type2/Type3/Type4 version numbers*/ 26 | #define PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(a) (((a) & (0xf0))>>(4)) 27 | #define PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(a) ((a) & (0x0f)) 28 | 29 | NFCSTATUS phFriNfc_NdefMap_CheckSpecVersion(phFriNfc_NdefMap_t *NdefMap, 30 | uint8_t VersionIndex); 31 | 32 | NFCSTATUS phFriNfc_NdefMap_SetCardState(phFriNfc_NdefMap_t *NdefMap, 33 | uint16_t Length); 34 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Fri/phFriNfc_Pch.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2012 Microsoft Corporation 4 | 5 | Module Name: 6 | phFriNfc_Pch.h 7 | 8 | Abstract: 9 | This module contains the precompiled headers for the FRI component 10 | 11 | Environment: 12 | User mode. 13 | 14 | --*/ 15 | 16 | #pragma once 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | #include "NfcCoreLibTracing.h" 58 | 59 | _Analysis_mode_(_Analysis_code_type_user_driver_) 60 | -------------------------------------------------------------------------------- /Test/NfcCxTests/SimulationSequences/Type5TagSequences.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | // Sequences relating to reading/writing Type 5 NFC tags (T5T). 10 | struct Type5TagSequences 11 | { 12 | struct LRI2K 13 | { 14 | static const SimSequenceStep ActivatedNotification; 15 | static const SimSequenceStep GetSystemInfoCommand; 16 | static const SimSequenceStep GetSystemInfoResponse; 17 | 18 | static const SimSequenceStep ReadBlock0Command; 19 | static const SimSequenceStep ReadBlock0Response; 20 | static const SimSequenceStep ReadBlock1Command; 21 | static const SimSequenceStep ReadBlock1Response; 22 | static const SimSequenceStep ReadBlock2Command; 23 | static const SimSequenceStep ReadBlock2Response; 24 | static const SimSequenceStep ReadBlock3Command; 25 | static const SimSequenceStep ReadBlock3Response; 26 | static const SimSequenceStep ReadBlock4Command; 27 | static const SimSequenceStep ReadBlock4Response; 28 | static const SimSequenceStep PresenceCheckCommand; 29 | static const SimSequenceStep PresenceCheckConnectedResponse; 30 | 31 | static const SimSequenceStep ActivatedSequence[4]; 32 | static const SimSequenceStep ReadSequence[21]; 33 | static const SimSequenceStep PresenceCheckConnectedSequence[3]; 34 | static const SimSequenceStep PresenceCheckDisconnectedSequence[2]; 35 | }; 36 | }; 37 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/NciCore/phNciNfc_CoreRecvMgr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include "phNciNfc_Core.h" 11 | 12 | extern NFCSTATUS 13 | phNciNfc_CoreRecvMgrInit( 14 | pphNciNfc_CoreContext_t pCoreCtx 15 | ); 16 | 17 | extern NFCSTATUS 18 | phNciNfc_CoreRecvMgrRelease( 19 | pphNciNfc_CoreContext_t pCoreCtx 20 | ); 21 | 22 | extern NFCSTATUS 23 | phNciNfc_CoreRecvMgrRegisterCb( 24 | void *pCtx, 25 | pphNciNfc_CoreRegInfo_t pRegInfo, 26 | phNciNfc_NciCoreMsgType_t eMsgType 27 | ); 28 | 29 | extern NFCSTATUS 30 | phNciNfc_CoreRecvMgrDeRegisterCb(void *pCtx, 31 | pphNciNfc_CoreRegInfo_t pRegInfo, 32 | phNciNfc_NciCoreMsgType_t eMsgType); 33 | 34 | extern void 35 | phNciNfc_CoreRecvMgrDeRegisterAll(void *pCtx); 36 | 37 | extern void 38 | phNciNfc_CoreRecvMgrDeRegDataCb(void *pCtx, uint8_t bConnId); 39 | 40 | extern NFCSTATUS 41 | phNciNfc_CoreRecvManager( 42 | void *pCtx, 43 | NFCSTATUS wStatus, 44 | pphNciNfc_sCoreHeaderInfo_t pHdrInfo, 45 | phNciNfc_NciCoreMsgType_t eMsgType 46 | ); 47 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_NfcIMgmt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfcTypes.h" 10 | 11 | extern 12 | NFCSTATUS 13 | phNciNfc_NfcIPollInit( 14 | void *psContext, 15 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 16 | uint8_t *pBuff, 17 | uint16_t wLen 18 | ); 19 | 20 | extern 21 | NFCSTATUS 22 | phNciNfc_NfcILstnInit( 23 | void *psContext, 24 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 25 | uint8_t *pBuff, 26 | uint16_t wLen 27 | ); 28 | 29 | extern 30 | NFCSTATUS 31 | phNciNfc_P2pMgmtDataXchg( 32 | void *psContext, 33 | void *pDevHandle, 34 | phNciNfc_TransceiveInfo_t *pTranscvIf, 35 | pphNciNfc_TransreceiveCallback_t pNotify, 36 | void *pContext 37 | ); 38 | 39 | extern 40 | NFCSTATUS 41 | phNciNfc_P2pMgmtDataXchgSeq( 42 | void *pNciCtx, 43 | void *pInfo,NFCSTATUS Status 44 | ); 45 | 46 | extern 47 | NFCSTATUS 48 | phNciNfc_P2pMgmtCompleteDataXchgSeq( 49 | void *pContext, 50 | NFCSTATUS wStatus 51 | ); 52 | -------------------------------------------------------------------------------- /libs/SmartCard/inc/StorageClassLoadKey.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All Rights Reserved 4 | 5 | Module Name: 6 | 7 | StorageClassLoadKey.h 8 | 9 | Abstract: 10 | 11 | Storage card load key declaration 12 | 13 | Environment: 14 | 15 | User mode 16 | 17 | --*/ 18 | 19 | #pragma once 20 | 21 | #define DEFAULT_KEY_SPACE 10 22 | #define KEYSIZE 0x06 23 | 24 | class LoadKey 25 | { 26 | public: 27 | LoadKey(); 28 | virtual ~LoadKey(); 29 | 30 | NTSTATUS Initialize(DWORD n); 31 | VOID Uninitialize(); 32 | 33 | BOOL InsertKey( 34 | _In_ DWORD KeyNumber, 35 | _In_reads_bytes_(cbSize) const BYTE *pbKeyData, 36 | _In_ DWORD cbSize 37 | ); 38 | DWORD ExtractKeyIndex(DWORD KeyNumber); 39 | BOOL ExtractKeys( 40 | _In_ DWORD KeyIndex, 41 | _Out_writes_bytes_all_(cbSize) BYTE* pbKeyData, 42 | _In_ DWORD cbSize 43 | ); 44 | BOOL OverWriteKeys( 45 | _In_ DWORD KeyIndex, 46 | _In_ DWORD KeyNumber, 47 | _In_reads_bytes_(cbSize) const BYTE *pbKeyData, 48 | _In_ DWORD cbSize 49 | ); 50 | BOOL KeyTableFull(); 51 | BOOL KeyTableEmpty(); 52 | 53 | private: 54 | DWORD m_MaxNumberOfKeys; 55 | DWORD m_NumberOfKeys; 56 | DWORD *m_pBeginningOfKeyNumberStore; 57 | DWORD *m_pEndOfKeyNumberStore; 58 | DWORD *m_pWritePos; 59 | DWORD *m_pReadPos; 60 | BYTE **m_LoadKeyArray; 61 | }; 62 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_RFReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfc_RFReaderA.h" 10 | #include "phNciNfc_RFReaderFelica.h" 11 | #include "phNciNfc_RFReaderIso15693.h" 12 | #include "phNciNfcTypes.h" 13 | 14 | #define PH_NCINFC_EXTN_INVALID_PARAM_VAL (0xFFU) /**< Initial value of Req/Resp Param/Status */ 15 | #define DATA_XCHG_PARAMS_LEN (0x03U) /**< Length of Data Exchange Params */ 16 | 17 | /** RdrDataXcng sequence */ 18 | extern phNciNfc_SequenceP_t *gpphNciNfc_RdrDataXchgSequence; 19 | 20 | extern 21 | NFCSTATUS 22 | phNciNfc_RdrMgmtInit( 23 | void *psContext, 24 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 25 | uint8_t *pBuff, 26 | uint16_t wLen 27 | ); 28 | 29 | extern 30 | NFCSTATUS 31 | phNciNfc_RdrMgmtRelease( 32 | void *psContext 33 | ); 34 | 35 | extern 36 | NFCSTATUS 37 | phNciNfc_RdrMgmtXchgData( 38 | void *psContext, 39 | void *pDevHandle, 40 | phNciNfc_TransceiveInfo_t *pTranscvIf, 41 | pphNciNfc_TransreceiveCallback_t pNotify, 42 | void *pContext 43 | ); 44 | 45 | extern NFCSTATUS 46 | phNciNfc_RdrDataXchgSequence(void *pNciCtx,void *pInfo,NFCSTATUS Status); 47 | 48 | extern NFCSTATUS 49 | phNciNfc_CompleteDataXchgSequence(void *pContext, NFCSTATUS wStatus); 50 | -------------------------------------------------------------------------------- /Test/README.md: -------------------------------------------------------------------------------- 1 | # NFC class extension (CX) test guide 2 | 3 | The `NfcCxTests` test suite verifies the NFC CX behavior without requiring any NFC hardware. 4 | 5 | ## How to run 6 | 7 | 1. Build the Visual Studio solution for `Debug` and `x64`. 8 | 9 | 2. On the test system, [enable test signing](https://docs.microsoft.com/en-us/windows-hardware/drivers/install/the-testsigning-boot-configuration-option). 10 | 11 | 3. Copy the test client driver to the test system: 12 | 13 | - `x64\Debug\NfcCxTestDeviceDriver\` 14 | 15 | 4. On the test system, install the test client driver: 16 | 17 | - In explorer, right-click `NfcCxTestDeviceDriver.inf`. 18 | - Click `Install`. 19 | 20 | 5. Locate the TAEF directory in the WDK (or eWDK) and copy it to the test system. 21 | 22 | - `C:\Program Files (x86)\Windows Kits\10\Testing\Runtimes\TAEF\x64\` 23 | 24 | 6. On the test system, install the TE.Service. In an administrator command prompt, run: 25 | 26 | - `cd ''` 27 | - `.\Wex.Services.exe /install:Te.Service` 28 | - `sc.exe start Te.Service` 29 | 30 | 7. Copy the `NfcCxTests.dll` to the test system: 31 | 32 | - `x64\Debug\NfcCxTests.dll` 33 | 34 | 8. Copy the VC++ redistribution DLLs to the same directory as `NfcCxTests.dll`. 35 | 36 | - `C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Redist\MSVC\14.15.26706\onecore\debug_nonredist\x64\Microsoft.VC141.DebugCRT\` 37 | 38 | 9. Copy the UCRT debug DLL to the same directory as `NfcCxTests.dll`. 39 | 40 | - `C:\Program Files (x86)\Windows Kits\10\bin\x64\ucrt\ucrtbased.dll` 41 | 42 | 10. On the test system, run: 43 | 44 | - `\te.exe NfcCxTests.dll` 45 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_ndef_raw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | typedef enum phLibNfc_Last_Call 10 | { 11 | ChkNdef = 0x00, 12 | NdefRd, 13 | NdefWr, 14 | NdefFmt, 15 | NdefReadOnly, 16 | RawTrans 17 | } phLibNfc_Last_Call_t; 18 | 19 | #define TAG_MIFARE 0x01 20 | #define TAG_FELICA 0x02 21 | #define TAG_JEWEL 0x04 22 | #define TAG_ISO14443_4A 0x08 23 | #define TAG_ISO14443_4B 0x10 24 | #define TAG_NFC_IP1 0x20 25 | 26 | #define NDEF_READ_TIMER_TIMEOUT 60U 27 | #define CHK_NDEF_TIMER_TIMEOUT 60U 28 | #define NDEF_SENDRCV_BUF_LEN 252U 29 | #define NDEF_TEMP_RECV_LEN 256U 30 | #define NDEF_MIFARE_UL_LEN 46U 31 | #define NDEF_FELICA_LEN 0U/*Len to be set when supported*/ 32 | #define NDEF_JEWEL_TOPAZ_LEN 0U 33 | #define NDEF_ISO14443_4A_LEN 4096U 34 | #define NDEF_ISO14443_4B_LEN 0U 35 | #define NDEF_MIFARE_4K_LEN 3356U 36 | #define NDEF_MIFARE_1K_LEN 716U 37 | #define MIFARE_STD_DEFAULT_KEY {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} 38 | #define MIFARE_STD_KEY_LEN 6 39 | #define ISO_SAK_VALUE 0x20U 40 | 41 | #define UNKNOWN_BLOCK_ADDRESS 0xFF /***/ 42 | #define SESSION_OPEN 0x01 43 | 44 | extern void phLibNfc_Ndef_Init(void); 45 | extern void phLibNfc_Ndef_DeInit(void); 46 | extern phLibNfc_Ndef_Info_t NdefInfo; 47 | extern phFriNfc_NdefRecord_t *pNdefRecord; 48 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_PollMgmt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #include "phNciNfc_Pch.h" 8 | 9 | #include "phNciNfc_RFReader.h" 10 | #include "phNciNfc_RFReaderA.h" 11 | 12 | #include "phNciNfc_PollMgmt.tmh" 13 | 14 | NFCSTATUS 15 | phNciNfc_PollMgmt(void *psContext, 16 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 17 | uint8_t *pBuff, 18 | uint16_t wLen) 19 | { 20 | NFCSTATUS wStatus = NFCSTATUS_SUCCESS; 21 | pphNciNfc_Context_t psNciCtxt = (pphNciNfc_Context_t)psContext; 22 | phNciNfc_RfProtocols_t eProto; 23 | phNciNfc_RfInterfaces_t eIntf; 24 | 25 | PH_LOG_NCI_FUNC_ENTRY(); 26 | if((NULL == psNciCtxt) || (0 == wLen) || (NULL == pBuff) || (NULL == pRemDevInf)) 27 | { 28 | wStatus = NFCSTATUS_INVALID_PARAMETER; 29 | PH_LOG_NCI_INFO_STR("Invalid input parameters"); 30 | } 31 | else 32 | { 33 | eIntf = (phNciNfc_RfInterfaces_t)pBuff[1]; 34 | eProto = (phNciNfc_RfProtocols_t)pBuff[2]; 35 | /* Based on active Rf Technology and Rf protocol, 36 | perform reader management init or P2P management init*/ 37 | if(phNciNfc_e_RfInterfacesNFCDEP_RF == eIntf && 38 | phNciNfc_e_RfProtocolsNfcDepProtocol == eProto) 39 | { 40 | wStatus = phNciNfc_NfcIPollInit(psNciCtxt,pRemDevInf,pBuff,wLen); 41 | } 42 | else 43 | { 44 | wStatus = phNciNfc_RdrMgmtInit(psNciCtxt,pRemDevInf,pBuff,wLen); 45 | } 46 | } 47 | PH_LOG_NCI_FUNC_EXIT(); 48 | return wStatus; 49 | } 50 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/ApduSamples.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include "ApduSamples.h" 8 | 9 | const uint8_t ApduSamples::GetDataCommand[5] = { 0x80, 0xCA, 0xFF, 0xFF, 0x00 }; 10 | const uint8_t ApduSamples::GetDataResponse[11] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x90, 0x00 }; 11 | 12 | std::vector 13 | ApduSamples::GenerateExtendedApduCommand(uint16_t payloadLength) 14 | { 15 | std::vector result; 16 | result.reserve(payloadLength + 10); 17 | 18 | // Add APDU header for a proprietary command. 19 | result.insert(result.end(), { 0x80, 0xFF, 0x00, 0x00 }); 20 | 21 | // Add payload length using the extended format. 22 | result.insert(result.end(), { 0x00, uint8_t(payloadLength >> 8), uint8_t(payloadLength) }); 23 | 24 | // Add payload of arbitrary bytes. 25 | for (uint16_t i = 0; i != payloadLength; ++i) 26 | { 27 | result.push_back(uint8_t(i)); 28 | } 29 | 30 | // Set max response length (Le) to to the maxiumum possible value (65,536) using the extended format. 31 | result.insert(result.end(), { 0x00, 0x00, 0x00 }); 32 | 33 | return std::move(result); 34 | } 35 | 36 | std::vector 37 | ApduSamples::GenerateExtendedApduResponse(uint32_t payloadLength) 38 | { 39 | std::vector result; 40 | result.reserve(payloadLength + 2); 41 | 42 | // Add payload of arbitrary bytes. 43 | for (uint32_t i = 0; i != payloadLength; ++i) 44 | { 45 | result.push_back(uint8_t(i)); 46 | } 47 | 48 | // Set the status code to success. 49 | result.insert(result.end(), { 0x90, 0x00 }); 50 | 51 | return std::move(result); 52 | } 53 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_Sequence.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNfcTypes.h" 10 | 11 | typedef NFCSTATUS (*SequenceEntry)(void *pContext, NFCSTATUS wStatus, void * pInfo); 12 | typedef NFCSTATUS (*SequenceExit)(void *pContext, NFCSTATUS wStatus, void * pInfo); 13 | 14 | typedef struct phLibNfc_SequenceParams 15 | { 16 | SequenceEntry SequnceInitiate; /**< To initiate sequence, generally it sends command/data*/ 17 | SequenceExit SequenceProcess; /**< To Process sequence, generally it completes command/data*/ 18 | }phLibNfc_Sequence_t; 19 | 20 | NFCSTATUS phLibNfc_SeqHandler(void *pCtx, NFCSTATUS Status, void* pInfo); 21 | void phLibNfc_InternalSequence(void *pCtx, NFCSTATUS Status, void* pInfo); 22 | uint8_t phLibNfc_getSequenceLength(const phLibNfc_Sequence_t * sequence); 23 | 24 | void phLibNfc_AddSequence( void *pCtx,\ 25 | phLibNfc_Sequence_t * pSequence,\ 26 | SequenceEntry pSeqEntry,\ 27 | SequenceExit pSeqExit); 28 | 29 | extern uint8_t phLibNfc_SkipSequenceSeq(void *pLibCtx, 30 | phLibNfc_Sequence_t *pReqSeq, 31 | uint8_t bValue); 32 | 33 | extern uint8_t phLibNfc_RepeatSequenceSeq(void *pLibCtx, 34 | phLibNfc_Sequence_t *pReqSeq, 35 | uint8_t bValue); 36 | 37 | #define PHLIBNFC_INIT_SEQUENCE(CONTEXT,SEQUENCE) \ 38 | (CONTEXT)->pSeqHandler = (SEQUENCE);\ 39 | (CONTEXT)->SeqNext = 0;\ 40 | (CONTEXT)->SeqMax = phLibNfc_getSequenceLength((SEQUENCE)) 41 | -------------------------------------------------------------------------------- /Test/NfcCxTests/IOHelpers/IoOperation.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "AsyncTask.h" 13 | #include "UniqueHandle.h" 14 | 15 | struct IoOperationResult 16 | { 17 | DWORD ErrorCode = ERROR_SUCCESS; 18 | DWORD BytesTransferred = 0; 19 | std::vector Output; 20 | }; 21 | 22 | // A helper class for making a Win32 I/O request. 23 | class IoOperation final : 24 | public Async::AsyncTaskBase 25 | { 26 | // Make the constructor private but still allow std::make_shared to be used. 27 | struct PrivateToken {}; 28 | 29 | public: 30 | static std::shared_ptr DeviceIoControl( 31 | _In_ HANDLE driverHandle, 32 | _In_ DWORD ioctl, 33 | _In_reads_bytes_opt_(inputSize) const void* input, 34 | _In_ DWORD inputSize, 35 | _In_ DWORD outputBufferSize); 36 | 37 | IoOperation(PrivateToken, _In_ HANDLE driverHandle, _In_reads_bytes_opt_(inputSize) const void* input, _In_ DWORD inputSize, _In_ DWORD outputBufferSize); 38 | ~IoOperation(); 39 | 40 | protected: 41 | void OnCanceled() override; 42 | 43 | private: 44 | static void CALLBACK IoCompletedCallback( 45 | _Inout_ PTP_CALLBACK_INSTANCE instance, 46 | _Inout_opt_ void* context, 47 | _Inout_ PTP_WAIT wait, 48 | _In_ TP_WAIT_RESULT waitResult 49 | ); 50 | void IoCompleted(); 51 | 52 | HANDLE _DriverHandle = nullptr; 53 | OVERLAPPED _Overlapped; 54 | UniqueHandle _EventHandle; 55 | PTP_WAIT _EventWait; 56 | std::shared_ptr _SelfRef; 57 | std::vector _InputBuffer; 58 | std::vector _OutputBuffer; 59 | }; 60 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/SimSequenceView.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include "SimSequenceView.h" 8 | 9 | SimSequenceView::SimSequenceView( 10 | _In_reads_(stepListSize) const SimSequenceStep* list, 11 | _In_ size_t listSize) 12 | : 13 | _Type(Type::StepList) 14 | { 15 | _Data.StepList.Data = list; 16 | _Data.StepList.Size = listSize; 17 | } 18 | 19 | SimSequenceView::SimSequenceView(_In_ const SimSequenceStep& step) : 20 | SimSequenceView(&step, 1) 21 | { 22 | } 23 | 24 | SimSequenceView::SimSequenceView( 25 | _In_reads_(stepListSize) const SimSequenceView* list, 26 | _In_ size_t listSize) 27 | : 28 | _Type(Type::SequenceList) 29 | { 30 | _Data.SequenceList.Data = list; 31 | _Data.SequenceList.Size = listSize; 32 | } 33 | 34 | SimSequenceView::Type 35 | SimSequenceView::GetType() const 36 | { 37 | return _Type; 38 | } 39 | 40 | const SimSequenceStep* 41 | SimSequenceView::GetStepList() const 42 | { 43 | if (_Type != Type::StepList) 44 | { 45 | return nullptr; 46 | } 47 | 48 | return _Data.StepList.Data; 49 | } 50 | 51 | size_t 52 | SimSequenceView::GetStepListSize() const 53 | { 54 | if (_Type != Type::StepList) 55 | { 56 | return 0; 57 | } 58 | 59 | return _Data.StepList.Size; 60 | } 61 | 62 | const SimSequenceView* 63 | SimSequenceView::GetSequenceList() const 64 | { 65 | if (_Type != Type::SequenceList) 66 | { 67 | return nullptr; 68 | } 69 | 70 | return _Data.SequenceList.Data; 71 | } 72 | 73 | size_t 74 | SimSequenceView::GetSequenceListSize() const 75 | { 76 | if (_Type != Type::SequenceList) 77 | { 78 | return 0; 79 | } 80 | 81 | return _Data.SequenceList.Size; 82 | } 83 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/NciDataPacket.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include 8 | 9 | #include "NciDataPacket.h" 10 | 11 | NciDataPacket::NciDataPacket( 12 | _In_ uint8_t connectionId, 13 | _In_ std::initializer_list payload) 14 | : 15 | NciDataPacket(connectionId, payload, true) 16 | { 17 | } 18 | 19 | NciDataPacket::NciDataPacket( 20 | _In_ uint8_t connectionId, 21 | _In_ std::initializer_list payload, 22 | _In_ bool packetBoundary) 23 | : 24 | NciDataPacket(connectionId, payload.begin(), uint8_t(payload.size()), packetBoundary) 25 | { 26 | if (payload.size() > size_t(std::numeric_limits::max())) 27 | { 28 | throw std::exception("NciDataPacket payload is too big."); 29 | } 30 | } 31 | 32 | NciDataPacket::NciDataPacket( 33 | _In_ uint8_t connectionId, 34 | _In_reads_(payloadLength) const uint8_t* payload, 35 | _In_ uint8_t payloadLength, 36 | _In_ bool packetBoundary) 37 | { 38 | // Refer to: NFC Controller Interface (NCI), Version 1.1, Section 3.4.2 39 | uint8_t packetBoundaryFlag = packetBoundary ? NCI_PACKET_PBF_COMPLETE : NCI_PACKET_PBF_NOT_COMPLETE; 40 | 41 | _NciPacket.Header[0] = 42 | ((NCI_PACKET_MT_DATA << NCI_PACKET_MT_SHIFT) & NCI_PACKET_MT_MASK) | 43 | ((packetBoundaryFlag << NCI_PACKET_PBF_SHIFT) & NCI_PACKET_PBF_MASK) | 44 | (connectionId & NCI_PACKET_DATA_CONNID_MASK); 45 | 46 | _NciPacket.Header[1] = 0; 47 | _NciPacket.PayloadLength = payloadLength; 48 | _NciPacketLength = NciPacketRaw::TotalHeaderLength + payloadLength; 49 | 50 | // Copy the payload data into the packet. 51 | if (payloadLength != 0) 52 | { 53 | memcpy(_NciPacket.Payload, payload, payloadLength); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Test/NfcCxTestDeviceDriver/Driver/Trace.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | // 8 | // Define shorter versions of the ETW trace levels 9 | // 10 | #define LEVEL_CRITICAL TRACE_LEVEL_CRITICAL 11 | #define LEVEL_ERROR TRACE_LEVEL_ERROR 12 | #define LEVEL_WARNING TRACE_LEVEL_WARNING 13 | #define LEVEL_INFO TRACE_LEVEL_INFORMATION 14 | #define LEVEL_VERBOSE TRACE_LEVEL_VERBOSE 15 | #define LEVEL_FATAL TRACE_LEVEL_FATAL 16 | 17 | // {05151F65-5035-4259-BA5C-A0FA698441A8} 18 | #define WPP_CONTROL_GUIDS \ 19 | WPP_DEFINE_CONTROL_GUID( \ 20 | NfcNciSimulatorDriverTraceGuid, \ 21 | (05151F65,5035,4259,BA5C,A0FA698441A8), \ 22 | WPP_DEFINE_BIT(DUMMY) \ 23 | ) 24 | 25 | #define WPP_LEVEL_LOGGER(LEVEL) (WPP_CONTROL(WPP_BIT_ ## DUMMY).Logger), 26 | #define WPP_LEVEL_ENABLED(LEVEL) (WPP_CONTROL(WPP_BIT_ ## DUMMY).Level >= LEVEL) 27 | 28 | #define WPP_TRACE_LEVEL_EXP_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) 29 | #define WPP_TRACE_LEVEL_EXP_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) 30 | 31 | // 32 | // TRACE_FUNCTION_ENTRY 33 | // 34 | // begin_wpp config 35 | // USEPREFIX (TRACE_FUNCTION_ENTRY, "[NfcNciSimulator][%!LEVEL!]%!FUNC!:%s", " "); 36 | // FUNC TRACE_FUNCTION_ENTRY(TRACE_LEVEL_EXP); 37 | // USESUFFIX (TRACE_FUNCTION_ENTRY, "Enter"); 38 | // end_wpp 39 | // 40 | // 41 | // TRACE_FUNCTION_SUCCESS 42 | // 43 | // begin_wpp config 44 | // USEPREFIX (TRACE_FUNCTION_SUCCESS, "[NfcNciSimulator][%!LEVEL!]%!FUNC!:%s", " "); 45 | // FUNC TRACE_FUNCTION_SUCCESS(TRACE_LEVEL_EXP); 46 | // USESUFFIX (TRACE_FUNCTION_SUCCESS, "Success"); 47 | // end_wpp 48 | // 49 | // 50 | // TRACE_LINE 51 | // 52 | // begin_wpp config 53 | // USEPREFIX (TRACE_LINE, "[NfcNciSimulator][%!LEVEL!]%!FUNC!:%s", " "); 54 | // FUNC TRACE_LINE(TRACE_LEVEL_EXP, MSG, ...); 55 | // end_wpp 56 | // 57 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_Pch.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2012 Microsoft Corporation 4 | 5 | Module Name: 6 | phNciNfc_Pch.h 7 | 8 | Abstract: 9 | This module contains the precompiled headers for the NCI component 10 | 11 | Environment: 12 | User mode. 13 | 14 | --*/ 15 | 16 | #pragma once 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include "phNciNfc.h" 34 | #include "phNciNfc_Context.h" 35 | #include "phNciNfc_Core.h" 36 | #include "phNciNfc_CoreStatus.h" 37 | #include "phNciNfc_CoreMemMgr.h" 38 | #include "phNciNfc_CoreUtils.h" 39 | #include "phNciNfc_Utils.h" 40 | #include "phNciNfc_Common.h" 41 | #include "phNciNfc_RfConfig.h" 42 | #include "phNciNfc_ListenMgmt.h" 43 | #include "phNciNfc_ListenNfcDep.h" 44 | #include "phNciNfc_ListenIsoDep.h" 45 | #include "phNciNfc_RFReader.h" 46 | #include "phNciNfc_Init.h" 47 | #include "phNciNfc_Discovery.h" 48 | #include "phNciNfc_LogicalConn.h" 49 | #include "phNciNfc_CoreRecvMgr.h" 50 | #include "phNciNfc_PollMgmt.h" 51 | #include "phNciNfc_DbgDescription.h" 52 | #include "phNciNfc_LoglConnMgmt.h" 53 | #include "phNciNfc_NfceeMgmt.h" 54 | #include "phNciNfc_TlvUtils.h" 55 | #include "phNciNfc_NfcIMgmt.h" 56 | #include "phNciNfc_PollNfcDep.h" 57 | #include "phNciNfc_ListenNfcDep.h" 58 | #include "phNciNfc_NfcIMgmt.h" 59 | 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | 67 | #include "NfcCoreLibTracing.h" 68 | 69 | _Analysis_mode_(_Analysis_code_type_user_driver_) 70 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Osal/NfcCoreOsal/NfcCoreOsal.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/SimSequenceView.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include "SimSequenceStep.h" 8 | 9 | // 'SimSequenceView' is a variant type of either: 10 | // SimSequenceStep[] OR 11 | // SimSequenceView[] 12 | // 13 | // This type is intended to be used to compose lists of SimSequenceStep without copying memory. 14 | // 15 | // WARNING: This type does not own the memory that it references. 16 | class SimSequenceView 17 | { 18 | public: 19 | enum class Type { StepList, SequenceList }; 20 | 21 | SimSequenceView( 22 | _In_reads_(stepListSize) const SimSequenceStep* list, 23 | _In_ size_t listSize); 24 | 25 | template 26 | SimSequenceView( 27 | const SimSequenceStep (&list)[ListSize]) 28 | : 29 | SimSequenceView(list, ListSize) 30 | { 31 | } 32 | 33 | SimSequenceView(_In_ const SimSequenceStep& step); 34 | 35 | SimSequenceView( 36 | _In_reads_(stepListSize) const SimSequenceView* list, 37 | _In_ size_t listSize); 38 | 39 | template 40 | SimSequenceView( 41 | const SimSequenceView (&list)[ListSize]) 42 | : 43 | SimSequenceView(list, ListSize) 44 | { 45 | } 46 | 47 | Type GetType() const; 48 | const SimSequenceStep* GetStepList() const; 49 | size_t GetStepListSize() const; 50 | const SimSequenceView* GetSequenceList() const; 51 | size_t GetSequenceListSize() const; 52 | 53 | private: 54 | union Data 55 | { 56 | struct 57 | { 58 | const SimSequenceStep* Data; 59 | size_t Size; 60 | } StepList; 61 | struct 62 | { 63 | const SimSequenceView* Data; 64 | size_t Size; 65 | } SequenceList; 66 | }; 67 | Data _Data = {}; 68 | Type _Type; 69 | }; 70 | -------------------------------------------------------------------------------- /Cx/NfcCxSNEP.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All Rights Reserved 4 | 5 | Module Name: 6 | 7 | NfcCxSNEP.h 8 | 9 | Abstract: 10 | 11 | SNEP interface declarations 12 | 13 | SNEP (Simple NDEF Exchange Protocol) implements NDEF publications and subscriptions over 14 | NFC peer-to-peer (P2P) connections. 15 | 16 | Environment: 17 | 18 | User-mode Driver Framework 19 | 20 | --*/ 21 | 22 | #pragma once 23 | 24 | typedef struct _NFCCX_SNEP_INTERFACE { 25 | PNFCCX_FDO_CONTEXT FdoContext; 26 | phLibNfc_SnepConfig_t sConfigInfo; 27 | phLibNfc_Handle pServerHandleDef; 28 | phLibNfc_Handle pConnHandleDef; 29 | phLibNfc_Handle pClientHandleDef; 30 | phLibNfc_Data_t sDataInbox; 31 | phLibNfc_Data_t sSendDataBuff; 32 | } NFCCX_SNEP_INTERFACE, *PNFCCX_SNEP_INTERFACE; 33 | 34 | NTSTATUS 35 | NfcCxSNEPInterfaceCreate( 36 | _In_ PNFCCX_RF_INTERFACE RFInterface, 37 | _Out_ PNFCCX_SNEP_INTERFACE * PPSNEPInterface 38 | ); 39 | 40 | VOID 41 | NfcCxSNEPInterfaceDestroy( 42 | _In_ PNFCCX_SNEP_INTERFACE SNEPInterface 43 | ); 44 | 45 | NTSTATUS 46 | NfcCxSNEPInterfaceServerInit( 47 | _In_ PNFCCX_SNEP_INTERFACE SNEPInterface 48 | ); 49 | 50 | NTSTATUS 51 | NfcCxSNEPInterfaceDeinit( 52 | _In_ PNFCCX_SNEP_INTERFACE SNEPInterface 53 | ); 54 | 55 | NTSTATUS 56 | NfcCxSNEPInterfaceClientConnect( 57 | _In_ PNFCCX_RF_INTERFACE RFInterface, 58 | _In_opt_ VOID* Param1, 59 | _In_opt_ VOID* Param2 60 | ); 61 | 62 | #define SNEP_INTERFACE_CONNECT_SEQUENCE \ 63 | NFCCX_CX_SEQUENCE_ENTRY(NfcCxSNEPInterfaceClientConnect) 64 | 65 | NTSTATUS 66 | NfcCxSNEPInterfaceClientPut( 67 | _In_ PNFCCX_RF_INTERFACE RFInterface, 68 | _In_opt_ VOID* Param1, 69 | _In_opt_ VOID* Param2 70 | ); 71 | 72 | #define SNEP_INTERFACE_CLIENT_PUT_SEQUENCE \ 73 | NFCCX_CX_SEQUENCE_ENTRY(NfcCxSNEPInterfaceClientPut) 74 | -------------------------------------------------------------------------------- /Cx/NfcCxSCPresentAbsentDispatcher.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All Rights Reserved 4 | 5 | Module Name: 6 | 7 | NfcCxSCPresentAbsentDispatcher.h 8 | 9 | Abstract: 10 | 11 | For the Smartcard DDI, only a single IOCTL_SMARTCARD_IS_ABSENT request and a single IOCTL_SMARTCARD_IS_PRESENT 12 | request may be pending at any given time. If a second request for either IOCTL is issued then the driver is 13 | required to complete the request with STATUS_DEVICE_BUSY. 14 | 15 | This class handles the logic that ensures there is only a single pending IOCTL. This includes cleaning up the 16 | request if it is canceled. 17 | 18 | Environment: 19 | 20 | User-mode Driver Framework 21 | 22 | --*/ 23 | 24 | #pragma once 25 | 26 | typedef struct _NFCCX_SC_PRESENT_ABSENT_DISPATCHER { 27 | WDFREQUEST CurrentRequest; 28 | BOOLEAN PowerManaged; 29 | } NFCCX_SC_PRESENT_ABSENT_DISPATCHER, *PNFCCX_SC_PRESENT_ABSENT_DISPATCHER; 30 | 31 | VOID 32 | NfcCxSCPresentAbsentDispatcherInitialize( 33 | _In_ PNFCCX_SC_PRESENT_ABSENT_DISPATCHER Dispatcher, 34 | _In_ BOOLEAN PowerManaged 35 | ); 36 | 37 | NTSTATUS 38 | NfcCxSCPresentAbsentDispatcherSetRequest( 39 | _In_ PNFCCX_FDO_CONTEXT FdoContext, 40 | _In_ PNFCCX_SC_PRESENT_ABSENT_DISPATCHER Dispatcher, 41 | _In_ WDFREQUEST Request 42 | ); 43 | 44 | VOID 45 | NfcCxSCPresentAbsentDispatcherCompleteRequest( 46 | _In_ PNFCCX_FDO_CONTEXT FdoContext, 47 | _In_ PNFCCX_SC_PRESENT_ABSENT_DISPATCHER Dispatcher 48 | ); 49 | 50 | // 51 | // Internal functions 52 | // 53 | 54 | typedef struct _NFCCX_SC_REQUEST_CONTEXT { 55 | PNFCCX_SC_PRESENT_ABSENT_DISPATCHER Dispatcher; 56 | } NFCCX_SC_REQUEST_CONTEXT, *PNFCCX_SC_REQUEST_CONTEXT; 57 | 58 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(NFCCX_SC_REQUEST_CONTEXT, NfcCxSCGetRequestContext) 59 | 60 | VOID 61 | NfcCxSCPresentAbsentDispatcherRequestCanceled( 62 | _In_ WDFREQUEST Request 63 | ); 64 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/VerifyHelpers.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include 8 | 9 | #include 10 | #include "VerifyHelpers.h" 11 | 12 | bool AreArraysEqual( 13 | _In_reads_bytes_(arrayALength) const void* arrayA, 14 | _In_ size_t arrayALength, 15 | _In_reads_bytes_(arrayBLength) const void* arrayB, 16 | _In_ size_t arrayBLength) 17 | { 18 | return arrayALength == arrayBLength && 19 | 0 == memcmp(arrayA, arrayB, arrayALength); 20 | } 21 | 22 | void VerifyArraysAreEqual( 23 | _In_ PCWSTR name, 24 | _In_reads_bytes_(arrayALength) const void* arrayA, 25 | _In_ size_t arrayALength, 26 | _In_reads_bytes_(arrayBLength) const void* arrayB, 27 | _In_ size_t arrayBLength) 28 | { 29 | if (!AreArraysEqual(arrayA, arrayALength, arrayB, arrayBLength)) 30 | { 31 | // Log the expected packet. 32 | LogByteBuffer(L"Expected", arrayA, arrayALength); 33 | 34 | // Log actual packet. 35 | LogByteBuffer(L"Actual ", arrayB, arrayBLength); 36 | 37 | VERIFY_FAIL_MSG(L"'%s' arrays don't match.", name); 38 | return; 39 | } 40 | 41 | LOG_COMMENT(L"'%s' arrays match.", name); 42 | } 43 | 44 | void VerifyProximitySubscribeMessage( 45 | _In_reads_bytes_(ioResultLength) const void* ioResult, 46 | _In_ size_t ioResultLength, 47 | _In_reads_bytes_(expectedMessageLength) const void* expectedMessage, 48 | _In_ size_t expectedMessageLength 49 | ) 50 | { 51 | auto message = reinterpret_cast(ioResult); 52 | VERIFY_ARE_EQUAL(expectedMessageLength, size_t(message->cbPayloadHint)); 53 | 54 | VerifyArraysAreEqual( 55 | L"Proximity subscription message", 56 | expectedMessage, expectedMessageLength, 57 | message->payload, ioResultLength - offsetof(SUBSCRIBED_MESSAGE, payload)); 58 | } 59 | -------------------------------------------------------------------------------- /Test/NfcCxTests/SimulationSequences/TagSequences.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | #include 10 | 11 | // Common NCI command/response sequences relating to reading/writing tags. 12 | struct TagSequences 13 | { 14 | static const SimSequenceStep Connection0CreditStep; 15 | 16 | // NTAG 216 tag with a payload containing http://www.bing.com 17 | struct Ntag216 18 | { 19 | static const SimSequenceStep ActivatedNotification; 20 | static const SimSequenceStep GetVersionCommand; 21 | static const SimSequenceStep GetVersionResponse; 22 | static const SimSequenceStep DeactivateCommand; 23 | static const SimSequenceStep DeactivateResponse; 24 | static const SimSequenceStep DeactivateNotification; 25 | static const SimSequenceStep DiscoverSelectCommand; 26 | static const SimSequenceStep DiscoverSelectResponse; 27 | static const SimSequenceStep ActivateFailedNotification; 28 | 29 | static const SimSequenceStep ReadPage2Command; 30 | static const SimSequenceStep ReadPage2Response; 31 | static const SimSequenceStep ReadPage4Command; 32 | static const SimSequenceStep ReadPage4Response; 33 | static const SimSequenceStep ReadPage8Command; 34 | static const SimSequenceStep ReadPage8Response; 35 | static const SimSequenceStep ReadErrorResponse; 36 | 37 | static const SimSequenceStep ActivatedSequence[10]; 38 | static const SimSequenceStep ResetSequence[6]; 39 | static const SimSequenceStep ResetFailedSequence[6]; 40 | 41 | static const SimSequenceStep ReadSequence[18]; 42 | static const SimSequenceStep PresenceCheckConnectedSequence[3]; 43 | static const SimSequenceStep PresenceCheckDisconnectedSequence[3]; 44 | 45 | static const uint8_t Atr[20]; 46 | }; 47 | }; 48 | -------------------------------------------------------------------------------- /inc/NfcRadioDev.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All Rights Reserved 4 | 5 | Module Name: 6 | 7 | NfcRadioDev.h 8 | 9 | Abstract: 10 | 11 | IOCTL codes and structure common to the NFC Radio Device Interface 12 | 13 | --*/ 14 | #pragma once 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #if (NTDDI_VERSION >= NTDDI_WINBLUE) 21 | 22 | //{4d51e930-750d-4a36-a9f791dc540fcd30} 23 | DEFINE_GUID(GUID_NFC_RADIO_MEDIA_DEVICE_INTERFACE, 0x4d51e930, 0x750d, 0x4a36, 0xa9, 0xf7, 0x91, 0xdc, 0x54, 0x0f, 0xcd, 0x30); 24 | 25 | // {EF8BA08F-148D-4116-83EF-A2679DFC3FA5} 26 | DEFINE_GUID(GUID_NFCSE_RADIO_MEDIA_DEVICE_INTERFACE, 0xef8ba08f, 0x148d, 0x4116, 0x83, 0xef, 0xa2, 0x67, 0x9d, 0xfc, 0x3f, 0xa5); 27 | 28 | // 29 | // IOCTL definitions. 30 | // 31 | #define NFCRMDDI_IOCTL_BASE 0x50 32 | 33 | #define IOCTL_NFCRM_SET_RADIO_STATE CTL_CODE(FILE_DEVICE_NFP, (NFCRMDDI_IOCTL_BASE + 0x11), METHOD_BUFFERED, FILE_ANY_ACCESS) // Input: NFCRM_SET_RADIO_STATE 34 | #define IOCTL_NFCRM_QUERY_RADIO_STATE CTL_CODE(FILE_DEVICE_NFP, (NFCRMDDI_IOCTL_BASE + 0x12), METHOD_BUFFERED, FILE_ANY_ACCESS) // Output: NFCRM_RADIO_STATE 35 | #define IOCTL_NFCSERM_SET_RADIO_STATE CTL_CODE(FILE_DEVICE_NFP, (NFCRMDDI_IOCTL_BASE + 0x13), METHOD_BUFFERED, FILE_ANY_ACCESS) // Input: NFCRM_SET_RADIO_STATE 36 | #define IOCTL_NFCSERM_QUERY_RADIO_STATE CTL_CODE(FILE_DEVICE_NFP, (NFCRMDDI_IOCTL_BASE + 0x14), METHOD_BUFFERED, FILE_ANY_ACCESS) // Output: NFCRM_RADIO_STATE 37 | 38 | #include 39 | 40 | typedef struct _NFCRM_SET_RADIO_STATE { 41 | BOOLEAN SystemStateUpdate; // TRUE if this is a system state update 42 | BOOLEAN MediaRadioOn; 43 | } NFCRM_SET_RADIO_STATE, *PNFCRM_SET_RADIO_STATE; 44 | 45 | typedef struct _NFCRM_RADIO_STATE { 46 | BOOLEAN MediaRadioOn; 47 | } NFCRM_RADIO_STATE, *PNFCRM_RADIO_STATE; 48 | 49 | #include 50 | 51 | #endif //NTDDI_WINBLUE 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | -------------------------------------------------------------------------------- /Cx/NfcCxSCCommon.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All Rights Reserved 4 | 5 | Module Name: 6 | 7 | NfcCxSCCommon.h 8 | 9 | Abstract: 10 | 11 | SmartCard Common functions/types. 12 | 13 | Environment: 14 | 15 | User-mode Driver Framework 16 | 17 | --*/ 18 | 19 | #pragma once 20 | 21 | // ISO 7816-3 2006, Section 8.1 (TS byte + 32 characters) 22 | #define MAXIMUM_ATR_LENGTH 33 23 | 24 | typedef 25 | NTSTATUS 26 | NFCCX_SC_DISPATCH_HANDLER( 27 | _In_ WDFDEVICE Device, 28 | _In_ WDFREQUEST Request, 29 | _In_opt_bytecount_(InputBufferLength) PVOID InputBuffer, 30 | _In_ size_t InputBufferLength, 31 | _Out_opt_bytecap_(OutputBufferLength) PVOID OutputBuffer, 32 | _In_ size_t OutputBufferLength 33 | ); 34 | 35 | typedef NFCCX_SC_DISPATCH_HANDLER *PFN_NFCCX_SC_DISPATCH_HANDLER; 36 | 37 | // {D6B5B883-18BD-4B4D-B2EC-9E38AFFEDA82}, 2, DEVPROP_TYPE_BYTE 38 | DEFINE_DEVPROPKEY(DEVPKEY_Device_ReaderKind, 0xD6B5B883, 0x18BD, 0x4B4D, 0xB2, 0xEC, 0x9E, 0x38, 0xAF, 0xFE, 0xDA, 0x82, 0x02); 39 | 40 | // {D6B5B883-18BD-4B4D-B2EC-9E38AFFEDA82}, D, DEVPROP_TYPE_GUID 41 | DEFINE_DEVPROPKEY(DEVPKEY_Device_ReaderSecureElementId, 42 | 0xD6B5B883, 0x18BD, 0x4B4D, 0xB2, 0xEC, 0x9E, 0x38, 0xAF, 0xFE, 0xDA, 0x82, 0x0D); 43 | 44 | static const DWORD SCReaderCurrentProtocolType = SCARD_PROTOCOL_T1; 45 | 46 | NTSTATUS 47 | NfcCxSCCommonGetAttribute( 48 | _In_ DWORD AttributeId, 49 | _Out_writes_bytes_to_(*OutputBufferLength, *OutputBufferLength) PVOID OutputBuffer, 50 | _Inout_ size_t* OutputBufferLength); 51 | 52 | NFCCX_SC_DISPATCH_HANDLER NfcCxSCCommonDispatchNotSupported; 53 | NFCCX_SC_DISPATCH_HANDLER NfcCxSCCommonDispatchGetLastError; 54 | 55 | NTSTATUS 56 | NfcCxSCCommonCopyTrasmitResponseData( 57 | _Out_opt_bytecap_(OutputBufferLength) PVOID OutputBuffer, 58 | _In_ ULONG OutputBufferLength, 59 | _In_bytecount_(DataLength) PVOID Data, 60 | _In_ ULONG DataLength, 61 | _Out_ PULONG BufferUsed 62 | ); 63 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/SimSequenceRunner.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | #include "NciControlPacket.h" 10 | #include "NciSimConnector.h" 11 | #include "SimSequenceView.h" 12 | #include "SimSequenceStep.h" 13 | 14 | class SimSequenceRunner 15 | { 16 | public: 17 | static void VerifyStep( 18 | const SimSequenceStep& expectedStep, 19 | const NciSimCallbackMessage& message); 20 | 21 | static void Run( 22 | _In_ NciSimConnector& simConnector, 23 | _In_ const SimSequenceStep& step); 24 | 25 | static void Run( 26 | _In_ NciSimConnector& simConnector, 27 | _In_reads_(stepListSize) const SimSequenceStep* stepList, 28 | _In_ size_t stepListSize); 29 | 30 | static void Run( 31 | NciSimConnector& simConnector, 32 | const std::vector& stepList); 33 | 34 | template 35 | static void Run( 36 | _In_ NciSimConnector& simConnector, 37 | const SimSequenceStep (&stepList)[ArraySize]) 38 | { 39 | Run(simConnector, stepList, ArraySize); 40 | } 41 | 42 | static void Run( 43 | NciSimConnector& simConnector, 44 | SimSequenceView sequence); 45 | 46 | static void Run( 47 | _In_ NciSimConnector& simConnector, 48 | _In_reads_(sequenceListSize) const SimSequenceView* sequenceList, 49 | _In_ size_t sequenceListSize); 50 | 51 | static void Run( 52 | NciSimConnector& simConnector, 53 | const std::vector& sequenceList); 54 | 55 | template 56 | static void Run( 57 | _In_ NciSimConnector& simConnector, 58 | const SimSequenceView (&sequenceList)[ArraySize]) 59 | { 60 | Run(simConnector, sequenceList, ArraySize); 61 | } 62 | 63 | private: 64 | static void LogExpectedStep(const SimSequenceStep& expectedStep); 65 | }; 66 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Fri/phFriNfc_LlcpTransport_Connectionless.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | void Handle_Connectionless_IncommingFrame(phFriNfc_LlcpTransport_t *pLlcpTransport, 16 | phNfc_sData_t *psData, 17 | uint8_t dsap, 18 | uint8_t ssap); 19 | 20 | NFCSTATUS phFriNfc_LlcpTransport_Connectionless_HandlePendingOperations(phFriNfc_LlcpTransport_Socket_t *pSocket); 21 | NFCSTATUS phFriNfc_LlcpTransport_Connectionless_Close(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket); 22 | 23 | NFCSTATUS phFriNfc_LlcpTransport_Connectionless_SendTo(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket, 24 | uint8_t nSap, 25 | phNfc_sData_t* psBuffer, 26 | pphFriNfc_LlcpTransportSocketSendCb_t pSend_RspCb, 27 | void* pContext); 28 | 29 | NFCSTATUS phLibNfc_LlcpTransport_Connectionless_RecvFrom(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket, 30 | phNfc_sData_t* psBuffer, 31 | pphFriNfc_LlcpTransportSocketRecvFromCb_t pRecv_Cb, 32 | void* pContext); 33 | -------------------------------------------------------------------------------- /Test/NfcCxTestDeviceDriver/Driver/Driver.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include "Device.h" 8 | 9 | #include "Driver.tmh" 10 | 11 | extern "C" DRIVER_INITIALIZE DriverEntry; 12 | static EVT_WDF_DRIVER_DEVICE_ADD DriverEvtDeviceAdd; 13 | static EVT_WDF_OBJECT_CONTEXT_CLEANUP DriverEvtCleanup; 14 | 15 | // DriverEntry initializes the driver and is the first routine called by the 16 | // system after the driver is loaded. 17 | extern "C" NTSTATUS 18 | DriverEntry( 19 | _In_ PDRIVER_OBJECT DriverObject, 20 | _In_ PUNICODE_STRING RegistryPath 21 | ) 22 | { 23 | NTSTATUS status = STATUS_SUCCESS; 24 | 25 | WPP_INIT_TRACING(DriverObject, RegistryPath); 26 | TRACE_FUNCTION_ENTRY(LEVEL_VERBOSE); 27 | 28 | WDF_DRIVER_CONFIG driverConfig; 29 | WDF_DRIVER_CONFIG_INIT(&driverConfig, DriverEvtDeviceAdd); 30 | 31 | WDF_OBJECT_ATTRIBUTES driverObjectAttributes; 32 | WDF_OBJECT_ATTRIBUTES_INIT(&driverObjectAttributes); 33 | driverObjectAttributes.EvtCleanupCallback = DriverEvtCleanup; 34 | 35 | status = WdfDriverCreate( 36 | DriverObject, 37 | RegistryPath, 38 | &driverObjectAttributes, 39 | &driverConfig, 40 | WDF_NO_HANDLE 41 | ); 42 | if (!NT_SUCCESS(status)) 43 | { 44 | TRACE_LINE(LEVEL_ERROR, "WdfDriverCreate failed. %!STATUS!", status); 45 | WPP_CLEANUP(DriverObject); 46 | return status; 47 | } 48 | 49 | TRACE_FUNCTION_SUCCESS(LEVEL_VERBOSE); 50 | return STATUS_SUCCESS; 51 | } 52 | 53 | NTSTATUS 54 | DriverEvtDeviceAdd( 55 | _In_ WDFDRIVER /*Driver*/, 56 | _Inout_ PWDFDEVICE_INIT DeviceInit 57 | ) 58 | { 59 | return DeviceContext::DeviceAdd(DeviceInit); 60 | } 61 | 62 | // Free all the resources allocated in DriverEntry. 63 | VOID 64 | DriverEvtCleanup( 65 | _In_ WDFOBJECT DriverObject 66 | ) 67 | { 68 | UNREFERENCED_PARAMETER(DriverObject); 69 | WPP_CLEANUP(WdfDriverWdmGetDriverObject((WDFDRIVER)DriverObject)); 70 | } 71 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/SimSequenceStep.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | #include "NciControlPacket.h" 11 | #include "NciDataPacket.h" 12 | #include "NciHciDataPacket.h" 13 | #include "NciPacket.h" 14 | 15 | enum class SimSequenceStepType 16 | { 17 | NciWrite, 18 | NciRead, 19 | SequenceHandler, 20 | D0Entry, 21 | D0Exit, 22 | }; 23 | 24 | struct SimSequenceStep 25 | { 26 | SimSequenceStepType Type; 27 | std::wstring StepName; 28 | NciPacket NciPacketData; 29 | NFC_CX_SEQUENCE SequenceHandlerType; 30 | NTSTATUS SequenceHandlerStatus; 31 | ULONG SequenceHandlerFlags; 32 | 33 | static SimSequenceStep NciWrite( 34 | std::wstring stepName, 35 | const NciPacket& packet); 36 | static SimSequenceStep NciRead( 37 | std::wstring stepName, 38 | const NciPacket& packet); 39 | static SimSequenceStep NciControlWrite( 40 | std::wstring stepName, 41 | const NciControlPacket& packet); 42 | static SimSequenceStep NciControlRead( 43 | std::wstring stepName, 44 | const NciControlPacket& packet); 45 | static SimSequenceStep NciDataWrite( 46 | std::wstring stepName, 47 | const NciDataPacket& packet); 48 | static SimSequenceStep NciDataRead( 49 | std::wstring stepName, 50 | const NciDataPacket& packet); 51 | static SimSequenceStep D0Entry( 52 | std::wstring stepName); 53 | static SimSequenceStep D0Exit( 54 | std::wstring stepName); 55 | static SimSequenceStep HciWrite( 56 | std::wstring stepName, 57 | const NciHciDataPacket& packet); 58 | static SimSequenceStep HciRead( 59 | std::wstring stepName, 60 | const NciHciDataPacket& packet); 61 | 62 | static SimSequenceStep SequenceHandler( 63 | std::wstring stepName, 64 | NFC_CX_SEQUENCE type, 65 | NTSTATUS status, 66 | ULONG flags); 67 | }; 68 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_RFReaderFelica.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfc_Context.h" 10 | 11 | typedef enum phNciNfc_SensFReqRC 12 | { 13 | phNciNfc_e_NoSysCode, /**< No SystemCode info requested */ 14 | phNciNfc_e_SysCode, /**< SystemCode info requested */ 15 | phNciNfc_e_AdvProt, /**< Advanced Protocol features supported */ 16 | phNciNfc_e_InvalidRC /**< Invalid request - RFU */ 17 | }phNciNfc_SensFReqRC_t; 18 | 19 | typedef enum phNciNfc_SensFReqTSN 20 | { 21 | phNciNfc_e_1TS = 0x00, /**< Num of TimeSlots = 1 */ 22 | phNciNfc_e_2TS, /**< Num of TimeSlots = 2 */ 23 | phNciNfc_e_4TS = 0x03, /**< Num of TimeSlots = 4 */ 24 | phNciNfc_e_8TS = 0x07, /**< Num of TimeSlots = 8 */ 25 | phNciNfc_e_16TS = 0x0F, /**< Num of TimeSlots = 16 */ 26 | phNciNfc_e_InvalidTSN /**< Invalid request - RFU*/ 27 | }phNciNfc_SensFReqTSN_t; 28 | 29 | typedef struct phNciNfc_BlkList 30 | { 31 | uint8_t bBlkInfo; /**< Interpreted as "|Len|Ac|Mo|de|Se|rv|Co|de|" ==> |b0|b1|..|b7| */ 32 | uint16_t wBlkNum; /**< 1 Byte or 2 Byte BlkNum depending on the "Len"(b0) bit in bBlkInfo */ 33 | } phNciNfc_BlkList_t; 34 | 35 | extern phNciNfc_SequenceP_t gphNciNfc_T3TSequence[]; 36 | 37 | extern 38 | NFCSTATUS 39 | phNciNfc_RdrFInit( 40 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 41 | uint8_t *pBuff, 42 | uint16_t wLen 43 | ); 44 | 45 | extern 46 | NFCSTATUS 47 | phNciNfc_SendFelicaReq( 48 | void *psContext 49 | ); 50 | 51 | extern 52 | NFCSTATUS 53 | phNciNfc_RecvFelicaResp( 54 | void *psContext, 55 | NFCSTATUS wStatus 56 | ); 57 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_Discovery.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfcTypes.h" 10 | 11 | extern NFCSTATUS phLibNfc_SendDeactDiscCmd(void *pContext,NFCSTATUS status,void *pInfo); 12 | extern NFCSTATUS phLibNfc_ProcessDeactResp(void *pContext,NFCSTATUS wStatus,void *pInfo); 13 | extern NFCSTATUS phLibNfc_ProcDeact2IdleResp(void *pContext,NFCSTATUS wStatus,void *pInfo); 14 | extern NFCSTATUS phLibNfc_ProcessDeactToDiscResp(void *pContext,NFCSTATUS wStatus,void *pInfo); 15 | extern NFCSTATUS phLibNfc_SendDeactSleepCmd(void *pContext,NFCSTATUS status,void *pInfo); 16 | extern NFCSTATUS phLibNfc_ReqInfoComplete(void *pContext,NFCSTATUS status,void *pInfo); 17 | 18 | extern NFCSTATUS phLibNfc_ProcessDiscReq(void *pCtx, phNfc_eDiscAndDisconnMode_t RequestedMode, phLibNfc_sADD_Cfg_t *pADDSetup, void *Param3); 19 | extern NFCSTATUS phLibNfc_ProcessReDiscReq(void *pCtx, phNfc_eDiscAndDisconnMode_t RequestedMode, phLibNfc_sADD_Cfg_t *pADDSetup, void *Param3); 20 | 21 | extern NFCSTATUS phLibNfc_SendSelectCmd(void *pContext, NFCSTATUS status, void *pInfo); 22 | extern NFCSTATUS phLibNfc_SendSelectCmd1(void *pContext, NFCSTATUS status, void *pInfo); 23 | extern NFCSTATUS phLibNfc_SelectCmdResp(void *pContext, NFCSTATUS status, void *pInfo); 24 | 25 | extern NFCSTATUS phLibNfc_P2pActivate(void *pContext, NFCSTATUS status, void *pInfo); 26 | extern NFCSTATUS phLibNfc_P2pActivateResp(void *pContext, NFCSTATUS status, void *pInfo); 27 | 28 | extern phLibNfc_Sequence_t gphLibNfc_ReDiscSeqWithDeactAndDisc[]; 29 | extern phLibNfc_Sequence_t gphLibNfc_DeactivateToIdle[]; 30 | extern phLibNfc_Sequence_t gphLibNfc_DiscoverSeq[]; 31 | extern phLibNfc_Sequence_t gphLibNfc_ReStartDiscoverSeq[]; 32 | extern phLibNfc_Sequence_t gphLibNfc_DeactivateToIdleDelay[]; 33 | extern phLibNfc_Sequence_t gphLibNfc_ReDiscrySeqWithDeactAndDiscDelay[]; 34 | extern phLibNfc_Sequence_t gphLibNfc_ReDiscSeqWithDisc[]; 35 | extern phLibNfc_Sequence_t gphLibNfc_ReDiscSeqWithDiscDelay[]; 36 | -------------------------------------------------------------------------------- /Test/NfcCxTests/SimulationSequences/InitSequences.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | // Common NCI command/response sequences relating to NCI initialize and uninitialize. 11 | struct InitSequences 12 | { 13 | struct Reset 14 | { 15 | static const SimSequenceStep NciResetCommand; 16 | static const SimSequenceStep NciResetResponse_Nci1; 17 | static const SimSequenceStep NciResetResponse_Nci2; 18 | static const SimSequenceStep NciResetNotification_Nci2; 19 | 20 | static const SimSequenceStep Sequence_Nci1[2]; 21 | static const SimSequenceStep Sequence_Nci2[3]; 22 | }; 23 | 24 | struct Initialize 25 | { 26 | static const SimSequenceStep PreInitialize; 27 | static const SimSequenceStep InitializeCommand_Nci1; 28 | static const SimSequenceStep InitializeCommand_Nci2; 29 | static const SimSequenceStep InitializeResponse_Nci1; 30 | static const SimSequenceStep InitializeResponse_Nci2; 31 | static const SimSequenceStep InitializeComplete; 32 | static const SimSequenceStep GetConfigCommand; 33 | static const SimSequenceStep GetConfigResponse; 34 | 35 | static const SimSequenceView NoSEsSequence_Nci1[8]; 36 | static const SimSequenceView NoSEsSequence_Nci2[8]; 37 | static const SimSequenceView NoSEsSequence(bool isNci2); 38 | 39 | static const SimSequenceView WithEseSequence_Nci1[8]; 40 | static const SimSequenceView WithEseSequence_Nci2[8]; 41 | static const SimSequenceView WithEseSequence(bool isNci2); 42 | }; 43 | 44 | struct Uninitialize 45 | { 46 | static const SimSequenceStep PreShutdown; 47 | static const SimSequenceStep ShutdownComplete; 48 | 49 | static const SimSequenceView Sequence_Nci1[3]; 50 | static const SimSequenceView Sequence_Nci2[3]; 51 | static const SimSequenceView Sequence(bool isNci2); 52 | }; 53 | 54 | struct Power 55 | { 56 | static const SimSequenceStep D0Entry; 57 | static const SimSequenceStep D0Exit; 58 | }; 59 | }; 60 | -------------------------------------------------------------------------------- /Test/NfcCxTests/IOHelpers/DeviceQuery.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | // Helper class for querying for drivers, devices and device interfaces on the system. 15 | class DeviceQuery 16 | { 17 | public: 18 | // Find all the driver interfaces with the specified GUID type on a device. 19 | static std::vector<::winrt::Windows::Devices::Enumeration::DeviceInformation> DevicesQuery( 20 | std::wstring_view queryString, 21 | const ::winrt::param::iterable<::winrt::hstring>& additionalProperties, 22 | ::winrt::Windows::Devices::Enumeration::DeviceInformationKind deviceKind, 23 | DWORD timeoutMilliseconds); 24 | 25 | // Find all the driver interfaces with the specified GUID type on a device. 26 | static std::vector FindDriverInterfaces( 27 | _In_opt_ PCWSTR deviceId, 28 | const GUID& interfaceTypeId, 29 | DWORD timeoutMilliseconds = 0); 30 | 31 | // Find all the driver interfaces on the system with the specified GUID type. 32 | static std::vector FindDriverInterfaces( 33 | const GUID& interfaceTypeId, 34 | DWORD timeoutMilliseconds = 0); 35 | 36 | // Gets the ID of the device that exposes the specified device interface. 37 | static std::wstring GetDeviceIdOfInterface( 38 | _In_ PCWSTR interfaceId); 39 | 40 | // Gets all the smartcard reader interfaces of a particular type. 41 | static std::vector GetSmartcardInterfacesOfType( 42 | _In_opt_ PCWSTR deviceId, 43 | _In_ BYTE smartcardType, 44 | DWORD timeoutMilliseconds = 0); 45 | 46 | private: 47 | static std::wstring GuidToString(const GUID& guid); 48 | static std::wstring DevPropToString(const DEVPROPKEY& propertyId); 49 | static std::vector ToIdList(const std::vector<::winrt::Windows::Devices::Enumeration::DeviceInformation>& devicesList); 50 | static std::wstring CreateInterfaceQueryString( 51 | _In_opt_ PCWSTR deviceId, 52 | const GUID& interfaceTypeId); 53 | }; 54 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/NciControlPacket.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include "NciControlPacket.h" 8 | 9 | #include 10 | 11 | NciControlPacket::NciControlPacket( 12 | _In_ uint8_t type, 13 | _In_ uint8_t groupId, 14 | _In_ uint8_t opcodeId) 15 | : 16 | NciControlPacket(type, groupId, opcodeId, nullptr, 0, true) 17 | { 18 | } 19 | 20 | NciControlPacket::NciControlPacket( 21 | _In_ uint8_t type, 22 | _In_ uint8_t groupId, 23 | _In_ uint8_t opcodeId, 24 | _In_ std::initializer_list payload) 25 | : 26 | NciControlPacket(type, groupId, opcodeId, payload, true) 27 | { 28 | } 29 | 30 | NciControlPacket::NciControlPacket( 31 | _In_ uint8_t type, 32 | _In_ uint8_t groupId, 33 | _In_ uint8_t opcodeId, 34 | _In_ std::initializer_list payload, 35 | _In_ bool packetBoundary) 36 | : 37 | NciControlPacket(type, groupId, opcodeId, payload.begin(), uint8_t(payload.size()), packetBoundary) 38 | { 39 | if (payload.size() > size_t(std::numeric_limits::max())) 40 | { 41 | throw std::exception("NciControlPacket payload is too big."); 42 | } 43 | } 44 | 45 | NciControlPacket::NciControlPacket( 46 | _In_ uint8_t type, 47 | _In_ uint8_t groupId, 48 | _In_ uint8_t opcodeId, 49 | _In_reads_(payloadLength) const uint8_t* payload, 50 | _In_ uint8_t payloadLength, 51 | _In_ bool packetBoundary) 52 | { 53 | // Refer to: NFC Controller Interface (NCI), Version 1.1, Section 3.4.2 54 | uint8_t packetBoundaryFlag = packetBoundary ? NCI_PACKET_PBF_COMPLETE : NCI_PACKET_PBF_NOT_COMPLETE; 55 | 56 | _NciPacket.Header[0] = 57 | ((type << NCI_PACKET_MT_SHIFT) & NCI_PACKET_MT_MASK) | 58 | ((packetBoundaryFlag << NCI_PACKET_PBF_SHIFT) & NCI_PACKET_PBF_MASK) | 59 | (groupId & NCI_PACKET_CONTROL_GID_MASK); 60 | 61 | _NciPacket.Header[1] = opcodeId & NCI_PACKET_CONTROL_OID_MASK; 62 | 63 | _NciPacket.PayloadLength = payloadLength; 64 | _NciPacketLength = NciPacketRaw::TotalHeaderLength + payloadLength; 65 | 66 | // Copy the payload data into the packet. 67 | if (payloadLength != 0) 68 | { 69 | memcpy(_NciPacket.Payload, payload, payloadLength); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_Context.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #include "phNciNfc_Pch.h" 8 | 9 | #include "phNciNfc_Context.tmh" 10 | 11 | void phNciNfc_NciCtxInitialize(pphNciNfc_Context_t pNciCtx) 12 | { 13 | PH_LOG_NCI_FUNC_ENTRY(); 14 | if(NULL != pNciCtx) 15 | { 16 | pNciCtx->NciDiscContext.pDiscPayload = NULL; 17 | pNciCtx->tDeActvInfo.pDeActvNotif = NULL; 18 | pNciCtx->tDeActvInfo.DeActvCtxt = NULL; 19 | pNciCtx->tRegListInfo.DiscoveryCtxt = NULL; 20 | pNciCtx->tRegListInfo.GenericErrNtfCtxt = NULL; 21 | pNciCtx->tRegListInfo.NfceeCtxt = NULL; 22 | pNciCtx->tRegListInfo.pDiscoveryNotification = NULL; 23 | pNciCtx->tRegListInfo.pGenericErrNtfCb = NULL; 24 | pNciCtx->tRegListInfo.pNfceeNotification = NULL; 25 | pNciCtx->tRfConfContext.pReqParamList = NULL; 26 | pNciCtx->tSendPayload.pBuff = NULL; 27 | pNciCtx->IfNtf = NULL; 28 | pNciCtx->IfNtfCtx = NULL; 29 | pNciCtx->ModeSetCallback = NULL; 30 | pNciCtx->ModeSetCallbackContext = NULL; 31 | pNciCtx->pSeqHandler = NULL; 32 | pNciCtx->RspBuffInfo.pBuff = NULL; 33 | pNciCtx->tTranscvCtxt.pNotify = NULL; 34 | pNciCtx->tTranscvCtxt.pContext = NULL; 35 | pNciCtx->tActvDevIf.pDevInfo = NULL; 36 | pNciCtx->tSendPayload.pBuff = NULL; 37 | pNciCtx->tTranscvCtxt.tSendPld.pBuff = NULL; 38 | pNciCtx->tTranscvCtxt.tRecvPld.pBuff = NULL; 39 | pNciCtx->pUpperLayerInfo = NULL; 40 | } 41 | PH_LOG_NCI_FUNC_EXIT(); 42 | return ; 43 | } 44 | 45 | void phNciNfc_SetUpperLayerCallback(pphNciNfc_Context_t nciContext, pphNciNfc_IfNotificationCb_t callbackFunction, void* callbackContext) 46 | { 47 | PH_LOG_NCI_FUNC_ENTRY(); 48 | 49 | if (nciContext->IfNtf != NULL && nciContext->IfNtf != callbackFunction || 50 | nciContext->IfNtfCtx != NULL && nciContext->IfNtfCtx != callbackContext) 51 | { 52 | PH_LOG_NCI_CRIT_STR("Error: overwriting upper layer callback in nciContext!"); 53 | } 54 | 55 | nciContext->IfNtf = callbackFunction; 56 | nciContext->IfNtfCtx = callbackContext; 57 | 58 | PH_LOG_NCI_FUNC_EXIT(); 59 | } 60 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Fri/phFriNfc_MapTools.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define PH_FRINFC_NDEFMAP_TLVLEN_ZERO 0 15 | 16 | /* NFC Device Major and Minor Version numbers*/ 17 | /* !!CAUTION!! these needs to be updated periodically.Major and Minor version numbers 18 | should be compatible to the version number of currently implemented mapping document. 19 | Example : NFC Device version Number : 1.0 , specifies 20 | Major VNo is 1, 21 | Minor VNo is 0 */ 22 | #define PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM 0x01 23 | #ifdef DESFIRE_EV1 24 | #define PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM_2 0x02 25 | #endif /* */ 26 | #define PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM 0x00 27 | 28 | /* Macros to find major and minor TAG : Ex:Type1/Type2/Type3/Type4 version numbers*/ 29 | #define PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(a) (((a) & (0xf0))>>(4)) 30 | #define PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(a) ((a) & (0x0f)) 31 | 32 | /* NFC Device Major and Minor Version numbers*/ 33 | /* !!CAUTION!! these needs to be updated periodically.Major and Minor version numbers 34 | should be compatible to the version number of currently implemented mapping document. 35 | Example : NFC Device version Number : 1.0 , specifies 36 | Major VNo is 1, 37 | Minor VNo is 0 */ 38 | #define PH_NFCFRI_MFSTDMAP_NFCDEV_MAJOR_VER_NUM 0x40 39 | #define PH_NFCFRI_MFSTDMAP_NFCDEV_MINOR_VER_NUM 0x00 40 | 41 | /* Macros to find major and minor TAG : Ex:Type1/Type2/Type3/Type4 version numbers*/ 42 | #define PH_NFCFRI_MFSTDMAP_GET_MAJOR_TAG_VERNO(a) ((a) & (0x40)) // must be 0xC0 43 | #define PH_NFCFRI_MFSTDMAP_GET_MINOR_TAG_VERNO(a) ((a) & (0x30)) 44 | 45 | NFCSTATUS phFriNfc_MapTool_ChkSpcVer( const phFriNfc_NdefMap_t *NdefMap, 46 | uint8_t VersionIndex); 47 | 48 | NFCSTATUS phFriNfc_MapTool_SetCardState(phFriNfc_NdefMap_t *NdefMap, 49 | uint32_t Length); 50 | -------------------------------------------------------------------------------- /Test/NfcCxTestDeviceDriver/Driver/ApiCallbacksManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | // Manages 'IOCTL_NCISIM_GET_NEXT_CALLBACK' I/O requests. This includes immediately fulfilling the request if a message 10 | // is already available or waiting for the next available message. 11 | class ApiCallbacksManager 12 | { 13 | public: 14 | ApiCallbacksManager(); 15 | ~ApiCallbacksManager(); 16 | 17 | NTSTATUS Initialize( 18 | _In_ WDFDEVICE Device 19 | ); 20 | 21 | // Queue up a NciSimCallbackType::NciWrite callback message. 22 | NTSTATUS PostNciWriteCallback( 23 | _In_reads_bytes_(nciPacketLength) void* nciPacket, 24 | _In_ size_t nciPacketLength 25 | ); 26 | // Queue up a NciSimCallbackType::SequenceHandler callback message. 27 | NTSTATUS PostSequenceHandlerCallback( 28 | _In_ NFC_CX_SEQUENCE Sequence 29 | ); 30 | // Queues up a callback message that signals that a D0 entry was triggered. 31 | NTSTATUS PostD0EntryCallback( 32 | ); 33 | // Queues up a callback message that signals that a D0 exit was triggered. 34 | NTSTATUS PostD0ExitCallback( 35 | ); 36 | // Processes a IOCTL_NCISIM_GET_NEXT_CALLBACK request (including storing the request in a queue if a 37 | // callback is not available yet). 38 | void HandleCallbackRequest( 39 | _In_ WDFREQUEST Request 40 | ); 41 | 42 | private: 43 | struct DeferredCallbackListItem 44 | { 45 | LIST_ENTRY ListEntry; 46 | DWORD DataLength; 47 | BYTE Data[ANYSIZE_ARRAY]; 48 | }; 49 | static_assert(__is_trivial(DeferredCallbackListItem), "DeferredCallbackListItem must be trivial."); 50 | 51 | NTSTATUS AllocateDeferredCallbackListItem( 52 | _In_ DWORD DataLength, 53 | _Outptr_ DeferredCallbackListItem** result 54 | ); 55 | void QueueNewCallback( 56 | _In_ DeferredCallbackListItem* deferredCallbackListItem 57 | ); 58 | void TryFulfillCallbackRequest(); 59 | 60 | template 61 | NTSTATUS PostSimpleCallback(const CallbackDataType& callbackData); 62 | 63 | WDFWAITLOCK _Lock = nullptr; 64 | WDFQUEUE _DeferredCallbackRequests = nullptr; 65 | LIST_ENTRY _DeferredCallbacks = {}; 66 | }; 67 | -------------------------------------------------------------------------------- /Test/NfcCxTests/IOHelpers/SmartcardIo.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include "IoOperation.h" 8 | #include "SmartcardIo.h" 9 | 10 | std::shared_ptr<::Async::AsyncTaskBase> 11 | SmartcardIo::SendApdu( 12 | _In_ HANDLE smartcardInterface, 13 | _In_reads_bytes_(apduCommandLength) const void* apduCommand, 14 | _In_ DWORD apduCommandLength, 15 | _In_ DWORD apduResponseLength) 16 | { 17 | DWORD inputLength = sizeof(SCARD_IO_REQUEST) + apduCommandLength; 18 | DWORD outputLength = sizeof(SCARD_IO_REQUEST) + apduResponseLength; 19 | 20 | // Add the SCARD_IO_REQUEST header to the command APDU. 21 | auto input = std::make_unique(inputLength); 22 | 23 | auto commandApduHeader = reinterpret_cast(input.get()); 24 | commandApduHeader->dwProtocol = SCARD_PROTOCOL_T1; 25 | commandApduHeader->cbPciLength = sizeof(SCARD_IO_REQUEST); 26 | 27 | memcpy(input.get() + sizeof(SCARD_IO_REQUEST), apduCommand, apduCommandLength); 28 | 29 | // Start the I/O request. 30 | std::shared_ptr ioTransmit = IoOperation::DeviceIoControl(smartcardInterface, IOCTL_SMARTCARD_TRANSMIT, input.get(), inputLength, outputLength); 31 | 32 | // Create a wrapper async task, to allow for a little bit of post processing. 33 | auto completionSource = Async::MakeCompletionSource(); 34 | ioTransmit->SetCompletedHandler( 35 | [completionSource](Async::AsyncTaskBase& asyncTask) 36 | { 37 | IoOperationResult ioResult = asyncTask.Get(); 38 | 39 | IoApduResult result = {}; 40 | result.ErrorCode = ioResult.ErrorCode; 41 | if (result.ErrorCode == ERROR_SUCCESS) 42 | { 43 | result.ApduResponse = std::move(ioResult.Output); 44 | 45 | // Strip out the SCARD_IO_REQUEST header from the response APDU. 46 | DWORD responseSize = ioResult.BytesTransferred - sizeof(SCARD_IO_REQUEST); 47 | memmove(result.ApduResponse.data(), result.ApduResponse.data() + sizeof(SCARD_IO_REQUEST), responseSize); 48 | result.ApduResponse.resize(responseSize); 49 | } 50 | 51 | // Complete async task. 52 | completionSource->EmplaceResult(std::move(result)); 53 | }); 54 | 55 | // Return async task. 56 | return completionSource; 57 | } 58 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/NciCore/phNciNfc_CoreSend.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfc_State.h" 10 | 11 | #define PHNCINFC_CORESEND_TIMEOUT_MULTIPLIER (100) 12 | 13 | typedef enum phNciNfc_EvtSend 14 | { 15 | phNciNfc_EvtSendPacket, /**< New Packet Send Request Event*/ 16 | phNciNfc_EvtSendComplete,/**< previous packet is sent*/ 17 | phNciNfc_EvtCreditAvail,/**< Credit Available event*/ 18 | phNciNfc_EvtWaitCreditTimeOut,/**< Wait credit time out event.*/ 19 | phNciNfc_EVT_SEND_MAX,/**< Max Even limit*/ 20 | phNciNfc_EvtNone/**< Inavalid event*/ 21 | }phNciNfc_EvtSend_t; 22 | 23 | typedef enum phNciNfc_StateSends 24 | { 25 | phNciNfc_StateSendIdle,/**< Send Idle(ready) state for new send request */ 26 | phNciNfc_StateSend,/**< Send state min one packet to sent to the lower layer*/ 27 | phNciNfc_StateWaitCredit,/**< The state no credit is available to send rest of the packets*/ 28 | phNciNfc_STATE_SEND_MAX,/**< Limit for states*/ 29 | phNciNfc_ConnChkPktType,/**< check packet type to be used to create packet*/ 30 | phNciNfc_ConnChkCredit, /**< Connector to checks credit availability*/ 31 | phNciNfc_ConnChkSize, /**< Connector to checks remaining size to be sent*/ 32 | phNciNfc_CONN_SEND_MAX, /**< Limit for connectors*/ 33 | phNciNfc_StateSendNone /**< State for no Action*/ 34 | }phNciNfc_StateSend_t; 35 | 36 | typedef struct phNciNfc_SendStateContext 37 | { 38 | phNciNfc_StateSend_t CurrState; /**< Current send State*/ 39 | phNciNfc_EvtSend_t Evt; /**< Event Triggered*/ 40 | phNciNfc_Connector_t *pfConnector; /**< State connectors*/ 41 | phNciNfc_StateFunction_t *pfStateFunction; /**< State fptrs (Entry, Transition, Exit)*/ 42 | phNciNfc_StateTransition_t *pStateTransition; /**< Send (State to State) transition function pointers*/ 43 | }phNciNfc_SendStateContext_t, *pphNciNfc_SendStateContext_t; /**< Pointer to #phNciNfc_SendStateContext_t structure */ 44 | 45 | extern NFCSTATUS phNciNfc_CoreInitSenderStateMachine(void *pContext); 46 | extern NFCSTATUS phNciNfc_CoreResetSenderStateMachine(void *pContext); 47 | extern NFCSTATUS phNciNfc_CoreReleaseSenderStateMachine(void *pContext); 48 | extern void phNciNfc_CoreResetSendStateMachine(void *pContext); 49 | 50 | extern NFCSTATUS phNciNfc_StateHandler(void* pContext, phNciNfc_EvtSend_t CurrEvent); 51 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/NciCore/phNciNfc_CoreRecv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "phNciNfc_State.h" 10 | 11 | typedef enum phNciNfc_EvtRecv 12 | { 13 | phNciNfc_EvtRecvPacket, /**< New Packet Recv Event*/ 14 | phNciNfc_EvtRecvComplete, /**< All segment of the packet recvd*/ 15 | phNciNfc_EvtRecvTimeOut,/**< Recv Response time out event.*/ 16 | phNciNfc_EvtRecvHwError,/**< HW error event.*/ 17 | phNciNfc_EVT_RECV_MAX,/**< Max Event limit*/ 18 | phNciNfc_EvtRecvNone/**< Inavalid event*/ 19 | }phNciNfc_EvtRecv_t; 20 | 21 | typedef enum phNciNfc_StateRecv 22 | { 23 | phNciNfc_StateRecvIdle,/**< Receive Idle(ready) state to receive new packetS*/ 24 | phNciNfc_StateRecv,/**< Receive state min one packet received*/ 25 | phNciNfc_StateRecvDummy,/**< The state no credit is available to send rest of the packets*/ 26 | phNciNfc_STATE_RECV_MAX,/**< Limit for states*/ 27 | phNciNfc_ConnRecvChkPktType,/**< check packet type to be used to create packet*/ 28 | phNciNfc_ConnChkPbf, /**< Connector to checks credit availability*/ 29 | phNciNfc_ConnExptdPktType, 30 | phNciNfc_CONN_RECV_MAX, /**< Limit for connectors*/ 31 | phNciNfc_StateRecvNone /**< State for no Action*/ 32 | }phNciNfc_StateRecv_t; 33 | 34 | typedef struct phNciNfc_RecvStateContext 35 | { 36 | phNciNfc_StateRecv_t CurrState; /**< Current Recv State*/ 37 | phNciNfc_EvtRecv_t Evt; /**< Event Triggered*/ 38 | phNciNfc_Connector_t *pfConnector; /**< State connectors*/ 39 | phNciNfc_StateFunction_t *pfStateFunction; /**< State fptrs (Entry, Transition, Exit)*/ 40 | phNciNfc_StateTransition_t *pStateTransition; /**< Send (State to State) transition function pointers*/ 41 | NFCSTATUS wProcessStatus; /*Status of the processed packet e.g, TML status, or timer status etc*/ 42 | }phNciNfc_RecvStateContext_t, *pphNciNfc_RecvStateContext_t; /**< Pointer to #phNciNfc_SendStateContext_t structure */ 43 | 44 | 45 | extern NFCSTATUS phNciNfc_CoreInitRecverStateMachine(void *pContext); 46 | extern NFCSTATUS phNciNfc_CoreReleaseRecverStateMachine(void *pContext); 47 | extern NFCSTATUS phNciNfc_RecvStateHandler(void* pContext, phNciNfc_EvtRecv_t CurrEvent); 48 | extern NFCSTATUS phNciNfc_CoreRecvConvertStatus2Evt(NFCSTATUS Status, phNciNfc_EvtRecv_t *pEvt); 49 | 50 | extern void phNciNfc_RspTimeOutCb(uint32_t TimerId, void *pContext); 51 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/inc/phNfcCompId.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | /** 10 | * \ingroup grp_comp_id 11 | * 12 | * \name Component IDs 13 | * 14 | * IDs for all NFC components. Combined with the Status Code they build the value (status) 15 | * returned by each function. 16 | * 17 | * ID Number Spaces: 18 | * - 01..1F: HAL 19 | * - 20..3F: NFC-MW (Local Device) 20 | * - 40..5F: NFC-MW (Remote Device) 21 | * . 22 | * 23 | * \note The value \ref CID_NFC_NONE does not exist for Component IDs. Do not use this value except 24 | * for \ref NFCSTATUS_SUCCESS. The enumeration function uses \ref CID_NFC_NONE 25 | * to mark unassigned "References". 26 | * 27 | * \if hal 28 | * \sa \ref phHalNfc_Enumerate 29 | * \endif 30 | */ 31 | 32 | #define CID_NFC_NONE 0x00 /**< Unassigned or doesn't apply (see #NFCSTATUS_SUCCESS) */ 33 | #define CID_NFC_TML 0x01 /**< Transport Mapping Layer */ 34 | #define CID_NFC_LLC 0x07 /**< Logical Link Control Layer */ 35 | #define CID_NFC_NCI 0x08 /**< NFC Controller(NFCC) Interface Layer */ 36 | #define CID_NFC_DNLD 0x09 /**< Firmware Download Management Layer */ 37 | #define CID_NFC_HAL 0x10 /**< Hardware Abstraction Layer */ 38 | #define CID_NFC_OSAL CID_NFC_NONE /**< Operating System Abstraction Layer*/ 39 | #define CID_FRI_NFC_OVR_HAL 0x20 /**< NFC-Device, HAL-based */ 40 | #define CID_FRI_NFC_NDEF_RECORD 0x22 /**< NDEF Record Tools Library. */ 41 | #define CID_FRI_NFC_NDEF_MAP 0x23 /**< NDEF Mapping. */ 42 | #define CID_FRI_NFC_NDEF_REGISTRY 0x24 /**< NDEF_REGISTRY. */ 43 | #define CID_FRI_NFC_AUTO_DEV_DIS 0x25 /**< Automatic Device Discovery. */ 44 | #define CID_FRI_NFC_NDEF_SMTCRDFMT 0x26 /**< Smart Card Formatting */ 45 | #define CID_NFC_LIB 0x30 /**< NFC Library Layer*/ 46 | #define CID_MAX_VALUE 0xF0 /**< The maximum CID value that is defined. */ 47 | #define CID_FRI_NFC_LLCP 0x40 /**< Logical Link Control Protocol */ 48 | #define CID_FRI_NFC_LLCP_TRANSPORT 0x50 49 | #define CID_FRI_NFC_LLCP_MAC 0x60 50 | #define CID_NFC_HCI CID_NFC_NCI 51 | #define CID_NFC_DAL CID_NFC_TML 52 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_ListenIsoDep.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #include "phNciNfc_Pch.h" 8 | 9 | #include "phNciNfc_ListenIsoDep.tmh" 10 | 11 | NFCSTATUS 12 | phNciNfc_NfcIsoLstnRdrInit( 13 | pphNciNfc_RemoteDevInformation_t pRemDevInf, 14 | uint8_t *pBuff, 15 | uint16_t wLen 16 | ) 17 | { 18 | NFCSTATUS wStatus = NFCSTATUS_SUCCESS; 19 | uint8_t *pRfNtfBuff = NULL; 20 | uint8_t RfTechSpecParamsLen = 0; 21 | uint8_t bUidLength = 0; 22 | uint8_t bSelResRespLen = 0; 23 | uint8_t bSelRespVal = 0; 24 | 25 | PH_LOG_NCI_FUNC_ENTRY(); 26 | 27 | if((NULL == pRemDevInf) || (NULL == pBuff) || (0 == wLen)) 28 | { 29 | wStatus = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER); 30 | PH_LOG_NCI_CRIT_STR(" Invalid Param(s).."); 31 | } 32 | else 33 | { 34 | pRemDevInf->bRfDiscId = pBuff[0]; 35 | pRemDevInf->eRfIf = (phNciNfc_RfInterfaces_t)pBuff[1]; 36 | pRemDevInf->eRFProtocol = (phNciNfc_RfProtocols_t)pBuff[2]; 37 | pRemDevInf->eRFTechMode = (phNciNfc_RfTechMode_t)pBuff[3]; 38 | pRemDevInf->bMaxPayLoadSize = pBuff[4]; 39 | pRemDevInf->bInitialCredit = pBuff[5]; 40 | /* Obtain the len of RF tech specific parameters from Resp buff */ 41 | RfTechSpecParamsLen = pBuff[6]; 42 | pRemDevInf->bTechSpecificParamLen = RfTechSpecParamsLen; 43 | pRfNtfBuff = &(pBuff[7+RfTechSpecParamsLen]); 44 | 45 | pRemDevInf->eDataXchgRFTechMode = (phNciNfc_RfTechMode_t)*(pRfNtfBuff+0); 46 | pRemDevInf->bTransBitRate = *(pRfNtfBuff+1); 47 | pRemDevInf->bRecvBitRate = *(pRfNtfBuff+2); 48 | 49 | /* Length of NFCID1 */ 50 | bUidLength = *(pRfNtfBuff+2); 51 | /* Length of SEL_RES response */ 52 | bSelResRespLen = *(pRfNtfBuff + 3 + bUidLength); 53 | if(1 == bSelResRespLen) 54 | { 55 | /* Length of SEL_RES shall be '0' incase of Nfc Forum Type 1 Tag */ 56 | bSelRespVal = *(pRfNtfBuff + 3 + bUidLength + 1); 57 | } 58 | else 59 | { 60 | bSelRespVal = 0; 61 | } 62 | /* Length of SEL_RES shall be '0' incase of Nfc Forum Type 1 Tag */ 63 | } 64 | PH_LOG_NCI_FUNC_EXIT(); 65 | return wStatus; 66 | } 67 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/SimSequenceStep.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include "SimSequenceStep.h" 8 | 9 | SimSequenceStep 10 | SimSequenceStep::NciWrite( 11 | std::wstring stepName, 12 | const NciPacket& packet) 13 | { 14 | return SimSequenceStep{ SimSequenceStepType::NciWrite, std::move(stepName), packet, {}, {}, {} }; 15 | } 16 | 17 | SimSequenceStep 18 | SimSequenceStep::NciRead( 19 | std::wstring stepName, 20 | const NciPacket& packet) 21 | { 22 | return SimSequenceStep{ SimSequenceStepType::NciRead, std::move(stepName), packet, {}, {}, {} }; 23 | } 24 | 25 | SimSequenceStep 26 | SimSequenceStep::NciControlWrite( 27 | std::wstring stepName, 28 | const NciControlPacket& packet) 29 | { 30 | return NciWrite(std::move(stepName), packet); 31 | } 32 | 33 | SimSequenceStep 34 | SimSequenceStep::NciControlRead( 35 | std::wstring stepName, 36 | const NciControlPacket& packet) 37 | { 38 | return NciRead(std::move(stepName), packet); 39 | } 40 | 41 | SimSequenceStep 42 | SimSequenceStep::NciDataWrite( 43 | std::wstring stepName, 44 | const NciDataPacket& packet) 45 | { 46 | return NciWrite(std::move(stepName), packet); 47 | } 48 | 49 | SimSequenceStep 50 | SimSequenceStep::NciDataRead( 51 | std::wstring stepName, 52 | const NciDataPacket& packet) 53 | { 54 | return NciRead(std::move(stepName), packet); 55 | } 56 | 57 | SimSequenceStep 58 | SimSequenceStep::HciWrite( 59 | std::wstring stepName, 60 | const NciHciDataPacket& packet) 61 | { 62 | return NciWrite(std::move(stepName), packet); 63 | } 64 | 65 | SimSequenceStep 66 | SimSequenceStep::HciRead( 67 | std::wstring stepName, 68 | const NciHciDataPacket& packet) 69 | { 70 | return NciRead(std::move(stepName), packet); 71 | } 72 | 73 | SimSequenceStep 74 | SimSequenceStep::SequenceHandler( 75 | std::wstring stepName, 76 | NFC_CX_SEQUENCE type, 77 | NTSTATUS status, 78 | ULONG flags) 79 | { 80 | return SimSequenceStep{ SimSequenceStepType::SequenceHandler, std::move(stepName), {}, type, status, flags }; 81 | } 82 | 83 | SimSequenceStep 84 | SimSequenceStep::D0Entry( 85 | std::wstring stepName) 86 | { 87 | return SimSequenceStep{ SimSequenceStepType::D0Entry, std::move(stepName), {}, {}, {}, {} }; 88 | } 89 | 90 | SimSequenceStep 91 | SimSequenceStep::D0Exit( 92 | std::wstring stepName) 93 | { 94 | return SimSequenceStep{ SimSequenceStepType::D0Exit, std::move(stepName), {}, {}, {}, {} }; 95 | } 96 | -------------------------------------------------------------------------------- /Cx/NfcCxLLCP.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All Rights Reserved 4 | 5 | Module Name: 6 | 7 | NfcCxLLCP.h 8 | 9 | Abstract: 10 | 11 | LLCP Interface declarations 12 | 13 | Environment: 14 | 15 | User-mode Driver Framework 16 | 17 | --*/ 18 | 19 | #pragma once 20 | 21 | // 22 | // LLCP Configurable Parameters 23 | // 24 | typedef struct _NFCCX_LLCP_CONFIG_PARAM { 25 | USHORT uMIU; 26 | UCHAR uLTO; 27 | UCHAR uRecvWindowSize; 28 | } NFCCX_LLCP_CONFIG_PARAM; 29 | 30 | // 31 | // LLCP Request State 32 | // 33 | #define NFCCX_LLCP_REQUEST_COMPLETE 0x0 34 | #define NFCCX_LLCP_REQUEST_PENDING 0x1 35 | 36 | // 37 | // LLCP Context 38 | // 39 | typedef struct _NFCCX_LLCP_INTERFACE { 40 | PNFCCX_FDO_CONTEXT FdoContext; 41 | NFCCX_LLCP_CONFIG_PARAM sLlcpConfigParams; 42 | phLibNfc_Llcp_eLinkStatus_t eLinkStatus; 43 | phLibNfc_Llcp_sLinkParameters_t sLocalLinkInfo; 44 | phNfc_sData_t sServiceName; 45 | UCHAR eRequestState; 46 | bool IsDeactivatePending; 47 | } NFCCX_LLCP_INTERFACE, *PNFCCX_LLCP_INTERFACE; 48 | 49 | NTSTATUS 50 | NfcCxLLCPInterfaceCreate( 51 | _In_ PNFCCX_RF_INTERFACE RFInterface, 52 | _Outptr_ PNFCCX_LLCP_INTERFACE * PPLLCPInterface 53 | ); 54 | 55 | VOID 56 | NfcCxLLCPInterfaceDestroy( 57 | _In_ PNFCCX_LLCP_INTERFACE LLCPInterface 58 | ); 59 | 60 | NTSTATUS 61 | NfcCxLLCPInterfaceConfigure( 62 | _In_ PNFCCX_RF_INTERFACE RFInterface, 63 | _In_opt_ VOID* Param1, 64 | _In_opt_ VOID* Param2 65 | ); 66 | 67 | #define LLCP_INTERFACE_CONFIG_SEQUENCE \ 68 | NFCCX_CX_SEQUENCE_ENTRY(NfcCxLLCPInterfaceConfigure) 69 | 70 | NTSTATUS 71 | NfcCxLLCPInterfaceCheck( 72 | _In_ PNFCCX_RF_INTERFACE RFInterface, 73 | _In_opt_ VOID* Param1, 74 | _In_opt_ VOID* Param2 75 | ); 76 | 77 | #define LLCP_INTERFACE_CHECK_SEQUENCE \ 78 | NFCCX_CX_SEQUENCE_ENTRY(NfcCxLLCPInterfaceCheck) 79 | 80 | NTSTATUS 81 | NfcCxLLCPInterfaceActivate( 82 | _In_ PNFCCX_RF_INTERFACE RFInterface, 83 | _In_opt_ VOID* Param1, 84 | _In_opt_ VOID* Param2 85 | ); 86 | 87 | #define LLCP_INTERFACE_ACTIVATE_SEQUENCE \ 88 | NFCCX_CX_SEQUENCE_ENTRY(NfcCxLLCPInterfaceActivate) 89 | 90 | NTSTATUS 91 | NfcCxLLCPInterfaceDeactivate( 92 | _In_ PNFCCX_RF_INTERFACE RFInterface, 93 | _In_opt_ VOID* Param1, 94 | _In_opt_ VOID* Param2 95 | ); 96 | 97 | #define LLCP_INTERFACE_DEACTIVATE_SEQUENCE \ 98 | NFCCX_CX_SEQUENCE_ENTRY(NfcCxLLCPInterfaceDeactivate) 99 | -------------------------------------------------------------------------------- /libs/SmartCard/lib/NfcSmartCard/NfcSmartCard.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Osal/phOsalNfc_Internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | /* Maximum number of timers supported */ 18 | #define PH_MAX_OSAL_NUM_TIMERS (15) 19 | 20 | /* Defines the base address for generating timer id */ 21 | #define PH_OSAL_TIMER_BASE_ADDRESS (100) 22 | 23 | /* Maximum message queue size */ 24 | #define PH_OSAL_MSG_QUEUE_MAX_SIZE (16) 25 | 26 | typedef struct phOsalNfc_Timer 27 | { 28 | PTP_TIMER pTimer; 29 | ppCallBck_t pCallback; 30 | void* pContext; 31 | BOOL bFired; 32 | DWORD dwThreadId; 33 | } phOsalNfc_Timer_t; 34 | 35 | typedef struct phOsalNfc_MsgQueue 36 | { 37 | uint32_t Message; 38 | UINT_PTR Param1; 39 | UINT_PTR Param2; 40 | UINT_PTR Param3; 41 | UINT_PTR Param4; 42 | } phOsalNfc_MsgQueue_t; 43 | 44 | typedef struct phOsalNfc_Context 45 | { 46 | HANDLE hCallbackThread; 47 | uint32_t dwCallbackThreadID; 48 | phOsalNfc_MsgFunc_t pfnCallback; 49 | void* pCallbackContext; 50 | phOsalNfc_Timer_t TimerList[PH_MAX_OSAL_NUM_TIMERS]; 51 | CRITICAL_SECTION TimerLock; 52 | HANDLE hMsgQueueEvent; 53 | CRITICAL_SECTION MsgQueueLock; 54 | uint8_t bMsgQueueHead; 55 | uint8_t bMsgQueueTail; 56 | uint8_t bMsgQueueUsed; 57 | phOsalNfc_MsgQueue_t MsgQueue[PH_OSAL_MSG_QUEUE_MAX_SIZE]; 58 | } phOsalNfc_Context_t;/**< Structure Instance to access variables of Context structure */ 59 | 60 | extern phOsalNfc_Context_t* phOsalNfc_GetContext(); 61 | 62 | /** 63 | * \ingroup grp_osal_nfc 64 | * \brief Initializes timer related structures 65 | */ 66 | void phOsalNfc_Timer_Init (void); 67 | 68 | /** 69 | * \ingroup grp_osal_nfc 70 | * \brief Deinitializes timer related structures 71 | */ 72 | void phOsalNfc_Timer_DeInit (void); 73 | 74 | /** 75 | * \ingroup grp_osal_nfc 76 | * \brief Initializes message queue related structures 77 | */ 78 | NFCSTATUS phOsalNfc_MsgQueue_Init(void); 79 | 80 | /** 81 | * \ingroup grp_osal_nfc 82 | * \brief Initializes message queue related structures 83 | */ 84 | void phOsalNfc_MsgQueue_DeInit(void); 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif /* C++ Compilation guard */ 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NFC class extension (CX) design guide 2 | 3 | 4 | The NFC CX driver implements all NFC device driver interfaces and standard NFC protocols and formats based on the *NFC Forum NFC Controller Interface (NCI) Technical Specification*. 5 | 6 | The NFC client driver is responsible for transport layer interfacing as well as support for any non-standard vendor-defined extensions for the optimized functioning of the NFC controller. 7 | 8 | The NFC class extension driver implements all standard NFC Forum Tag (T1T, T2T, T3T, ISO-DEP) and P2P (LLCP and SNEP) protocols, and RF Management based on the NCI Core specification. The class extension driver implements all the Windows-defined device driver interfaces to interact with the NFC controller, Secure Elements, and Remote RF endpoints. 9 | 10 | These topics describe the architecture and public interface between the NFC class extension driver supplied by Microsoft and the NFC client driver supplied by the corresponding chipset manufacturers. The NFC CX driver is designed to support NFC chipsets from various manufacturers, and enables manufacturers to implement non-NCI standard functionality in their NFC client driver for differentiation purposes. 11 | 12 | ## NFC driver DDI 13 | The following are the Windows-defined NFC driver DDI that are implemented by the NFC CX driver: 14 | 15 | - [Near Field Proximity DDI](https://msdn.microsoft.com/library/windows/hardware/jj866056) 16 | - [NFC Secure Element Management DDI](https://msdn.microsoft.com/library/windows/hardware/dn905485) 17 | - [Smart Card DDI for contactless smart card access](https://msdn.microsoft.com/library/windows/hardware/dn905601) 18 | - [NFC Radio Management DDI](https://msdn.microsoft.com/library/windows/hardware/dn905577) 19 | - DTA DDI for NFC Forum certification 20 | 21 | ## NFC forum specifications 22 | The following are the NFC Forum specifications implemented by the NFC CX driver: 23 | 24 | - NFC Controller Interface, NCI 1.0 Specification 25 | - NFC Data Exchange Format, NDEF 26 | - NFC Forum Type 1-4 Tag 27 | - Logical Link Control Protocol, LLCP 1.1 Specification 28 | - Simple NDEF Exchange Protocol, SNEP 1.0 Specification 29 | - ISO/IEC 15693 30 | 31 | ## Supported NFC smart cards and tags 32 | The following are the NFC smart cards and tags supported by the NFC CX driver: 33 | 34 | - MIFARE Classic family 35 | - MIFARE Ultralight family 36 | - MIFARE DESFire family 37 | - FeliCa family 38 | - Jewel/Topaz family 39 | - Generic ISO 15693 tags 40 | 41 | ## Contributions 42 | 43 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 44 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /Test/NfcCxTests/IOHelpers/RadioManager.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include 8 | 9 | #include "DeviceQuery.h" 10 | #include "IoOperation.h" 11 | #include "RadioManager.h" 12 | 13 | RadioManager::RadioManager(_In_ PCWSTR deviceName) 14 | { 15 | // Find the proximity interface for the device. 16 | std::vector radioManagerInterfaces = DeviceQuery::FindDriverInterfaces(deviceName, GUID_NFC_RADIO_MEDIA_DEVICE_INTERFACE); 17 | 18 | // Only a single interface is expected to be found. 19 | VERIFY_ARE_EQUAL(1u, radioManagerInterfaces.size()); 20 | const std::wstring& radioManagerInterface = radioManagerInterfaces[0]; 21 | 22 | // Open handle to interface. 23 | _DeviceInterface.Reset(CreateFile( 24 | radioManagerInterface.c_str(), 25 | GENERIC_READ, 26 | 0, 27 | nullptr, 28 | OPEN_EXISTING, 29 | FILE_FLAG_OVERLAPPED, 30 | nullptr)); 31 | VERIFY_WIN32_BOOL_SUCCEEDED(INVALID_HANDLE_VALUE != _DeviceInterface.Get(), L"Open radio manager interface"); 32 | } 33 | 34 | bool 35 | RadioManager::GetNfcRadioState() 36 | { 37 | std::shared_ptr ioOperation = IoOperation::DeviceIoControl(_DeviceInterface.Get(), IOCTL_NFCRM_QUERY_RADIO_STATE, nullptr, 0, sizeof(NFCRM_RADIO_STATE)); 38 | VERIFY_IS_TRUE(ioOperation->Wait(/*wait (ms)*/ 1'000)); 39 | 40 | IoOperationResult ioResult = ioOperation->Get(); 41 | VERIFY_WIN32_SUCCEEDED(ioResult.ErrorCode, L"Get radio state"); 42 | 43 | auto radioState = reinterpret_cast(ioResult.Output.data()); 44 | return !!radioState->MediaRadioOn; 45 | } 46 | 47 | void 48 | RadioManager::SetNfcRadioState(bool enableNfcRadio) 49 | { 50 | SetRadioState(false, enableNfcRadio); 51 | } 52 | 53 | void 54 | RadioManager::SetAirplaneMode(bool enableAirplaneMode) 55 | { 56 | SetRadioState(true, !enableAirplaneMode); 57 | } 58 | 59 | // Params: 60 | // isSystemUpdate: Is airplane mode switch (or nfc radio switch). 61 | // enableRadio: Enable the radio. (For airplane mode, 'true' means disable airplane mode.) 62 | void 63 | RadioManager::SetRadioState(bool isSystemUpdate, bool enableRadio) 64 | { 65 | NFCRM_SET_RADIO_STATE radioState = {}; 66 | radioState.SystemStateUpdate = isSystemUpdate; 67 | radioState.MediaRadioOn = enableRadio; 68 | 69 | std::shared_ptr ioOperation = IoOperation::DeviceIoControl(_DeviceInterface.Get(), IOCTL_NFCRM_SET_RADIO_STATE, &radioState, sizeof(radioState), 0); 70 | VERIFY_IS_TRUE(ioOperation->Wait(/*wait (ms)*/ 1'000)); 71 | 72 | IoOperationResult ioResult = ioOperation->Get(); 73 | 74 | // ERROR_BAD_COMMAND is returned when the state is already correct. 75 | if (ioResult.ErrorCode != ERROR_BAD_COMMAND) 76 | { 77 | VERIFY_WIN32_SUCCEEDED(ioResult.ErrorCode); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /inc/WdfCxProxy.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All Rights Reserved 4 | 5 | Module Name: 6 | 7 | WdfCxProxy.h 8 | 9 | Abstract: 10 | 11 | WDF class extension proxy interface declaration 12 | 13 | Environment: 14 | 15 | User-mode Driver Framework 16 | 17 | --*/ 18 | 19 | #pragma once 20 | 21 | typedef 22 | VOID 23 | (*PFN_WDF_CLASS_EXPORT)( 24 | VOID 25 | ); 26 | 27 | typedef 28 | _Function_class_(EVT_WDFCX_DEVICE_FILE_CREATE) 29 | _IRQL_requires_same_ 30 | _IRQL_requires_max_(PASSIVE_LEVEL) 31 | BOOLEAN 32 | EVT_WDFCX_DEVICE_FILE_CREATE( 33 | _In_ 34 | WDFDEVICE Device, 35 | _In_ 36 | WDFREQUEST Request, 37 | _In_ 38 | WDFFILEOBJECT FileObject 39 | ); 40 | 41 | typedef EVT_WDFCX_DEVICE_FILE_CREATE *PFN_WDFCX_DEVICE_FILE_CREATE; 42 | 43 | typedef NTSTATUS (*ClassLibraryInitializeCallback)(VOID); 44 | 45 | typedef VOID (*ClassLibraryDeinitializeCallback)(VOID); 46 | 47 | typedef NTSTATUS (*ClassLibraryBindClientCallback)( 48 | _In_ PVOID ClassBindInfo, 49 | _In_ ULONG FunctionTableCount, 50 | _In_ PFN_WDF_CLASS_EXPORT* FunctionTable); 51 | 52 | typedef VOID (*ClassLibraryUnbindClientCallback)( 53 | _In_ PVOID ClassBindInfo); 54 | 55 | 56 | WDF_EXTERN_C_START 57 | 58 | NTSTATUS 59 | CxProxyWdfRegisterClassLibrary( 60 | _In_ PUNICODE_STRING RegistryPath, 61 | _In_opt_ PCUNICODE_STRING ClassLibraryDeviceName, 62 | _In_ ULONG VersionMajor, 63 | _In_ ULONG VersionMinor, 64 | _In_ ULONG VersionBuild, 65 | _In_ ClassLibraryInitializeCallback InitializeCallback, 66 | _In_ ClassLibraryDeinitializeCallback DeinitializeCallback, 67 | _In_ ClassLibraryBindClientCallback BindClientCallback, 68 | _In_ ClassLibraryUnbindClientCallback UnbindClientCallback 69 | ); 70 | 71 | PWDFCXDEVICE_INIT 72 | CxProxyWdfCxDeviceInitAllocate( 73 | _In_ PWDFDEVICE_INIT DeviceInit 74 | ); 75 | 76 | VOID 77 | CxProxyWdfDeviceInitAllowSelfIoTarget( 78 | _In_ PWDFDEVICE_INIT DeviceInit 79 | ); 80 | 81 | VOID 82 | CxProxyWdfCxDeviceInitSetFileObjectConfig( 83 | _In_ PWDFCXDEVICE_INIT CxDeviceInit, 84 | _In_opt_ PWDF_OBJECT_ATTRIBUTES FileObjectAttributes, 85 | _In_opt_ PFN_WDFCX_DEVICE_FILE_CREATE EvtCxDeviceFileCreate, 86 | _In_opt_ PFN_WDF_FILE_CLOSE EvtFileClose, 87 | _In_opt_ PFN_WDF_FILE_CLEANUP EvtFileCleanup 88 | ); 89 | 90 | NTSTATUS 91 | CxProxyWdfIoTargetSelfAssignDefaultIoQueue( 92 | _In_ WDFIOTARGET IoTarget, 93 | _In_ WDFQUEUE Queue 94 | ); 95 | 96 | WDFIOTARGET 97 | CxProxyWdfDeviceGetSelfIoTarget( 98 | _In_ WDFDEVICE Device 99 | ); 100 | 101 | VOID 102 | CxProxyWdfCxVerifierKeBugCheck( 103 | _In_opt_ WDFOBJECT Object, 104 | _In_ ULONG BugCheckCode, 105 | _In_ ULONG_PTR BugCheckParameter1, 106 | _In_ ULONG_PTR BugCheckParameter2, 107 | _In_ ULONG_PTR BugCheckParameter3, 108 | _In_ ULONG_PTR BugCheckParameter4 109 | ); 110 | 111 | WDF_EXTERN_C_END 112 | -------------------------------------------------------------------------------- /Cx/NfcCxSequence.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Module Name: 6 | 7 | NfcCxSequence.h 8 | 9 | Abstract: 10 | 11 | This module declares sequence types in NFC CX 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | typedef 18 | NTSTATUS 19 | (FN_NFCCX_CX_SEQUENCE_ENTRY)( 20 | _In_ PNFCCX_RF_INTERFACE RFInterface, 21 | _In_opt_ void* Param1, 22 | _In_opt_ void* Param2 23 | ); 24 | 25 | typedef 26 | void 27 | (FN_NFCCX_CX_SEQUENCE_EXIT)( 28 | _In_ PNFCCX_RF_INTERFACE RFInterface, 29 | _In_ NTSTATUS Status, 30 | _In_opt_ void* Param1, 31 | _In_opt_ void* Param2 32 | ); 33 | 34 | typedef FN_NFCCX_CX_SEQUENCE_ENTRY* PFN_NFCCX_CX_SEQUENCE_ENTRY; 35 | typedef FN_NFCCX_CX_SEQUENCE_EXIT* PFN_NFCCX_CX_SEQUENCE_EXIT; 36 | 37 | #define NFCCX_CX_BEGIN_SEQUENCE_MAP(Sequence) static constexpr PFN_NFCCX_CX_SEQUENCE_ENTRY Sequence[] = { 38 | #define NFCCX_CX_SEQUENCE_ENTRY(SequenceInitiate) SequenceInitiate, 39 | #define NFCCX_CX_END_SEQUENCE_MAP() }; 40 | 41 | struct NFCCX_CX_SEQUENCE 42 | { 43 | PNFCCX_RF_INTERFACE RFInterface; 44 | const PFN_NFCCX_CX_SEQUENCE_ENTRY* SequenceSteps; 45 | UCHAR SequenceStepsNext; 46 | UCHAR SequenceStepsSize; 47 | PFN_NFCCX_CX_SEQUENCE_EXIT SequenceCompleteStep; 48 | bool IsSequenceRunning; 49 | }; 50 | 51 | NTSTATUS 52 | NfcCxSequenceStart( 53 | _In_ PNFCCX_RF_INTERFACE RFInterface, 54 | _In_reads_(SequenceStepsSize) const PFN_NFCCX_CX_SEQUENCE_ENTRY* SequenceSteps, 55 | _In_ UCHAR SequenceStepsSize, 56 | _In_ PFN_NFCCX_CX_SEQUENCE_EXIT SequenceCompleteStep, 57 | _In_opt_ void* Param1, 58 | _In_opt_ void* Param2 59 | ); 60 | 61 | template 62 | NTSTATUS 63 | NfcCxSequenceStart( 64 | _In_ PNFCCX_RF_INTERFACE RFInterface, 65 | _In_ const PFN_NFCCX_CX_SEQUENCE_ENTRY (&SequenceSteps)[SequenceStepsSize], 66 | _In_ PFN_NFCCX_CX_SEQUENCE_EXIT SeqComplete, 67 | _In_opt_ void* Param1, 68 | _In_opt_ void* Param2 69 | ) 70 | { 71 | return NfcCxSequenceStart(RFInterface, SequenceSteps, SequenceStepsSize, SeqComplete, Param1, Param2); 72 | } 73 | 74 | void 75 | NfcCxSequenceResume( 76 | _In_ PNFCCX_RF_INTERFACE RFInterface, 77 | _In_ NFCCX_CX_SEQUENCE* Sequence, 78 | _In_ NTSTATUS SequenceStatus, 79 | _In_opt_ void* Param1, 80 | _In_opt_ void* Param2 81 | ); 82 | 83 | void 84 | NfcCxSequenceDispatchResume( 85 | _In_ PNFCCX_RF_INTERFACE RFInterface, 86 | _In_ NFCCX_CX_SEQUENCE* Sequence, 87 | _In_ NTSTATUS Status, 88 | _In_opt_ void* Param1, 89 | _In_opt_ void* Param2 90 | ); 91 | 92 | NTSTATUS 93 | NfcCxSkipSequence( 94 | _In_ PNFCCX_RF_INTERFACE RFInterface, 95 | _In_ NFCCX_CX_SEQUENCE* Sequence, 96 | _In_ UCHAR Value 97 | ); 98 | 99 | NTSTATUS 100 | NfcCxRepeatSequence( 101 | _In_ PNFCCX_RF_INTERFACE RFInterface, 102 | _In_ NFCCX_CX_SEQUENCE* Sequence, 103 | _In_ UCHAR Value 104 | ); 105 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Nci/phNciNfc_NfceeMgmt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #define PH_NCINFC_NFCEE_DISC_ENABLE (0x01) 10 | #define PH_NCINFC_NFCEE_DISC_DISABLE (0x00) 11 | 12 | #define PH_NCINFC_NFCEE_T3T_CMDSET_LEN_MIN (9u) 13 | #define PH_NCINFC_NFCEE_T3T_CMDSET_LEN_MAX (169u) 14 | 15 | #define PH_NCINFC_NFCEE_START_RFCOMM_TLV (0x00) 16 | #define PH_NCINFC_NFCEE_STOP_RFCOMM_TLV (0x01) 17 | #define PH_NCINFC_NFCEE_START_STOP_RFCOMM_TLV_LEN (0x03) 18 | 19 | #define PH_NCINFC_NFCEE_MIN_TLV_LEN (0x02) 20 | #define PH_NCINFC_NFCEE_T3T_ENTRY_LEN (10U) 21 | 22 | /** Value indicates length of Nfcee Mode set command payload */ 23 | #define PHNCINFC_NFCEEMODESET_PAYLOADLEN (0x02) 24 | #define PHNCINFC_NFCEEMODESET_RESP_LEN (0x01) 25 | 26 | #define PH_NCINFC_NFCEEACTION_MIN_LEN (0x03) 27 | #define PH_NCINFC_NFCEEDISC_MIN_LEN (0x06) 28 | 29 | #define PH_NCINFC_NFCEE_PROTOS_PROP_MIN (0x80) 30 | #define PH_NCINFC_NFCEE_PROTOS_PROP_MAX (0xFE) 31 | 32 | #define PH_NCINFC_NFCEEPOWERLINKCTRL_PAYLOADLEN (0x02) 33 | 34 | typedef struct phNciNfc_NfceeContext 35 | { 36 | /** Total number of Nfcee discovered from response*/ 37 | uint8_t bNumberOfNfcee; 38 | /** Total number of Nfcee discovered from Discover Response*/ 39 | uint8_t bNfceeCount; 40 | /** Index of Intended Nfcee from discovered group of Nfcee*/ 41 | phNciNfc_NfceeModes_t eNfceeMode;/**< Used to store the NFCEE Mode to be set*/ 42 | uint8_t bNfceeDiscState;/**< Indicates whether NFCEE Discovery is enabled/Disabled*/ 43 | /** Nfcee Device information This can be changed to array of pointers if memory increases 44 | and then allocate memory for each discoverd device*/ 45 | phNciNfc_NfceeDeviceHandle_t pNfceeDevInfo[PH_NCINFC_NFCEE_DEVICE_MAX]; 46 | }phNciNfc_NfceeContext_t, *pphNciNfc_NfceeContext_t; /**< Pointer to #phNciNfc_NfceeContext_t structure */ 47 | 48 | typedef void (*pphNciNfc_Notification_CB_t) ( 49 | void *pContext, 50 | uint8_t type, 51 | void *pInfo 52 | ); 53 | 54 | extern phNciNfc_SequenceP_t gphNciNfc_NfceeDiscSequence[]; 55 | extern phNciNfc_SequenceP_t gphNciNfc_ModeSetSequence[]; 56 | extern phNciNfc_SequenceP_t gphNciNfc_SePowerAndLinkCtrlSequence[]; 57 | 58 | NFCSTATUS phNciNfc_DeActivateNfcee(void *pContext); 59 | NFCSTATUS phNciNfc_RfFieldInfoNtfHandler(void *pContext, void *pInfo,NFCSTATUS Status); 60 | NFCSTATUS phNciNfc_NfceeActionNtfHandler(void *pContext, void *pInfo, NFCSTATUS Status); 61 | NFCSTATUS phNciNfc_NfceeProcessRfActvtdNtf(void *pContext,uint8_t *pBuff, uint16_t Len); 62 | NFCSTATUS phNciNfc_NfceeDiscReqNtfHandler(void *pContext, void *pInfo, NFCSTATUS Status); 63 | -------------------------------------------------------------------------------- /Cx/NfcCx/Readme.txt: -------------------------------------------------------------------------------- 1 | NFC Class Extension (NfcCx) 2 | 3 | Prerequisites 4 | - Windows PC 5 | - Visual Studio 2015 (includes Windows 10 SDK) 6 | - Windows 10 WDK 7 | 8 | 9 | Building the NfcCx 10 | 11 | In order to build the NfcCx solution, you will need to get WdfCxProxy.lib from Microsoft and place it for the appropriate platform in the following directory: 12 | 13 | $(SolutionDir)libs\$(Platform) 14 | 15 | where $(Platform) can be "Win32", "x64", or "ARM". 16 | 17 | Once you have built the solution, you will need to deploy NfcCx.dll to the device. 18 | 19 | 20 | Deploying to desktop 21 | 22 | Acquire permission to modify NfcCx.dll - one time setup 23 | 1. Open command prompt as administrator 24 | 2. Run: cd %SystemRoot%\System32\drivers\UMDF 25 | 3. Run: takeown /f NfcCx.dll 26 | 4. Run the following command, replacing with the username obtained from the output of the previous command: icacls NfcCx.dll /grant :M 27 | You should now be able to copy+paste the NfcCx.dll you built into %SystemRoot%\System32\drivers\UMDF. 28 | 29 | When copying NfcCx.dll to %SystemRoot%\System32\drivers\UMDF, you will need to make sure that no driver is using that dll. You can use Device Manager to disable any driver that is using NfcCx.dll. You can open Device Manager by pressing the Windows key + R and then entering "devmgmt.msc" into the Windows Run window. To disable a driver, right-click it, then click "Disable". Then you can copy+paste NfcCx.dll into %SystemRoot%\System32\drivers\UMDF. To re-enable a driver, right-click it in Device Manager, then click "Enable". 30 | 31 | 32 | Deploying to phone 33 | 34 | You will need a phone that is engineering- or retail-unlocked. To deploy NfcCx.dll to the phone, you will need to plug it into a PC via USB. 35 | 36 | Acquire permission to modify NfcCx.dll - one time setup 37 | 1. Put the phone in mass storage mode. To do this, you must first put the phone into flashing mode by holding the volume up button while the phone is booting. Then run the following command: ffutool.exe -massStorage 38 | - FFUTool.exe is part of the WDK. After installing the WDK, you can find it here: %ProgramFiles(x86)%\Windows Kits\10\Tools\bin\i386\ 39 | 2. You should see the phone enumerate as a storage drive in File Explorer. It will have a drive letter associated with it. Open up command prompt as administrator and navigate to this drive with the following command: cd /d 40 | - For example: cd /d G: 41 | 3. Run: cd Windows\System32\Drivers\UMDF 42 | 4. Run: takeown /f NfcCx.dll 43 | 5. Run: icacls NfcCx.dll /grant Administrators:M 44 | You should now be able to put a *signed* copy of NfcCx.dll into C:\Windows\System32\Drivers\UMDF on the phone while the phone is in mass storage mode. 45 | 46 | Signing NfcCx.dll 47 | 1. Set up the signing environment by following the instructions here: https://msdn.microsoft.com/en-us/library/windows/hardware/dn756804%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 48 | 2. Sign NfcCx.dll by following the instructions here: https://msdn.microsoft.com/en-us/library/windows/hardware/dn789217%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 49 | -------------------------------------------------------------------------------- /Cx/device.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All Rights Reserved 4 | 5 | Module Name: 6 | 7 | device.h 8 | 9 | Abstract: 10 | 11 | Cx Device declarations. 12 | 13 | Environment: 14 | 15 | User-mode Driver Framework 16 | 17 | --*/ 18 | 19 | #pragma once 20 | 21 | // 22 | // The device extension for the Nfc Class extension 23 | // 24 | typedef struct _NFCCX_FDO_CONTEXT { 25 | 26 | WDFDEVICE Device; 27 | 28 | // 29 | // Pointer to the class extension client context 30 | // 31 | PNFCCX_CLIENT_GLOBALS NfcCxClientGlobal; 32 | 33 | // 34 | // State 35 | // 36 | _Guarded_by_(HasFailedWaitLock) 37 | BOOLEAN HasFailed; 38 | WDFWAITLOCK HasFailedWaitLock; 39 | 40 | // 41 | // Power State 42 | // 43 | BOOLEAN NfpRadioInterfaceCreated; 44 | BOOLEAN SERadioInterfaceCreated; 45 | 46 | BOOLEAN DisablePowerManagerStopIdle; 47 | BOOLEAN DisableRfInterfaces; 48 | 49 | PNFCCX_POWER_MANAGER Power; 50 | 51 | // 52 | // Registry-provided config 53 | // 54 | BOOLEAN LogNciDataMessages; 55 | 56 | // 57 | // IO Queues 58 | // 59 | WDFQUEUE DefaultQueue; 60 | WDFQUEUE SelfQueue; 61 | 62 | // 63 | // RF interface 64 | // 65 | PNFCCX_RF_INTERFACE RFInterface; 66 | 67 | // 68 | // Tml interface 69 | // 70 | PNFCCX_TML_INTERFACE TmlInterface; 71 | 72 | // 73 | // Pub/Sub DDI 74 | // 75 | PNFP_INTERFACE NfpInterface; 76 | 77 | // 78 | // SE DDI 79 | // 80 | PNFCCX_SE_INTERFACE SEInterface; 81 | 82 | // 83 | // SmartCard DDI 84 | // 85 | PNFCCX_SC_INTERFACE SCInterface; 86 | 87 | // 88 | // eSE (SmartCard) DDI 89 | // 90 | PNFCCX_ESE_INTERFACE ESEInterface; 91 | 92 | // 93 | // DTA interface 94 | // 95 | PNFCCX_DTA_INTERFACE DTAInterface; 96 | 97 | } NFCCX_FDO_CONTEXT, *PNFCCX_FDO_CONTEXT; 98 | 99 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(NFCCX_FDO_CONTEXT, NfcCxFdoGetContext) 100 | 101 | // 102 | // Wdf callbacks 103 | // 104 | EVT_WDF_OBJECT_CONTEXT_CLEANUP NfcCxFdoContextCleanup; 105 | EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL NfcCxEvtDefaultIoControl; 106 | EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL NfcCxEvtSelfIoControl; 107 | 108 | NTSTATUS 109 | NfcCxFdoCreate( 110 | _In_ PNFCCX_FDO_CONTEXT FdoContext 111 | ); 112 | 113 | NTSTATUS 114 | NfcCxFdoReadCxDriverRegistrySettings( 115 | _Out_ BOOLEAN* pLogNciDataMessages 116 | ); 117 | 118 | NTSTATUS 119 | NfcCxFdoReadPersistedDeviceRegistrySettings( 120 | _In_ PNFCCX_FDO_CONTEXT FdoContext 121 | ); 122 | 123 | NTSTATUS 124 | NfcCxFdoWritePersistedDeviceRegistrySettings( 125 | _In_ PNFCCX_FDO_CONTEXT FdoContext 126 | ); 127 | 128 | NTSTATUS 129 | NfcCxFdoInitialize( 130 | _In_ PNFCCX_FDO_CONTEXT FdoContext 131 | ); 132 | 133 | NTSTATUS 134 | NfcCxFdoDeInitialize( 135 | _In_ PNFCCX_FDO_CONTEXT FdoContext 136 | ); 137 | 138 | NTSTATUS 139 | NfcCxFdoCleanup( 140 | _In_ PNFCCX_FDO_CONTEXT FdoContext 141 | ); 142 | 143 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_Pch.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2012 Microsoft Corporation 4 | 5 | Module Name: 6 | phLibNfc_Pch.h 7 | 8 | Abstract: 9 | This module contains the precompiled headers for the NfcCoreLib component 10 | 11 | Environment: 12 | User mode. 13 | 14 | --*/ 15 | 16 | #pragma once 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include "phNciNfc_Context.h" 37 | #include "phNciNfc_Core.h" 38 | #include "phNciNfc_CoreStatus.h" 39 | #include "phNciNfc_CoreMemMgr.h" 40 | #include "phNciNfc_CoreUtils.h" 41 | #include "phNciNfc_Utils.h" 42 | #include "phNciNfc_Common.h" 43 | #include "phNciNfc_RfConfig.h" 44 | #include "phNciNfc_ListenMgmt.h" 45 | #include "phNciNfc_ListenNfcDep.h" 46 | #include "phNciNfc_ListenIsoDep.h" 47 | #include "phNciNfc_RFReader.h" 48 | #include "phNciNfc_Init.h" 49 | #include "phNciNfc_Discovery.h" 50 | #include "phNciNfc_LogicalConn.h" 51 | #include "phNciNfc_Common.h" 52 | #include "phNciNfc_CoreRecvMgr.h" 53 | #include "phNciNfc_PollMgmt.h" 54 | #include "phNciNfc_DbgDescription.h" 55 | #include "phNciNfc_LoglConnMgmt.h" 56 | #include "phNciNfc_NfceeMgmt.h" 57 | #include "phNciNfc_TlvUtils.h" 58 | #include "phNciNfc_NfcIMgmt.h" 59 | #include "phNciNfc_PollNfcDep.h" 60 | #include "phNciNfc_ListenNfcDep.h" 61 | #include "phNciNfc_NfcIMgmt.h" 62 | #include "phHciNfc_Core.h" 63 | #include "phHciNfc_CoreRxMemMgr.h" 64 | #include "phHciNfc_Pipe.h" 65 | 66 | #include 67 | #include "phLibNfc_Internal.h" 68 | #include "phLibNfc_Initiator.h" 69 | #include 70 | #include "phLibNfc_IoctlUtils.h" 71 | #include "phLibNfc_State.h" 72 | #include "phLibNfc_Sequence.h" 73 | #include "phLibNfc_Init.h" 74 | #include "phLibNfc_Discovery.h" 75 | #include "phLibNfc_Target.h" 76 | #include "phLibNfc_Se.h" 77 | #include "phLibNfc_Hci.h" 78 | 79 | #include 80 | #include 81 | #include 82 | #include 83 | #include 84 | #include 85 | #include 86 | #include 87 | #include 88 | #include 89 | #include 90 | #include 91 | #include 92 | #include 93 | #include 94 | 95 | #include 96 | #include 97 | #include 98 | #include 99 | #include 100 | #include 101 | #include 102 | 103 | #include "NfcCoreLibTracing.h" 104 | 105 | _Analysis_mode_(_Analysis_code_type_user_driver_) 106 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/NciSimConnector.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "NciPacket.h" 19 | 20 | struct NciSimCallbackMessage 21 | { 22 | public: 23 | NciSimCallbackMessage(std::vector&& data) : 24 | _Data(std::move(data)) 25 | { 26 | } 27 | 28 | DWORD Length() const 29 | { 30 | return DWORD(_Data.size()); 31 | } 32 | 33 | const NciSimCallbackHeader* Header() const 34 | { 35 | return reinterpret_cast(_Data.data()); 36 | } 37 | 38 | private: 39 | std::vector _Data; 40 | }; 41 | 42 | // Connects the NFC CX Test Driver's test driver interface and provides a wrapper API. 43 | class NciSimConnector 44 | { 45 | public: 46 | NciSimConnector(); 47 | ~NciSimConnector(); 48 | 49 | const std::wstring& DeviceId(); 50 | 51 | std::shared_ptr StartHostAsync(); 52 | std::shared_ptr StopHostAsync(); 53 | void SendNciWriteCompleted(); 54 | void SendNciRead(const NciPacket& packet); 55 | void SendSequenceCompleted(NTSTATUS status, ULONG flags); 56 | NciSimCallbackMessage ReceiveLibNfcThreadCallback(); 57 | NciSimCallbackMessage ReceivePowerCallback(); 58 | std::shared_ptr> WhenLibNfcThreadCallbackAvailableAsync(); 59 | std::shared_ptr> WhenPowerCallbackAvailableAsync(); 60 | 61 | private: 62 | static void ThrowIfWin32BoolFailed(BOOL succeeded); 63 | static void ThrowIfWin32Failed(DWORD error); 64 | 65 | void SendCommandSync(_In_ DWORD ioctl, _In_reads_bytes_opt_(inputSize) const void* input, _In_ DWORD inputSize); 66 | 67 | void StartGetNextCallback(); 68 | void CallbackRetrieved(Async::AsyncTaskBase& ioOperation); 69 | 70 | UniqueHandle _DriverHandle; 71 | std::vector _CallbackDataBuffer; 72 | std::wstring _DeviceId; 73 | 74 | enum class CallbacksState 75 | { 76 | // The get-callbacks loop is running. 77 | Started, 78 | // The class is shutting down and has requested that the get-callbacks loop stop. 79 | Stopping, 80 | // The get-callbacks is not running. 81 | Stopped, 82 | }; 83 | 84 | std::mutex _CallbacksLock; 85 | std::condition_variable _CallbacksUpdatedEvent; 86 | CallbacksState _CallbacksState = CallbacksState::Stopped; 87 | DWORD _CallbackAllocSize = NciPacketRaw::MaxLength + sizeof(NciSimCallbackHeader); 88 | std::weak_ptr _CurrentCallbackIo; 89 | std::queue _LibNfcThreadCallbacks; 90 | std::queue _PowerCallbacks; 91 | std::vector>> _LibNfcThreadCallbackWaiters; 92 | std::vector>> _PowerCallbackWaiters; 93 | }; 94 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_Se.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | /* Watch dog time for callback */ 12 | #define PH_LIBNFC_WD_TIMEOUT 5000 13 | 14 | /* Listen Nfc-A technology supported by NFEE */ 15 | #define PH_LIBNFC_SE_LSTN_NFC_A_SUPP 0x01 16 | /* Listen Nfc-B technology supported by NFEE */ 17 | #define PH_LIBNFC_SE_LSTN_NFC_B_SUPP 0x02 18 | /* Listen Nfc-F technology supported by NFEE */ 19 | #define PH_LIBNFC_SE_LSTN_NFC_F_SUPP 0x04 20 | 21 | extern phLibNfc_Sequence_t gphLibNfc_SetSeModeSeq[]; 22 | extern phLibNfc_Sequence_t gphLibNfc_SePowerAndLinkCtrlSeq[]; 23 | 24 | #include 25 | #include "phNciNfcTypes.h" 26 | 27 | #define PH_LIBNFC_GETRFCONFIG_LENGTH 0x49 28 | #define PH_LIBNFC_RF_DATA_OFFSET 6 29 | 30 | /* RF Technology A */ 31 | #define PH_LIBNFC_UIDREGSIZE_A_TECH 10 32 | #define PH_LIBNFC_ATQASIZE_A_TECH 2 33 | #define PH_LIBNFC_APPLICATIONDATASIZE_A_TECH 15 34 | #define PH_LIBNFC_DATAMAXRATESIZE_A_TECH 3 35 | 36 | /* RF Technology B */ 37 | #define PH_LIBNFC_PUPIREG_SIZE_B_TECH 4 38 | #define PH_LIBNFC_ATQASIZE_B_TECH 4 39 | #define PH_LIBNFC_HIGHLLAYERRSP_B_TECH 15 40 | #define PH_LIBNFC_DATAMAXRATESIZE_B_TECH 3 41 | 42 | extern 43 | void phLibNfc_SENtfHandler(void* pContext, 44 | phNciNfc_NotificationType_t eNtfType, 45 | pphNciNfc_NotificationInfo_t pSEInfo, 46 | NFCSTATUS status); 47 | 48 | extern 49 | void phLibNfc_InvokeSeNtfCallback(void* pContext, 50 | void* pInfo, 51 | NFCSTATUS status, 52 | uint8_t bPipeId, 53 | phLibNfc_eSE_EvtType_t eEventType); 54 | 55 | extern NFCSTATUS 56 | phLibNfc_LaunchNfceeDiscCompleteSequence(void *pContext, 57 | NFCSTATUS wStatus, 58 | void *pInfo); 59 | 60 | extern 61 | void phLibNfc_ConfigRoutingTableCb(void *pContext, 62 | NFCSTATUS wStatus, 63 | void *pInfo); 64 | 65 | extern 66 | void phLibNfc_SeEventHotPlugCb(void* pContext, 67 | NFCSTATUS wStatus, 68 | void *pInfo); 69 | 70 | extern NFCSTATUS 71 | phLibNfc_SE_GetIndex(void* pContext, 72 | phLibNfc_SE_Status_t bSeState, 73 | uint8_t *pbIndex); 74 | 75 | extern phHciNfc_HostID_t 76 | phLibNfc_SE_GetHciHostId(void* pContext, 77 | pphNciNfc_NfceeInfo_t pNfceeInfo); 78 | 79 | NFCSTATUS phLibNfc_DelayForSeNtfProc(void* pContext,NFCSTATUS status,void* pInfo); 80 | NFCSTATUS phLibNfc_DelayForSeNtf(void* pContext, NFCSTATUS status, void* pInfo); 81 | NFCSTATUS phLibNfc_DelayForNfceeAtrProc(void* pContext, NFCSTATUS status, void* pInfo); 82 | NFCSTATUS phLibNfc_DelayForNfceeAtr(void* pContext, NFCSTATUS status, void* pInfo); 83 | -------------------------------------------------------------------------------- /Test/NfcCxTests/Simulation/TestDeviceInstall.cpp: -------------------------------------------------------------------------------- 1 | #include "Precomp.h" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include "NciSimConnector.h" 9 | #include "SimSequenceRunner.h" 10 | #include "TestDeviceInstall.h" 11 | 12 | TestDeviceInstall::TestDeviceInstall() 13 | { 14 | GUID instanceId; 15 | VerifyHresultSucceeded(CoCreateGuid(&instanceId)); 16 | 17 | WCHAR instanceIdString[40]; 18 | (void)StringFromGUID2(instanceId, instanceIdString, ARRAYSIZE(instanceIdString)); 19 | 20 | SW_DEVICE_CREATE_INFO deviceCreateInfo = {}; 21 | deviceCreateInfo.cbSize = sizeof(SW_DEVICE_CREATE_INFO); 22 | deviceCreateInfo.pszInstanceId = instanceIdString; 23 | deviceCreateInfo.pszzHardwareIds = L"root\\NfcCxTestDevice\0"; // Multi-string (i.e. null-null terminated list of strings) 24 | deviceCreateInfo.CapabilityFlags = SWDeviceCapabilitiesSilentInstall | SWDeviceCapabilitiesDriverRequired; 25 | 26 | // Install the device. 27 | VerifyHresultSucceeded(SwDeviceCreate( 28 | L"NfcCxTestDevice", // enumerator name 29 | L"HTREE\\ROOT\\0", // parent device (system root) 30 | &deviceCreateInfo, // info 31 | 0, // properties count 32 | nullptr, // properties 33 | DeviceCreatedCallback, 34 | this, 35 | &_Device)); 36 | 37 | // Wait for the DeviceCreateCallback to execute. 38 | HRESULT createResult = _CreateResult; 39 | while (createResult == E_PENDING) 40 | { 41 | static_assert(sizeof(createResult) == sizeof(_CreateResult), "std::atomic has an unsupported implementation"); 42 | WaitOnAddress(&_CreateResult, &createResult, sizeof(createResult), INFINITE); 43 | 44 | createResult = _CreateResult; 45 | } 46 | 47 | VerifyHresultSucceeded(createResult); 48 | 49 | // Handle the initial D0 entry/exit that occurs during device initialization. 50 | NciSimConnector simConnector; 51 | SimSequenceRunner::Run(simConnector, InitSequences::Power::D0Entry); 52 | SimSequenceRunner::Run(simConnector, InitSequences::Power::D0Exit); 53 | } 54 | 55 | TestDeviceInstall::~TestDeviceInstall() 56 | { 57 | if (_Device) 58 | { 59 | // Uninstall the device. 60 | SwDeviceClose(_Device); 61 | _Device = nullptr; 62 | } 63 | } 64 | 65 | void 66 | TestDeviceInstall::DeviceCreatedCallback( 67 | _In_ HSWDEVICE hSwDevice, 68 | _In_ HRESULT CreateResult, 69 | _In_opt_ void* pContext, 70 | _In_opt_ PCWSTR pszDeviceInstanceId) 71 | { 72 | auto me = reinterpret_cast(pContext); 73 | me->DeviceCreated(hSwDevice, CreateResult, pszDeviceInstanceId); 74 | } 75 | 76 | void 77 | TestDeviceInstall::DeviceCreated( 78 | _In_ HSWDEVICE /*hSwDevice*/, 79 | _In_ HRESULT CreateResult, 80 | _In_opt_ PCWSTR pszDeviceInstanceId) 81 | { 82 | _DeviceInstanceId = pszDeviceInstanceId; 83 | _CreateResult = CreateResult; 84 | WakeByAddressAll(&_CreateResult); 85 | } 86 | 87 | void 88 | TestDeviceInstall::VerifyHresultSucceeded(HRESULT hr) 89 | { 90 | if (!SUCCEEDED(hr)) 91 | { 92 | throw std::system_error(hr, std::system_category(), "HRESULT failed."); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Test/NfcCxTests/IOHelpers/DriverHandleFactory.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include "DeviceQuery.h" 8 | #include "DriverHandleFactory.h" 9 | #include "IoOperation.h" 10 | 11 | std::wstring 12 | DriverHandleFactory::FindProximityInterfaceForDevice(_In_ PCWSTR deviceName) 13 | { 14 | // Find the proximity interface for the device. 15 | std::vector nfpInterfaces = DeviceQuery::FindDriverInterfaces(deviceName, GUID_DEVINTERFACE_NFP); 16 | 17 | // Only a single interface is expected to be found. 18 | VERIFY_ARE_EQUAL(1u, nfpInterfaces.size()); 19 | return std::move(nfpInterfaces[0]); 20 | } 21 | 22 | std::wstring 23 | DriverHandleFactory::FindSmartcardInterfaceForDevice( 24 | _In_ PCWSTR deviceName, 25 | _In_ ::winrt::Windows::Devices::SmartCards::SmartCardReaderKind readerKind) 26 | { 27 | std::vector nfcScInterfaces = DeviceQuery::GetSmartcardInterfacesOfType(deviceName, BYTE(readerKind)); 28 | VERIFY_ARE_EQUAL(1u, nfcScInterfaces.size()); 29 | 30 | return std::move(nfcScInterfaces[0]); 31 | } 32 | 33 | UniqueHandle 34 | DriverHandleFactory::OpenSubscriptionHandle(_In_ PCWSTR deviceName, _In_ PCWSTR messageType) 35 | { 36 | // Find the proximity interface for the device. 37 | std::wstring subId = FindProximityInterfaceForDevice(deviceName); 38 | 39 | // Create the name for the subscription. 40 | subId += L"\\Subs\\"; 41 | subId += messageType; 42 | 43 | // Open the device handle. 44 | UniqueHandle nfpSubInterface(CreateFile( 45 | subId.c_str(), 46 | GENERIC_READ, 47 | 0, 48 | nullptr, 49 | OPEN_EXISTING, 50 | FILE_FLAG_OVERLAPPED, 51 | nullptr)); 52 | VERIFY_WIN32_BOOL_SUCCEEDED(INVALID_HANDLE_VALUE != nfpSubInterface.Get()); 53 | 54 | return std::move(nfpSubInterface); 55 | } 56 | 57 | UniqueHandle 58 | DriverHandleFactory::OpenSmartcardHandle( 59 | _In_ PCWSTR deviceName, 60 | _In_ ::winrt::Windows::Devices::SmartCards::SmartCardReaderKind readerKind) 61 | { 62 | std::wstring smartcardInterfaceName = FindSmartcardInterfaceForDevice(deviceName, readerKind); 63 | 64 | UniqueHandle scInterface(CreateFile( 65 | smartcardInterfaceName.c_str(), 66 | GENERIC_READ, 67 | 0, 68 | nullptr, 69 | OPEN_EXISTING, 70 | FILE_FLAG_OVERLAPPED, 71 | nullptr)); 72 | VERIFY_WIN32_BOOL_SUCCEEDED(INVALID_HANDLE_VALUE != scInterface.Get()); 73 | 74 | return std::move(scInterface); 75 | } 76 | 77 | std::shared_ptr<::Async::AsyncTaskBase> 78 | DriverHandleFactory::OpenSmartcardHandleAsync( 79 | _In_ PCWSTR deviceName, 80 | _In_ ::winrt::Windows::Devices::SmartCards::SmartCardReaderKind readerKind) 81 | { 82 | return Async::RunBackgroundTask( 83 | [deviceName = std::wstring(deviceName), readerKind]() 84 | { 85 | return OpenSmartcardHandle(deviceName.c_str(), readerKind); 86 | }); 87 | } 88 | 89 | std::shared_ptr<::Async::AsyncTaskBase> 90 | DriverHandleFactory::CloseHandleAsync(UniqueHandle&& obj) 91 | { 92 | return Async::RunBackgroundTask( 93 | [obj = std::move(obj)]() 94 | { 95 | }); 96 | } 97 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/Fri/phFriNfc_SnepProtocolUtility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | NFCSTATUS phLibNfc_SnepProtocolReq (pphLibNfc_SnepClientSession_t pClientSessionContext); 14 | 15 | NFCSTATUS phLibNfc_SnepProtocolSendResponse (pphLibNfc_SnepServerConnection_t pSnepServerConnection); 16 | 17 | void SnepSocketSendCb (void *pContext, NFCSTATUS status); 18 | 19 | void SnepSocketSendData (void *pContext, NFCSTATUS status); 20 | void SnepSocketReceiveData (void *pContext, NFCSTATUS status); 21 | void SnepSocketSendDataSrv (void *pContext, NFCSTATUS status); 22 | void SnepSocketReceiveDataCli (void *pContext, NFCSTATUS status); 23 | 24 | void LlcpSocketSendResponseCb (void *pContext, NFCSTATUS status); 25 | 26 | phNfc_sData_t* phLibNfc_PrepareSnepPacket(phLibNfc_SnepPacket_t packetType, phNfc_sData_t *pData, 27 | uint8_t version, uint32_t acceptableLength); 28 | 29 | void LlcpSocketRecvCbForRspContinue(void* pContext, NFCSTATUS status); 30 | 31 | void LlcpSocketRecvCbForInvalidResponse(void* pContext, NFCSTATUS status); 32 | 33 | void LlcpSocketRecvCbForInvalidRequest(void* pContext, NFCSTATUS status); 34 | 35 | void LlcpSocketRecvCbForReqContinue(void* pContext, NFCSTATUS status); 36 | 37 | NFCSTATUS CollectReply(pphLibNfc_SnepClientSession_t pClientSessionContext); 38 | 39 | void LlcpSocketRecvCbForRecvBegin(void* pContext, 40 | NFCSTATUS status); 41 | 42 | NFCSTATUS GetNfcStatusFromSnepResponse(uint8_t snepCode); 43 | 44 | uint8_t GetSnepResponseCodeFromPacketType(phLibNfc_SnepPacket_t packetType); 45 | uint8_t GetSnepResponseCodeFromNfcStatus(NFCSTATUS nfcStatus); 46 | 47 | phLibNfc_SnepPacket_t GetSnepPacketType(NFCSTATUS nfcStatus); 48 | 49 | void sendSnepRequestContinue(pphLibNfc_SnepClientSession_t pClientSessionContext); 50 | void sendSnepRequestReject(pphLibNfc_SnepClientSession_t pClientSessionContext); 51 | 52 | void LlcpSocketSendCbForReqContinue (void *pContext, NFCSTATUS status); 53 | void LlcpSocketSendCbForReqReject (void *pContext, NFCSTATUS status); 54 | void LlcpSocketReceiveCb(void* pContext, NFCSTATUS status); 55 | 56 | void phLibNfc_ClearMemNCallCb(pphLibNfc_SnepClientSession_t pClientSessionContext, NFCSTATUS status, 57 | phNfc_sData_t *pReqResponse); 58 | 59 | void phLibNfc_ClearMemNCallResponseCb(pphLibNfc_SnepServerConnection_t pSnepServerConnection, 60 | NFCSTATUS status); 61 | 62 | void phLibNfc_NotifyUpperLayer(pphLibNfc_SnepServerConnection_t pServerConnectionContext); 63 | 64 | void SnepSrvSendContinuecomplete (void *pContext, NFCSTATUS status, phLibNfc_Handle ConnHandle); 65 | void SnepSrvSendcompleteInternal (void* pContext, NFCSTATUS Status, phLibNfc_Handle ConnHandle); 66 | 67 | BOOL areVersionsCompatible(uint8_t ver1, uint8_t ver2); 68 | 69 | void ResetServerConnectionContext(pphLibNfc_SnepServerConnection_t pServerConnectionContext); 70 | void ResetCliDataContext(pphLibNfc_SnepClientSession_t pClientSessionContext); 71 | 72 | void SnepSocketRecvCbForServer(void* pContext, NFCSTATUS status); 73 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/inc/phNfcLlcpTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | #define PHFRINFC_LLCP_MIU_DEFAULT 128 /**< Default MIU value (in bytes).*/ 13 | #define PHFRINFC_LLCP_WKS_DEFAULT 1 /**< Default WKS value (bitfield).*/ 14 | #define PHFRINFC_LLCP_LTO_DEFAULT 10 /**< Default LTO value (in step of 10ms).*/ 15 | #define PHFRINFC_LLCP_RW_DEFAULT 1 /**< Default RW value (in frames).*/ 16 | #define PHFRINFC_LLCP_OPTION_DEFAULT 0 /**< Default OPTION value (in frames).*/ 17 | #define PHFRINFC_LLCP_MIUX_DEFAULT 0 /**< Default MIUX value (in bytes) */ 18 | #define PHFRINFC_LLCP_MIUX_MAX 0x7FF /**< Max MIUX value (in bytes) */ 19 | #define PHFRINFC_LLCP_PDU_HEADER_MAX 3 /**< Max size of PDU header (in bytes) */ 20 | #define PHFRINFC_LLCP_SN_MAX_LENGTH 255 /**< Max length value for the Service Name */ 21 | #define PHFRINFC_LLCP_RW_MAX 15 /**< Max RW value (in frames).*/ 22 | 23 | #define PHFRINFC_LLCP_NB_SOCKET_MAX 5 /**< Max.number of simultaneous sockets */ 24 | #define PHFRINFC_LLCP_SNL_RESPONSE_MAX 256 /**< Max.number of simultaneous discovery requests */ 25 | 26 | #define PHFRINFC_LLCP_ERR_DISCONNECTED 0x00 27 | #define PHFRINFC_LLCP_ERR_FRAME_REJECTED 0x01 28 | #define PHFRINFC_LLCP_ERR_BUSY_CONDITION 0x02 29 | #define PHFRINFC_LLCP_ERR_NOT_BUSY_CONDITION 0x03 30 | 31 | #define PHFRINFC_LLCP_DM_OPCODE_DISCONNECTED 0x00 32 | #define PHFRINFC_LLCP_DM_OPCODE_SAP_NOT_ACTIVE 0x01 33 | #define PHFRINFC_LLCP_DM_OPCODE_SAP_NOT_FOUND 0x02 34 | #define PHFRINFC_LLCP_DM_OPCODE_CONNECT_REJECTED 0x03 35 | #define PHFRINFC_LLCP_DM_OPCODE_SAP_UNAVAILABLE 0x10 36 | #define PHFRINFC_LLCP_DM_OPCODE_SERVICE_UNAVAILABLE 0x11 37 | #define PHFRINFC_LLCP_DM_OPCODE_CONNECT_NOT_ACCEPTED 0x20 38 | #define PHFRINFC_LLCP_DM_OPCODE_SOCKET_NOT_AVAILABLE 0x21 39 | 40 | typedef enum phFriNfc_LlcpMac_eLinkStatus 41 | { 42 | phFriNfc_LlcpMac_eLinkDefault, 43 | phFriNfc_LlcpMac_eLinkActivated, 44 | phFriNfc_LlcpMac_eLinkDeactivated 45 | }phFriNfc_LlcpMac_eLinkStatus_t; 46 | 47 | typedef enum phFriNfc_LlcpTransport_eSocketType 48 | { 49 | phFriNfc_LlcpTransport_eDefaultType, 50 | phFriNfc_LlcpTransport_eConnectionOriented, 51 | phFriNfc_LlcpTransport_eConnectionLess 52 | }phFriNfc_LlcpTransport_eSocketType_t; 53 | 54 | typedef struct phFriNfc_LlcpTransport_sSocketOptions 55 | { 56 | /** The remote Maximum Information Unit Extension (NOTE: this is MIUX, not MIU !)*/ 57 | uint16_t miu; 58 | /** The Receive Window size (4 bits)*/ 59 | uint8_t rw; 60 | 61 | }phFriNfc_LlcpTransport_sSocketOptions_t; 62 | 63 | typedef struct phFriNfc_Llcp_sLinkParameters 64 | { 65 | /** The remote Maximum Information Unit (NOTE: this is MIU, not MIUX !)*/ 66 | uint16_t miu; 67 | /** The remote Well-Known Services*/ 68 | uint16_t wks; 69 | /** The remote Link TimeOut (in 1/100s)*/ 70 | uint8_t lto; 71 | /** The remote options*/ 72 | uint8_t option; 73 | 74 | } phFriNfc_Llcp_sLinkParameters_t; 75 | -------------------------------------------------------------------------------- /libs/NfcCoreLib/lib/LibNfc/phLibNfc_ContextMgmt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modifications Copyright (c) Microsoft. All rights reserved. 3 | * 4 | * Original code Copyright (c), NXP Semiconductors 5 | */ 6 | 7 | #pragma once 8 | 9 | #include"phLibNfc_Snep.h" 10 | 11 | /* ----------------------- SNEP Server -------------------------- */ 12 | 13 | BOOL phLibNfc_SnepServer_InitServerContext(void); 14 | 15 | /* Retreives a Server Context 16 | * If NULL is returned indicates context is not initialized */ 17 | phLibNfc_SnepServerContext_t *phLibNfc_SnepServer_GetServerContext(void); 18 | 19 | /* Removes a Server Context if server count is '0' 20 | * Should be called in every Server De-init. 21 | * Returns FALSE if still active server sessions are present */ 22 | BOOL phLibNfc_SnepServer_RemoveServerContext(void); 23 | 24 | /* Retreives a Server Session matching the given Handle */ 25 | phLibNfc_SnepServerSession_t * 26 | phLibNfc_SnepServer_GetSessionContext(phLibNfc_Handle ServerHandle); 27 | 28 | /* Retreives a Server Connection matching the given Handle */ 29 | phLibNfc_SnepServerConnection_t * 30 | phLibNfc_SnepServer_GetConnectionContext(phLibNfc_Handle ConnHandle); 31 | 32 | /* Adds a new Server to the Server Context */ 33 | phLibNfc_SnepServerSession_t * 34 | phLibNfc_SnepServer_AddSession(void); 35 | 36 | /* Adds a new Connection to the Server Session */ 37 | phLibNfc_SnepServerConnection_t * 38 | phLibNfc_SnepServer_AddConnection(phLibNfc_Handle ServerHandle); 39 | 40 | /* Removes a Server session from the Server Context */ 41 | NFCSTATUS 42 | phLibNfc_SnepServer_RemoveSession(phLibNfc_Handle ServerHandle); 43 | 44 | /* Removes a Connection from the Server Session Context */ 45 | NFCSTATUS 46 | phLibNfc_SnepServer_RemoveOneConnection(phLibNfc_Handle ConnHandle); 47 | 48 | /* Removes all Connections from a Server Session Context */ 49 | NFCSTATUS 50 | phLibNfc_SnepServer_RemoveAllConnections(phLibNfc_Handle ServerHandle); 51 | 52 | /* Retreives a Server Session matching the connection */ 53 | phLibNfc_SnepServerSession_t * 54 | phLibNfc_SnepServer_GetSessionByConnection(phLibNfc_Handle ConnHandle); 55 | 56 | /* ----------------------- SNEP Client -------------------------- */ 57 | 58 | /* Initializes the Client Context 59 | * Returns TRUE if succeeded */ 60 | BOOL phLibNfc_SnepServer_InitClientContext(void); 61 | 62 | /* Retreives a Client Context 63 | * If NULL is returned indicates context allocation failed */ 64 | phLibNfc_SnepClientContext_t * 65 | phLibNfc_SnepClient_GetClientContext(void); 66 | 67 | /* Removes a Client Context if Client count is '0' 68 | * Should be called in every Client De-init. 69 | * Returns FALSE if still Client sessions are present */ 70 | BOOL 71 | phLibNfc_SnepClient_RemoveClientContext(void); 72 | 73 | /* Retreives a Client Session matching the given Handle */ 74 | phLibNfc_SnepClientSession_t * 75 | phLibNfc_SnepClient_GetClientSession(phLibNfc_Handle ClientHandle); 76 | 77 | /* Adds a new Client session to the Client Context */ 78 | phLibNfc_SnepClientSession_t * 79 | phLibNfc_SnepClient_AddSession(void); 80 | 81 | /* Removes a Client from the Client Context */ 82 | NFCSTATUS 83 | phLibNfc_SnepClient_RemoveSession(phLibNfc_Handle ClientHandle); 84 | 85 | /* Removes a Incomplete Client from the Client Context */ 86 | NFCSTATUS 87 | phLibNfc_SnepClient_RemoveIncompleteSession(phLibNfc_SnepClientSession_t *pClientSession); 88 | 89 | /* Removes all Client Sessions from Client Context */ 90 | NFCSTATUS 91 | phLibNfc_SnepClient_RemoveAllSessions(void); 92 | -------------------------------------------------------------------------------- /Test/NfcCxTestDeviceDriver/Driver/Device.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | #include "ApiCallbacksManager.h" 10 | 11 | class FileObjectContext; 12 | 13 | // Holds all the context information for a device. 14 | class DeviceContext 15 | { 16 | public: 17 | static NTSTATUS DeviceAdd( 18 | _Inout_ PWDFDEVICE_INIT DeviceInit 19 | ); 20 | NTSTATUS ClientConnected( 21 | _In_ FileObjectContext* FileContext 22 | ); 23 | void ClientDisconnected( 24 | _In_ FileObjectContext* FileContext 25 | ); 26 | 27 | private: 28 | DeviceContext() = default; 29 | ~DeviceContext() = default; 30 | static void ShutdownCallback( 31 | _In_ WDFOBJECT Object 32 | ); 33 | void Shutdown(); 34 | static void DestroyCallback( 35 | _In_ WDFOBJECT Object 36 | ); 37 | static NTSTATUS D0EntryCallback( 38 | _In_ WDFDEVICE Device, 39 | _In_ WDF_POWER_DEVICE_STATE PreviousState 40 | ); 41 | NTSTATUS D0Entry( 42 | _In_ WDF_POWER_DEVICE_STATE PreviousState 43 | ); 44 | static NTSTATUS D0ExitCallback( 45 | _In_ WDFDEVICE Device, 46 | _In_ WDF_POWER_DEVICE_STATE TargetState 47 | ); 48 | NTSTATUS D0Exit( 49 | _In_ WDF_POWER_DEVICE_STATE TargetState 50 | ); 51 | static void WriteNciPacketCallback( 52 | _In_ WDFDEVICE Device, 53 | _In_ WDFREQUEST Request 54 | ); 55 | void WriteNciPacket( 56 | _In_ WDFREQUEST Request 57 | ); 58 | static void DeviceIoCallback( 59 | _In_ WDFDEVICE Device, 60 | _In_ WDFREQUEST Request, 61 | _In_ size_t OutputBufferLength, 62 | _In_ size_t InputBufferLength, 63 | _In_ ULONG IoControlCode 64 | ); 65 | void DeviceIo( 66 | _In_ WDFREQUEST Request, 67 | _In_ size_t OutputBufferLength, 68 | _In_ size_t InputBufferLength, 69 | _In_ ULONG IoControlCode 70 | ); 71 | static void SequenceHandlerCallback( 72 | _In_ WDFDEVICE Device, 73 | _In_ NFC_CX_SEQUENCE Sequence, 74 | _In_ PFN_NFC_CX_SEQUENCE_COMPLETION_ROUTINE CompletionRoutine, 75 | _In_opt_ WDFCONTEXT CompletionContext 76 | ); 77 | void SequenceHandler( 78 | _In_ NFC_CX_SEQUENCE Sequence, 79 | _In_ PFN_NFC_CX_SEQUENCE_COMPLETION_ROUTINE CompletionRoutine, 80 | _In_opt_ WDFCONTEXT CompletionContext 81 | ); 82 | NTSTATUS CommandGetNextCallback( 83 | _In_ WDFREQUEST Request 84 | ); 85 | NTSTATUS CommandNciRead( 86 | _In_ WDFREQUEST Request 87 | ); 88 | NTSTATUS CommandHardwareEvent( 89 | _In_ WDFREQUEST Request 90 | ); 91 | NTSTATUS CommandSequenceHandlerComplete( 92 | _In_ WDFREQUEST Request 93 | ); 94 | NTSTATUS CommandNciWriteComplete( 95 | _In_ WDFREQUEST Request 96 | ); 97 | 98 | WDFDEVICE _Device = nullptr; 99 | 100 | ApiCallbacksManager _ApiCallbacksManager; 101 | 102 | WDFWAITLOCK _ClientLock = nullptr; 103 | FileObjectContext* _CurrentSimClient = nullptr; 104 | PFN_NFC_CX_SEQUENCE_COMPLETION_ROUTINE _SequenceCompleted = nullptr; 105 | WDFCONTEXT _SequenceCompletedContext = nullptr; 106 | WDFREQUEST _NciWriteRequest = nullptr; 107 | }; 108 | 109 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DeviceContext, DeviceGetContext); 110 | -------------------------------------------------------------------------------- /Test/NfcCxTests/IOHelpers/IoOperation.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All Rights Reserved 3 | // 4 | 5 | #include "Precomp.h" 6 | 7 | #include "IoOperation.h" 8 | 9 | std::shared_ptr 10 | IoOperation::DeviceIoControl(_In_ HANDLE driverHandle, _In_ DWORD ioctl, _In_reads_bytes_opt_(inputSize) const void* input, _In_ DWORD inputSize, _In_ DWORD outputBufferSize) 11 | { 12 | auto ioOperation = std::make_shared(PrivateToken{}, driverHandle, input, inputSize, outputBufferSize); 13 | 14 | void* inputBuffer = inputSize == 0 ? 15 | nullptr : 16 | ioOperation->_InputBuffer.data(); 17 | 18 | void* outputBuffer = outputBufferSize == 0 ? 19 | nullptr : 20 | ioOperation->_OutputBuffer.data(); 21 | 22 | // Ensure the object's memory stays around until the I/O operation has completed. 23 | ioOperation->_SelfRef = ioOperation; 24 | 25 | BOOL ioResult = ::DeviceIoControl(driverHandle, ioctl, inputBuffer, inputSize, outputBuffer, outputBufferSize, nullptr, &ioOperation->_Overlapped); 26 | if (!ioResult && GetLastError() != ERROR_IO_PENDING) 27 | { 28 | ioOperation->_SelfRef = nullptr; 29 | throw std::system_error(GetLastError(), std::system_category()); 30 | } 31 | 32 | return ioOperation; 33 | } 34 | 35 | IoOperation::IoOperation(PrivateToken, _In_ HANDLE driverHandle, _In_reads_bytes_opt_(inputSize) const void* input, _In_ DWORD inputSize, _In_ DWORD outputBufferSize) : 36 | _DriverHandle(driverHandle), 37 | _InputBuffer((const BYTE*)input, (const BYTE*)input + inputSize), 38 | _OutputBuffer(outputBufferSize) 39 | { 40 | ZeroMemory(&_Overlapped, sizeof(_Overlapped)); 41 | 42 | _EventHandle.Reset(CreateEvent(nullptr, /*ManualReset*/ TRUE, /*InitialState*/ FALSE, nullptr)); 43 | if (nullptr == _EventHandle.Get()) 44 | { 45 | throw std::system_error(GetLastError(), std::system_category()); 46 | } 47 | 48 | _Overlapped.hEvent = _EventHandle.Get(); 49 | 50 | _EventWait = CreateThreadpoolWait(IoCompletedCallback, this, nullptr); 51 | if (nullptr == _EventWait) 52 | { 53 | throw std::system_error(GetLastError(), std::system_category()); 54 | } 55 | 56 | SetThreadpoolWait(_EventWait, _EventHandle.Get(), nullptr); 57 | } 58 | 59 | IoOperation::~IoOperation() 60 | { 61 | if (_EventWait != nullptr) 62 | { 63 | CloseThreadpoolWait(_EventWait); 64 | } 65 | } 66 | 67 | // Called when the I/O request has completed. 68 | void CALLBACK 69 | IoOperation::IoCompletedCallback( 70 | _Inout_ PTP_CALLBACK_INSTANCE /*instance*/, 71 | _Inout_opt_ void* context, 72 | _Inout_ PTP_WAIT /*wait*/, 73 | _In_ TP_WAIT_RESULT /*waitResult*/ 74 | ) 75 | { 76 | auto me = reinterpret_cast(context); 77 | me->IoCompleted(); 78 | } 79 | 80 | void 81 | IoOperation::IoCompleted() 82 | { 83 | // Drop the self-reference once this function has completed. 84 | std::shared_ptr selfRef = std::move(_SelfRef); 85 | 86 | // Get the results of the operation. 87 | DWORD bytesTransferred; 88 | BOOL operationSucceeded = GetOverlappedResult(_DriverHandle, &_Overlapped, &bytesTransferred, /*wait*/ false); 89 | 90 | DWORD errorCode = operationSucceeded ? ERROR_SUCCESS : GetLastError(); 91 | 92 | // Set the task result. 93 | EmplaceResult(errorCode, bytesTransferred, std::move(_OutputBuffer)); 94 | } 95 | 96 | void 97 | IoOperation::OnCanceled() 98 | { 99 | CancelIoEx(_DriverHandle, &_Overlapped); 100 | } 101 | -------------------------------------------------------------------------------- /Cx/NfcCxTml.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Module Name: 6 | 7 | NfcCxTml.h 8 | 9 | Abstract: 10 | 11 | This module declares the Tml layer to adapt the NfcCoreLib to the 12 | class extension 13 | 14 | --*/ 15 | 16 | #pragma once 17 | 18 | typedef enum _INTERFACE_STATE { 19 | INTERFACE_STATE_STOPPED, 20 | INTERFACE_STATE_RUNNING 21 | } INTERFACE_STATE; 22 | 23 | // 24 | // NfcLib transport mapping layer 25 | // 26 | typedef struct _NFCCX_TML_INTERFACE { 27 | // 28 | // Backlink to the FdoContext 29 | // 30 | PNFCCX_FDO_CONTEXT FdoContext; 31 | 32 | INTERFACE_STATE InterfaceState; 33 | 34 | _Guarded_by_(QueueLock) 35 | LIST_ENTRY ReadQueue; 36 | 37 | _Guarded_by_(QueueLock) 38 | LIST_ENTRY ReadNotificationQueue; 39 | WDFWAITLOCK QueueLock; 40 | 41 | _Guarded_by_(QueueLock) 42 | LIST_ENTRY WriteQueue; 43 | 44 | // 45 | // Flag to indicate if write pending with the lower transport layer. 46 | // If so, then do not pass any reads to the NfcCoreLib since it expects 47 | // this synchronization in the transport layer. 48 | // 49 | _Guarded_by_(QueueLock) 50 | BOOLEAN IsWriteCompletionPending; 51 | 52 | } NFCCX_TML_INTERFACE, *PNFCCX_TML_INTERFACE; 53 | 54 | typedef struct _NFCCX_TML_READ_QUEUE_ENTRY { 55 | LIST_ENTRY ListEntry; 56 | _Field_size_bytes_(BufferLength) PUCHAR Buffer; 57 | USHORT BufferLength; 58 | pphTmlNfc_TransactCompletionCb_t PfnReadCompletion; 59 | PVOID Context; 60 | HANDLE hCompletionEvent; 61 | } NFCCX_TML_READ_QUEUE_ENTRY, *PNFCCX_TML_READ_QUEUE_ENTRY; 62 | 63 | typedef struct _NFCCX_TML_WRITE_QUEUE_ENTRY { 64 | LIST_ENTRY ListEntry; 65 | WDFREQUEST Request; 66 | PNFCCX_TML_INTERFACE TmlInterface; 67 | } NFCCX_TML_WRITE_QUEUE_ENTRY, *PNFCCX_TML_WRITE_QUEUE_ENTRY; 68 | 69 | typedef struct _NFCCX_TML_READ_NOTIFICATION_QUEUE_ENTRY { 70 | LIST_ENTRY ListEntry; 71 | UCHAR Buffer[NCI_PACKET_MAX_SIZE]; 72 | USHORT BufferLength; 73 | } NFCCX_TML_READ_NOTIFICATION_QUEUE_ENTRY, *PNFCCX_TML_READ_NOTIFICATION_QUEUE_ENTRY; 74 | 75 | typedef struct _NFCCX_TML_WRITE_CONTEXT { 76 | WDFDEVICE Device; 77 | pphTmlNfc_TransactCompletionCb_t PfnWriteCompletion; 78 | PVOID Context; 79 | WDFMEMORY Memory; 80 | USHORT Length; 81 | NTSTATUS Status; 82 | HANDLE hCompletionEvent; 83 | ULONG ReferenceCount; 84 | } NFCCX_TML_WRITE_CONTEXT, *PNFCCX_TML_WRITE_CONTEXT; 85 | 86 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(NFCCX_TML_WRITE_CONTEXT, NfcCxTmlWriteGetContext); 87 | 88 | NTSTATUS 89 | NfcCxTmlInterfaceCreate( 90 | _In_ PNFCCX_FDO_CONTEXT FdoContext, 91 | _Out_ PNFCCX_TML_INTERFACE * PPRFInterface 92 | ); 93 | 94 | VOID 95 | NfcCxTmlInterfaceDestroy( 96 | _In_ PNFCCX_TML_INTERFACE TmlInterface 97 | ); 98 | 99 | VOID 100 | NfcCxTml_DrainQueue( 101 | _In_ PNFCCX_TML_INTERFACE TmlInterface 102 | ); 103 | 104 | NTSTATUS 105 | NfcCxTmlInterfaceStart( 106 | _In_ PNFCCX_TML_INTERFACE TmlInterface 107 | ); 108 | 109 | NTSTATUS 110 | NfcCxTmlInterfaceStop( 111 | _In_ PNFCCX_TML_INTERFACE TmlInterface 112 | ); 113 | 114 | NTSTATUS 115 | NfcCxTmlDispatchReadNotification( 116 | _In_ PNFCCX_TML_INTERFACE TmlInterface, 117 | _In_opt_bytecount_(BufferSize) PUCHAR Buffer, 118 | _In_ USHORT BufferSize 119 | ); 120 | 121 | VOID 122 | NfcCxTml_Write( 123 | _In_ PNFCCX_TML_WRITE_QUEUE_ENTRY WriteQueueEntry 124 | ); 125 | 126 | EVT_WDF_REQUEST_COMPLETION_ROUTINE NfcCxTml_WriteCompletion; 127 | --------------------------------------------------------------------------------