From 446dd850a3b1893bff858389b403b7b03a4922f6 Mon Sep 17 00:00:00 2001 From: TheJoKlLa Date: Sun, 29 Jan 2023 22:14:39 +0100 Subject: [PATCH] More NFCService --- Borepin/Borepin.UWP/Services/NFCService.cs | 60 ++++++++++++++++++++-- Borepin/Borepin/Service/NFC/INFCService.cs | 41 +++++++++++++-- external/NFC | 2 +- 3 files changed, 95 insertions(+), 8 deletions(-) diff --git a/Borepin/Borepin.UWP/Services/NFCService.cs b/Borepin/Borepin.UWP/Services/NFCService.cs index 3c651d2..2571955 100644 --- a/Borepin/Borepin.UWP/Services/NFCService.cs +++ b/Borepin/Borepin.UWP/Services/NFCService.cs @@ -1,5 +1,7 @@ using Borepin.Service.NFC; +using NFC; using NFC.Interfaces; +using NFC_PCSC; using System; using System.Collections.Generic; using System.Linq; @@ -10,17 +12,69 @@ namespace Borepin.UWP.Services { public class NFCService : INFCService { - public ICard GetCard() + #region Private Members + IHardware _Hardware; + IReader _Reader; + ICard _Card; + #endregion + + #region Constructors + public NFCService(IHardware hardware = null) + { + if(hardware == null) + { + _Hardware = new Hardware_PCSC(); + } + else + { + _Hardware = hardware; + } + } + #endregion + + #region Members + public bool IsAvailable + { + get + { + return true; + } + } + public bool IsEnabled + { + get + { + return true; + } + } + + public bool IsConnected + { + get + { + return _Reader != null && _Card != null; + } + } + #endregion + + #region Methods + public IList GetReaderIDs() + { + return new List(_Hardware.GetReaders()); + } + #endregion + + public void Connect(string readerID) { throw new NotImplementedException(); } - public IHardware GetHardware() + public void Disconnect() { throw new NotImplementedException(); } - public IReader GetReader() + public APDUResponse Transmit(APDUCommand command) { throw new NotImplementedException(); } diff --git a/Borepin/Borepin/Service/NFC/INFCService.cs b/Borepin/Borepin/Service/NFC/INFCService.cs index e863c38..f099455 100644 --- a/Borepin/Borepin/Service/NFC/INFCService.cs +++ b/Borepin/Borepin/Service/NFC/INFCService.cs @@ -1,4 +1,5 @@ -using NFC.Interfaces; +using NFC; +using NFC.Interfaces; using System; using System.Collections.Generic; using System.Text; @@ -10,8 +11,40 @@ namespace Borepin.Service.NFC /// public interface INFCService { - IHardware GetHardware(); - IReader GetReader(); - ICard GetCard(); + /// + /// Indicates if NFC Hardware is available + /// + bool IsAvailable { get; } + + /// + /// Indicates if NFC Hardware is enabled + /// + bool IsEnabled { get; } + + /// + /// Indicates if NFC Card is connected + /// + bool IsConnected { get; } + + /// + /// Get a list of availible NFC ReaderIDs + /// + IList GetReaderIDs(); + + /// + /// Connect with ReaderID to NFC Card + /// + /// ReaderID from GetReaderIDs + void Connect(string readerID); + + /// + /// Disconnects Reader from NFC Card + /// + void Disconnect(); + + /// + /// Transmit APDUCommand to Card if connected + /// + APDUResponse Transmit(APDUCommand command); } } diff --git a/external/NFC b/external/NFC index 4420dbf..327472b 160000 --- a/external/NFC +++ b/external/NFC @@ -1 +1 @@ -Subproject commit 4420dbf1b1e820d94d6adaa2b65a851ac582be8f +Subproject commit 327472bea06316a6d439b6b0224ffedd2c6f1bbc