2020-09-15 10:47:46 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace NFC
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Abstract representation of the platform specific NFC Hardware.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public interface IHardware
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Check if the device has nfc support.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Returns true if the device supports NFC.</returns>
|
|
|
|
|
bool IsAvailable();
|
|
|
|
|
|
|
|
|
|
/// <returns>Returns all available readers.</returns>
|
2020-09-15 15:27:01 +02:00
|
|
|
|
string[] GetReaders();
|
2020-09-15 10:47:46 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new reader instance from the specified id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Returns the spatform specific reader that corresponds to the id.</returns>
|
|
|
|
|
/// <exception cref="ArgumentException">Invalid reader id.</exception>
|
2020-09-15 15:27:01 +02:00
|
|
|
|
IReader OpenReader(string readerID);
|
2020-09-15 10:47:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-15 15:27:01 +02:00
|
|
|
|
public delegate void ReaderEventHandler(object sender, ICard card);
|
|
|
|
|
|
2020-09-15 10:47:46 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Abstraction of a platform-specifc reader that can communicate with NFC cards.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public interface IReader
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Event that will be called when a new tag was discovered.
|
|
|
|
|
/// </summary>
|
2020-09-15 15:27:01 +02:00
|
|
|
|
event ReaderEventHandler CardDiscovered;
|
2020-09-15 10:47:46 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Event that will be called when a tag that is in use gets disconnected.
|
|
|
|
|
/// </summary>
|
2020-09-15 15:27:01 +02:00
|
|
|
|
event ReaderEventHandler CardLost;
|
2020-09-15 10:47:46 +02:00
|
|
|
|
|
2020-09-17 16:07:58 +02:00
|
|
|
|
void Start();
|
2020-09-15 10:47:46 +02:00
|
|
|
|
|
2020-09-17 16:07:58 +02:00
|
|
|
|
void Stop();
|
2020-09-15 10:47:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface ICard
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Connect to Smartcard
|
|
|
|
|
/// </summary>
|
|
|
|
|
void Connect();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Disconnect from Smartcard
|
|
|
|
|
/// </summary>
|
|
|
|
|
void Disconnect();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Transmit APDU Command to Smartcard
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="apdu_cmd">Application Protocol Data Unit Command - ISO 7816</param>
|
|
|
|
|
/// <returns>Application Protocol Data Unit Response - ISO 7816</returns>
|
2020-09-15 15:27:01 +02:00
|
|
|
|
APDUResponse Transmit(APDUCommand apdu_cmd);
|
2020-09-15 10:47:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ReaderUnavailableException : Exception { }
|
|
|
|
|
|
|
|
|
|
public class CardUnavailableException : Exception { }
|
|
|
|
|
|
|
|
|
|
public class APDUException : Exception {
|
|
|
|
|
public readonly byte ResponseCode;
|
|
|
|
|
}
|
|
|
|
|
}
|