Ejemplo n.º 1
0
        private static async void InitCard()
        {
            WriteToLog("InitCard");
            try
            {
                if (_card == null)
                {
                    //if (_isInfoNoCardShow)
                    //    return;

                    //throw new Exception("No card!");
                    WriteToLog("ERROR!!! No card!");

                    return;
                }

                _cardIdentification = await _card.GetCardInfo();

                WriteToLog("Connected to card\r\nPC/SC device class: " + _cardIdentification.PcscDeviceClass +
                           "\r\nCard name: " + _cardIdentification.PcscCardName);
            }
            catch (Exception e)
            {
                WriteToLog("InitCard ERROR!!!\r\n" + e.Message);
                //throw;
            }
        }
Ejemplo n.º 2
0
        public async void OnCardAdded(SmartCardReader sender, CardAddedEventArgs args)
        {
            // カード検索
            var card = args.SmartCard;

            if (card == null)
            {
                return;
            }
            Log("Card OK");

            // カードタイプ判別
            using (var con = await card.ConnectAsync())
            {
                IccDetection detection = new IccDetection(card, con);
                await detection.DetectCardTypeAync();

                Log(" CardName : " + detection.PcscCardName.ToString());
                Log(" DeviceClass : " + detection.PcscDeviceClass.ToString());

                if (detection.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                    detection.PcscCardName == Pcsc.CardName.FeliCa)
                {
                    new Controller.FelicaController(con);
                }
            }
        }
Ejemplo n.º 3
0
        private void HandleSmartCard(String readerName)
        {
            using (ISCardContext ctx = contextFactory.Establish(SCardScope.System))
                using (ICardReader reader = ctx.ConnectReader(readerName, SCardShareMode.Shared, SCardProtocol.Any))
                {
                    StatusMessage?.Invoke("Connected to tag");

                    IccDetection cardIdent = new IccDetection(reader);
                    cardIdent.DetectCardType();

                    StatusMessage?.Invoke("Device class: " + cardIdent.PcscDeviceClass.ToString());
                    StatusMessage?.Invoke("Card name: " + cardIdent.PcscCardName.ToString());
                    StatusMessage?.Invoke("ATR: " + BitConverter.ToString(cardIdent.Atr));

                    if (cardIdent.PcscDeviceClass == DeviceClass.StorageClass &&
                        (cardIdent.PcscCardName == CardName.MifareUltralight ||
                         cardIdent.PcscCardName == CardName.MifareUltralightC ||
                         cardIdent.PcscCardName == CardName.MifareUltralightEV1))
                    {
                        HandleMifareUL(reader);
                    }
                    else if (cardIdent.PcscDeviceClass == DeviceClass.StorageClass &&
                             (cardIdent.PcscCardName == CardName.MifareStandard1K ||
                              cardIdent.PcscCardName == CardName.MifareStandard4K))
                    {
                        HandleMifareStandard(reader);
                    }
                    else
                    {
                        HandleHCEClient(reader);
                    }
                }
        }
Ejemplo n.º 4
0
        public async Task <IccDetection> GetCardInfo()
        {
            var atrbytes = await GetAnswerToResetAsync();

            var cardIdentification = new IccDetection(atrbytes);

            return(cardIdentification);
        }
Ejemplo n.º 5
0
 public async Task <IccDetection> GetCardInfo()
 {
     if (cardInfo == null)
     {
         cardInfo = await Reader.GetCardInfo();
     }
     return(cardInfo);
 }
Ejemplo n.º 6
0
        private void Initialize()
        {
            sectors  = new Sector[MaxSectors];
            mad      = null;
            mad2     = null;
            cardInfo = null;

            ActiveSector = -1;
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void cardEV_Tap(SmartCardReader sender, CardAddedEventArgs args)
        {
            CardStatus = ScanningStatus.CardScanning;
            try
            {
                System.Diagnostics.Debug.WriteLine("Got card tap event.");
                // woooot
                using (SmartCardConnection connection = await args.SmartCard.ConnectAsync())
                {
                    // figure out what kind of card this is.
                    IccDetection cardIdentification = new IccDetection(args.SmartCard, connection);
                    await cardIdentification.DetectCardTypeAync();

                    System.Diagnostics.Debug.WriteLine("FOUND CARD");
                    System.Diagnostics.Debug.WriteLine(cardIdentification.PcscDeviceClass.ToString());
                    if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.MifareDesfire)
                    {
                        Pcsc.Desfire.AccessHandler       desfireAccess = new Pcsc.Desfire.AccessHandler(connection);
                        PhysicalCard.Desfire.DesfireCard _card         = await ZaibatsuPass.PhysicalCard.Desfire.DesfireCard.SnapshotAsync(desfireAccess);

                        var ignored = Dispatcher.RunAsync(
                            Windows.UI.Core.CoreDispatcherPriority.Normal,
                            () => {
                            // try to parse the card
                            tCard = _card;
                            TransitCard.TransitCard parsedCard = TransitCard.TransitCardParser.parseTransitCard(tCard);
                            if (parsedCard == null)
                            {
                                CardStatus = ScanningStatus.ScanningFailure;
                            }
                            else
                            {
                                (Window.Current.Content as Frame).Navigate(typeof(DetailsPage), parsedCard);
                            }
                        });
                        CardStatus = ScanningStatus.ScanningSuccess;
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(" ** OOPS: " + e.ToString());
                CardStatus = ScanningStatus.ScanningFailure;
            }
        }
Ejemplo n.º 8
0
        public static async void OnCardAdded(SmartCardReader sender, CardAddedEventArgs args)
        {
            // カード検索
            var card = args.SmartCard;

            if (card == null)
            {
                return;
            }
            Debug.WriteLine("Card OK");

            // カードタイプ判別
            using (var connection = await card.ConnectAsync())
            {
                IccDetection detection = new IccDetection(card, connection);
                await detection.DetectCardTypeAync();

                Debug.WriteLine("CardName : " + detection.PcscCardName.ToString());

                if (detection.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass && detection.PcscCardName == Pcsc.CardName.FeliCa)
                {
                    var felicaAccess = new Felica.AccessHandler(connection);

                    byte[] commandPacket = new byte[] { 0x00, 0x00, 0xff, 0xff, 0x01, 0x0f };
                    commandPacket[0] = (byte)commandPacket.Length;

                    byte[] result = await felicaAccess.TransparentExchangeAsync(commandPacket);

                    byte[] idm = new byte[8];
                    Array.Copy(result, 2, idm, 0, idm.Length);

                    byte[] systemCode = new byte[2];
                    Array.Copy(result, 18, systemCode, 0, systemCode.Length);

                    string strIdm        = BitConverter.ToString(idm);
                    string strSystemCode = BitConverter.ToString(systemCode);

                    Debug.WriteLine("IDm        : " + strIdm);
                    Debug.WriteLine("SystemCode : " + strSystemCode);
                }
            }
        }
Ejemplo n.º 9
0
        public async Task ConnectAsync(SmartCard smartcard)
        {
            _MifareSmartCard = smartcard;
            var newConnection = await smartcard.ConnectAsync();

            lock (CardConnectionLock)
            {
                if (_MifareSmartCardConnection != null)
                {
                    _MifareSmartCardConnection.Dispose();
                }
                _MifareSmartCardConnection = newConnection;
            }
            mfStdAccess = new Mifare.AccessHandler(_MifareSmartCardConnection);
            IccDetection cardIdentification = new IccDetection(_MifareSmartCard, _MifareSmartCardConnection);
            await cardIdentification.DetectCardTypeAync();

            CurrentCardName = cardIdentification.PcscCardName;
            if (!(CurrentCardName == CardName.MifareStandard1K || CurrentCardName == CardName.MifareStandard4K))
            {
                throw new Mifare.Exceptions.CardTypeException("this Card is not mifare classic card");
            }
        }
Ejemplo n.º 10
0
        private async void cardReader_CardAdded(SmartCardReader sender, CardAddedEventArgs args)
        {
            SmartCard smartCard = args.SmartCard;

            try
            {
                await LogMessageAsync("カードを検知しました", true);

                using (SmartCardConnection connection = await smartCard.ConnectAsync())
                {
                    IccDetection cardIdentification = new IccDetection(smartCard, connection);
                    await cardIdentification.DetectCardTypeAync();

                    await LogMessageAsync("PC/SCデバイスクラス: " + cardIdentification.PcscDeviceClass.ToString());
                    await LogMessageAsync("カード名: " + cardIdentification.PcscCardName.ToString());

                    if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                        cardIdentification.PcscCardName == CardName.FeliCa)
                    {
                        await LogMessageAsync("FelicaCardがみつかりました");

                        if (isEDYChecked)
                        {
                            await ReadEdyAsync(connection);
                        }
                        else
                        {
                            await ReadSuicaAsync(connection);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await LogMessageAsync("例外が発生: " + ex.ToString());
            }
        }
Ejemplo n.º 11
0
        public async Task <Tuple <CardName, DeviceClass> > DetectCardType()
        {
            try
            {
                if (connection == null)
                {
                    throw new Exception("Card connection not initialised");
                }

                // Try to identify what type of card it was
                IccDetection cardIdentification = new IccDetection(card, connection);
                await cardIdentification.DetectCardTypeAync();

                LogMessage("Connected to card\r\nPC/SC device class: " + cardIdentification.PcscDeviceClass.ToString());
                LogMessage("Card name: " + cardIdentification.PcscCardName.ToString());
                LogMessage("ATR: " + BitConverter.ToString(cardIdentification.Atr));

                return(Tuple.Create(cardIdentification.PcscCardName, cardIdentification.PcscDeviceClass));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Sample code to hande a couple of different cards based on the identification process
        /// </summary>
        /// <returns>None</returns>
        private async Task HandleCard(SmartCard card)
        {
            try
            {
                // Clear the messages
                MainPage.Current.NotifyUser(String.Empty, NotifyType.StatusMessage, true);

                // Connect to the card
                using (SmartCardConnection connection = await card.ConnectAsync())
                {
                    // Try to identify what type of card it was
                    IccDetection cardIdentification = new IccDetection(card, connection);
                    await cardIdentification.DetectCardTypeAync();

                    LogMessage("Connected to card\r\nPC/SC device class: " + cardIdentification.PcscDeviceClass.ToString());
                    LogMessage("Card name: " + cardIdentification.PcscCardName.ToString());
                    LogMessage("ATR: " + BitConverter.ToString(cardIdentification.Atr));

                    if ((cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass) &&
                        (cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightC ||
                         cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralight ||
                         cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightEV1))
                    {
                        // Handle MIFARE Ultralight
                        MifareUltralight.AccessHandler mifareULAccess = new MifareUltralight.AccessHandler(connection);

                        // Each read should get us 16 bytes/4 blocks, so doing
                        // 4 reads will get us all 64 bytes/16 blocks on the card
                        for (byte i = 0; i < 4; i++)
                        {
                            byte[] response = await mifareULAccess.ReadAsync((byte)(4 * i));

                            LogMessage("Block " + (4 * i).ToString() + " to Block " + (4 * i + 3).ToString() + " " + BitConverter.ToString(response));
                        }

                        byte[] responseUid = await mifareULAccess.GetUidAsync();

                        LogMessage("UID:  " + BitConverter.ToString(responseUid));
                    }
                    else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.MifareDesfire)
                    {
                        // Handle MIFARE DESfire
                        Desfire.AccessHandler desfireAccess = new Desfire.AccessHandler(connection);
                        Desfire.CardDetails   desfire       = await desfireAccess.ReadCardDetailsAsync();

                        LogMessage("DesFire Card Details:  " + Environment.NewLine + desfire.ToString());
                    }
                    else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                             cardIdentification.PcscCardName == Pcsc.CardName.FeliCa)
                    {
                        // Handle Felica
                        LogMessage("Felica card detected");
                        var felicaAccess = new Felica.AccessHandler(connection);
                        var uid          = await felicaAccess.GetUidAsync();

                        LogMessage("UID:  " + BitConverter.ToString(uid));
                    }
                    else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                             (cardIdentification.PcscCardName == Pcsc.CardName.MifareStandard1K || cardIdentification.PcscCardName == Pcsc.CardName.MifareStandard4K))
                    {
                        // Handle MIFARE Standard/Classic
                        LogMessage("MIFARE Standard/Classic card detected");
                        var mfStdAccess = new MifareStandard.AccessHandler(connection);
                        var uid         = await mfStdAccess.GetUidAsync();

                        LogMessage("UID:  " + BitConverter.ToString(uid));

                        ushort maxAddress = 0;
                        switch (cardIdentification.PcscCardName)
                        {
                        case Pcsc.CardName.MifareStandard1K:
                            maxAddress = 0x3f;
                            break;

                        case Pcsc.CardName.MifareStandard4K:
                            maxAddress = 0xff;
                            break;
                        }
                        await mfStdAccess.LoadKeyAsync(MifareStandard.DefaultKeys.FactoryDefault);

                        for (ushort address = 0; address <= maxAddress; address++)
                        {
                            var response = await mfStdAccess.ReadAsync(address, Pcsc.GeneralAuthenticate.GeneralAuthenticateKeyType.MifareKeyA);

                            LogMessage("Block " + address.ToString() + " " + BitConverter.ToString(response));
                        }
                    }
                    else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                             (cardIdentification.PcscCardName == Pcsc.CardName.ICODE1 ||
                              cardIdentification.PcscCardName == Pcsc.CardName.ICODESLI ||
                              cardIdentification.PcscCardName == Pcsc.CardName.iCodeSL2))
                    {
                        // Handle ISO15693
                        LogMessage("ISO15693 card detected");
                        var iso15693Access = new Iso15693.AccessHandler(connection);
                        var uid            = await iso15693Access.GetUidAsync();

                        LogMessage("UID:  " + BitConverter.ToString(uid));
                    }
                    else
                    {
                        // Unknown card type
                        // Note that when using the XDE emulator the card's ATR and type is not passed through, so we'll
                        // end up here even for known card types if using the XDE emulator

                        // Some cards might still let us query their UID with the PC/SC command, so let's try:
                        var apduRes = await connection.TransceiveAsync(new Pcsc.GetUid());

                        if (!apduRes.Succeeded)
                        {
                            LogMessage("Failure getting UID of card, " + apduRes.ToString());
                        }
                        else
                        {
                            LogMessage("UID:  " + BitConverter.ToString(apduRes.ResponseData));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogMessage("Exception handling card: " + ex.ToString(), NotifyType.ErrorMessage);
            }
        }
Ejemplo n.º 13
0
        public void FindCard(int timeoutInSecs = 10,
                             CancellationTokenSource tokenSource = null)
        {
            Task findCardTask = Task.Factory.StartNew(async() =>
            {
                // SmartCardReaderを取得
                var deviceInfo = await SmartCardReaderUtils.GetFirstSmartCardReaderInfo(SmartCardReaderKind.Nfc);

                this.IsSupported = deviceInfo != null;
                this.IsEnabled   = (deviceInfo != null) && deviceInfo.IsEnabled;

                if (!this.IsSupported)
                {
                    throw new FelicaReaderNotSupportedException("NFC is not supported");
                }
                else if (!this.IsEnabled)
                {
                    throw new FelicaReaderNotEnabledException("NFC is not enabled");
                }

                this.reader = await SmartCardReader.FromIdAsync(deviceInfo.Id);

                // Felicaカードを探索
                var cts = tokenSource ?? new CancellationTokenSource();
                try
                {
                    var task = this.FindSmartCard(this.reader, cts.Token);
                    task.Wait(timeoutInSecs * 1000);

                    if (task.Status == TaskStatus.RanToCompletion)
                    {
                        var smartCard = task.Result;
                        SmartCardConnection connection = await smartCard.ConnectAsync();

                        IccDetection cardIdentification = new IccDetection(smartCard, connection);
                        await cardIdentification.DetectCardTypeAync();

                        if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                            cardIdentification.PcscCardName == Pcsc.CardName.FeliCa)
                        {
                            this.felicaCardSubject.OnNext(new FelicaCardMediaImplementation(connection));
                        }
                        else
                        {
                            throw new UnknownCardException(
                                String.Format("Unknown device: PcscDeviceClass={0}, PcscCardName={1}",
                                              cardIdentification.PcscDeviceClass,
                                              cardIdentification.PcscCardName));
                        }
                    }
                    else if (task.Status == TaskStatus.Canceled)
                    {
                        throw new FelicaReaderTimeoutException("Read Timeout");
                    }
                    else
                    {
                        // Timeoutが発生した場合
                        throw new FelicaReaderTimeoutException("Read Timeout");
                    }
                }
                catch (AggregateException)
                {
                    throw new FelicaReaderException();
                }
            });

            return;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Sample code to hande a couple of different cards based on the identification process
        /// </summary>
        /// <returns>None</returns>
        private async Task HandleCard(SmartCard card)
        {
            try
            {
                // Connect to the card
                using (SmartCardConnection connection = await card.ConnectAsync())
                {
                    // Try to identify what type of card it was
                    IccDetection cardIdentification = new IccDetection(card, connection);
                    await cardIdentification.DetectCardTypeAync();

                    LogMessage("Connected to card\r\nPC/SC device class: " + cardIdentification.PcscDeviceClass.ToString());
                    LogMessage("Card name: " + cardIdentification.PcscCardName.ToString());
                    LogMessage("ATR: " + BitConverter.ToString(cardIdentification.Atr));

                    if ((cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass) &&
                        (cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightC ||
                         cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralight ||
                         cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightEV1))
                    {
                        // Handle MIFARE Ultralight
                        MifareUltralight.AccessHandler mifareULAccess = new MifareUltralight.AccessHandler(connection);

                        await mifareULAccess.ReadCapsAsync();

                        if (!mifareULAccess.isNTag21x)
                        {
                            var ignored1 = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                            {
                                var msgbox = new Windows.UI.Popups.MessageDialog("This application only works with the NXP NTAG21x line of NFC chips. Sorry.");
                                msgbox.Commands.Add(new Windows.UI.Popups.UICommand("OK"));
                                await msgbox.ShowAsync();
                            });

                            return;
                        }

                        bool authenticated = false;

                        byte[] password = await ParseField(passwordBox, 4);

                        byte[] passwordAck = await ParseField(passwordAckBox, 2);

                        if (password != null && passwordAck != null)
                        {
                            try
                            {
                                await mifareULAccess.AuthenticateWithPassword(password, passwordAck);

                                authenticated = true;
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine("Exception sending provisioning password: "******"Exception sending provisioning password: "******"ReadCount:  " + responseAccess.ToString());

                            var ignored2 = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                            {
                                accessCount.Text = responseAccess.ToString();
                            });

                            accessCountEnabled = true;
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("Exception sending Getting Access Count: " + ex);
                        }

                        if (!accessCountEnabled)
                        {
                            var ignored3 = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                            {
                                accessCount.Text             = " ";
                                accessCountEnable.Visibility = Visibility.Visible;
                            });

                            if (autoProvision.IsChecked == true)
                            {
                                await mifareULAccess.EnableAccessCountAsync();
                            }
                        }

                        for (byte i = 0; i < mifareULAccess.Blocks; i++)
                        {
                            byte[] response = await mifareULAccess.ReadAsync((byte)(4 * i));

                            for (byte y = 0; y < 4; y++)
                            {
                                byte[] buf4 = new byte[4];
                                Array.Copy(response, y * 4, buf4, 0, 4);
                                LogMessage((i * 4 + y).ToString("x2") + ": " + BitConverter.ToString(buf4));
                            }
                        }

                        byte[] responseUid = await mifareULAccess.GetUidAsync();

                        string uidString = BitConverter.ToString(responseUid);
                        LogMessage("UID:  " + uidString);

                        var ignored4 = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                        {
                            uid.Text            = uidString;
                            UidPanel.Visibility = Visibility.Visible;
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception handling card: " + ex.ToString());
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Sample code to hande a couple of different cards based on the identification process
        /// </summary>
        /// <returns>None</returns>
        private async Task HandleCard(SmartCard card)
        {
            try
            {
                // Clear the messages
                //MainPage.Current.NotifyUser(String.Empty, NotifyType.StatusMessage, true);

                // Connect to the card
                using (SmartCardConnection connection = await card.ConnectAsync())
                {
                    // Try to identify what type of card it was
                    IccDetection cardIdentification = new IccDetection(card, connection);
                    await cardIdentification.DetectCardTypeAync();

                    LogMessage("Connected to card\r\nPC/SC device class: " + cardIdentification.PcscDeviceClass.ToString());
                    LogMessage("Card name: " + cardIdentification.PcscCardName.ToString());
                    LogMessage("ATR: " + BitConverter.ToString(cardIdentification.Atr));

                    if ((cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass) &&
                        (cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightC ||
                         cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralight ||
                         cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightEV1))
                    {
                        // Handle MIFARE Ultralight
                        MifareUltralight.AccessHandler mifareULAccess = new MifareUltralight.AccessHandler(connection);

                        // Each read should get us 16 bytes/4 blocks, so doing
                        // 4 reads will get us all 64 bytes/16 blocks on the card
                        for (byte i = 0; i < 4; i++)
                        {
                            byte[] response = await mifareULAccess.ReadAsync((byte)(4 * i));

                            LogMessage("Block " + (4 * i).ToString() + " to Block " + (4 * i + 3).ToString() + " " + BitConverter.ToString(response));
                        }

                        byte[] responseUid = await mifareULAccess.GetUidAsync();

                        LogMessage("UID:  " + BitConverter.ToString(responseUid));
                    }
                    else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.MifareDesfire)
                    {
                        // Handle MIFARE DESfire
                        Desfire.AccessHandler desfireAccess = new Desfire.AccessHandler(connection);
                        Desfire.CardDetails   desfire       = await desfireAccess.ReadCardDetailsAsync();

                        LogMessage("DesFire Card Details:  " + Environment.NewLine + desfire.ToString());
                    }
                    else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                             cardIdentification.PcscCardName == Pcsc.CardName.FeliCa)
                    {
                        // Handle Felica
                        LogMessage("Felica card detected");
                        var cyberneticsAccess = new Cybernetics.AccessHandler(connection);
                        var cardinfo          = null as Cybernetics.CardInfo;
                        var histories         = new List <Cybernetics.HistoryInfo>();
                        var gateHistories     = new List <Cybernetics.GateHistoryInfo>();
                        var sfHistory         = null as Cybernetics.SFEntryInfo;

                        var IDm = await cyberneticsAccess.GetUidAsync(); // ok

                        LogMessage("IDm: " + BitConverter.ToString(IDm));
                        await cyberneticsAccess.SelectFileAsync(new byte[] { 0x8B, 0x00 });

                        var block008B = await cyberneticsAccess.ReadBinaryAsync(0x00);

                        LogMessage("Card Type:  " + BitConverter.ToString(block008B));
                        cardinfo = Cybernetics.CardInfo.FromBytes(block008B);
                        await cyberneticsAccess.SelectFileAsync(new byte[] { 0x0F, 0x09 });

                        for (byte block = 0; block < 20; ++block)
                        {
                            var block090F = await cyberneticsAccess.ReadBinaryAsync(block);

                            LogMessage("History:  " + BitConverter.ToString(block090F));
                            histories.Add(Cybernetics.HistoryInfo.FromBytes(block090F));
                        }
                        var histList = new List <ICHistoryReader.Core.Cybernetics.HistoryInfo>();
                        var prevHist = null as ICHistoryReader.Core.Cybernetics.HistoryInfo;
                        foreach (var hist in histories)
                        {
                            var h = ICHistoryReader.Core.Cybernetics.HistoryInfo.From(hist, m_stationCodeList);
                            histList.Add(h);
                            if (prevHist != null)
                            {
                                // 前の履歴から精算額を計算
                                prevHist.Amount = h.Balance - prevHist.Balance;
                            }
                            prevHist = h;
                        }
                        histList = histList.SkipLast(1).ToList();
                        await cyberneticsAccess.SelectFileAsync(new byte[] { 0x8F, 0x10 });

                        for (byte block = 0; block < 3; ++block)
                        {
                            var block108F = await cyberneticsAccess.ReadBinaryAsync(block);

                            LogMessage("Gate:  " + BitConverter.ToString(block108F));
                            gateHistories.Add(Cybernetics.GateHistoryInfo.FromBytes(block108F));
                        }
                        await cyberneticsAccess.SelectFileAsync(new byte[] { 0xCB, 0x10 });

                        var temp = new List <byte>();
                        for (byte block = 0; block < 2; ++block)
                        {
                            var block10CB = await cyberneticsAccess.ReadBinaryAsync(block);

                            LogMessage("SF:  " + BitConverter.ToString(block10CB));
                            temp.AddRange(block10CB);
                        }
                        sfHistory = Cybernetics.SFEntryInfo.FromBytes(temp.ToArray());
                    }
                    else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                             (cardIdentification.PcscCardName == Pcsc.CardName.MifareStandard1K || cardIdentification.PcscCardName == Pcsc.CardName.MifareStandard4K))
                    {
                        // Handle MIFARE Standard/Classic
                        LogMessage("MIFARE Standard/Classic card detected");
                        var mfStdAccess = new MifareStandard.AccessHandler(connection);
                        var uid         = await mfStdAccess.GetUidAsync();

                        LogMessage("UID:  " + BitConverter.ToString(uid));

                        ushort maxAddress = 0;
                        switch (cardIdentification.PcscCardName)
                        {
                        case Pcsc.CardName.MifareStandard1K:
                            maxAddress = 0x3f;
                            break;

                        case Pcsc.CardName.MifareStandard4K:
                            maxAddress = 0xff;
                            break;
                        }
                        await mfStdAccess.LoadKeyAsync(MifareStandard.DefaultKeys.FactoryDefault);

                        for (ushort address = 0; address <= maxAddress; address++)
                        {
                            var response = await mfStdAccess.ReadAsync(address, Pcsc.GeneralAuthenticate.GeneralAuthenticateKeyType.MifareKeyA);

                            LogMessage("Block " + address.ToString() + " " + BitConverter.ToString(response));
                        }
                    }
                    else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                             (cardIdentification.PcscCardName == Pcsc.CardName.ICODE1 ||
                              cardIdentification.PcscCardName == Pcsc.CardName.ICODESLI ||
                              cardIdentification.PcscCardName == Pcsc.CardName.iCodeSL2))
                    {
                        // Handle ISO15693
                        LogMessage("ISO15693 card detected");
                        var iso15693Access = new Iso15693.AccessHandler(connection);
                        var uid            = await iso15693Access.GetUidAsync();

                        LogMessage("UID:  " + BitConverter.ToString(uid));
                    }
                    else
                    {
                        // Unknown card type
                        // Note that when using the XDE emulator the card's ATR and type is not passed through, so we'll
                        // end up here even for known card types if using the XDE emulator

                        // Some cards might still let us query their UID with the PC/SC command, so let's try:
                        var apduRes = await connection.TransceiveAsync(new Pcsc.GetUid());

                        if (!apduRes.Succeeded)
                        {
                            LogMessage("Failure getting UID of card, " + apduRes.ToString());
                        }
                        else
                        {
                            LogMessage("UID:  " + BitConverter.ToString(apduRes.ResponseData));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogMessage("Exception handling card: " + ex.ToString(), NotifyType.ErrorMessage);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Sample code to hande a couple of different cards based on the identification process
        /// </summary>
        /// <returns>None</returns>
        private async Task HandleCard(CardAddedEventArgs args)
        {
            try
            {
                var newConnection = await args.SmartCard.ConnectAsync();

                lock (CardConnectionLock)
                {
                    if (CardConnection != null)
                    {
                        CardConnection.Dispose();
                    }
                    CardConnection = newConnection;
                }

                IccDetection cardIdentification = new IccDetection(args.SmartCard, CardConnection);
                await cardIdentification.DetectCardTypeAync();

                DisplayText("Connected to card\r\nPC/SC device class: " + cardIdentification.PcscDeviceClass.ToString() + "\r\nCard name: " + cardIdentification.PcscCardName.ToString());

                if ((cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass) &&
                    (cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightC ||
                     cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralight ||
                     cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightEV1))
                {
                    // Handle MIFARE Ultralight
                    MifareUltralight.AccessHandler mifareULAccess = new MifareUltralight.AccessHandler(CardConnection);

                    // Each read should get us 16 bytes/4 blocks, so doing
                    // 4 reads will get us all 64 bytes/16 blocks on the card
                    for (byte i = 0; i < 4; i++)
                    {
                        byte[] response = await mifareULAccess.ReadAsync((byte)(4 * i));

                        DisplayText("Block " + (4 * i).ToString() + " to Block " + (4 * i + 3).ToString() + " " + BitConverter.ToString(response));
                    }

                    byte[] responseUid = await mifareULAccess.GetUidAsync();

                    DisplayText("UID:  " + BitConverter.ToString(responseUid));
                }
                else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.MifareDesfire)
                {
                    // Handle MIFARE DESfire
                    Desfire.AccessHandler desfireAccess = new Desfire.AccessHandler(CardConnection);
                    Desfire.CardDetails   card          = await desfireAccess.ReadCardDetailsAsync();

                    DisplayText("DesFire Card Details:  " + Environment.NewLine + card.ToString());
                }
                else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                         cardIdentification.PcscCardName == Pcsc.CardName.FeliCa)
                {
                    // Handle Felica
                    DisplayText("Felica card detected");
                    var felicaAccess = new Felica.AccessHandler(CardConnection);
                    var uid          = await felicaAccess.GetUidAsync();

                    DisplayText("UID:  " + BitConverter.ToString(uid));
                }
                else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                         (cardIdentification.PcscCardName == Pcsc.CardName.MifareStandard1K || cardIdentification.PcscCardName == Pcsc.CardName.MifareStandard4K))
                {
                    // Handle MIFARE Standard/Classic
                    DisplayText("MIFARE Standard/Classic card detected");
                    var mfStdAccess = new MifareStandard.AccessHandler(CardConnection);
                    var uid         = await mfStdAccess.GetUidAsync();

                    DisplayText("UID:  " + BitConverter.ToString(uid));

                    ushort maxAddress = 0;
                    switch (cardIdentification.PcscCardName)
                    {
                    case Pcsc.CardName.MifareStandard1K:
                        maxAddress = 0x3f;
                        break;

                    case Pcsc.CardName.MifareStandard4K:
                        maxAddress = 0xff;
                        break;
                    }
                    await mfStdAccess.LoadKeyAsync(MifareStandard.DefaultKeys.FactoryDefault);

                    for (ushort address = 0; address <= maxAddress; address++)
                    {
                        var response = await mfStdAccess.ReadAsync(address, Pcsc.GeneralAuthenticate.GeneralAuthenticateKeyType.MifareKeyA);

                        DisplayText("Block " + address.ToString() + " " + BitConverter.ToString(response));
                    }
                }
            }
            catch (Exception e)
            {
                PopupMessage("HandleCard Exception: " + e.Message);
            }
        }
        /// <summary>
        /// Sample code to hande a couple of different cards based on the identification process
        /// </summary>
        /// <returns>None</returns>
        private async Task HandleCard(SmartCard card)
        {
            try
            {
                // Clear the messages
                MainPage.Current.NotifyUser(String.Empty, NotifyType.StatusMessage, true);

                // Connect to the card
                var connection = await card.ConnectAsync();

                // Try to identify what type of card it was
                IccDetection cardIdentification = new IccDetection(card, connection);
                await cardIdentification.DetectCardTypeAync();

                LogMessage("Connected to card\r\nPC/SC device class: " + cardIdentification.PcscDeviceClass.ToString());
                LogMessage("Card name: " + cardIdentification.PcscCardName.ToString());

                if ((cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass) &&
                    (cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightC ||
                     cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralight ||
                     cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightEV1))
                {
                    // Handle MIFARE Ultralight
                    MifareUltralight.AccessHandler mifareULAccess = new MifareUltralight.AccessHandler(connection);

                    // Each read should get us 16 bytes/4 blocks, so doing
                    // 4 reads will get us all 64 bytes/16 blocks on the card
                    for (byte i = 0; i < 4; i++)
                    {
                        byte[] response = await mifareULAccess.ReadAsync((byte)(4 * i));

                        LogMessage("Block " + (4 * i).ToString() + " to Block " + (4 * i + 3).ToString() + " " + BitConverter.ToString(response));
                    }

                    byte[] responseUid = await mifareULAccess.GetUidAsync();

                    LogMessage("UID:  " + BitConverter.ToString(responseUid));
                }
                else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.MifareDesfire)
                {
                    // Handle MIFARE DESfire
                    Desfire.AccessHandler desfireAccess = new Desfire.AccessHandler(connection);
                    Desfire.CardDetails   desfire       = await desfireAccess.ReadCardDetailsAsync();

                    LogMessage("DesFire Card Details:  " + Environment.NewLine + desfire.ToString());
                }
                else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                         cardIdentification.PcscCardName == Pcsc.CardName.FeliCa)
                {
                    // Handle Felica
                    LogMessage("Felica card detected");
                    var felicaAccess = new Felica.AccessHandler(connection);
                    var uid          = await felicaAccess.GetUidAsync();

                    LogMessage("UID:  " + BitConverter.ToString(uid));
                }
                else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                         (cardIdentification.PcscCardName == Pcsc.CardName.MifareStandard1K || cardIdentification.PcscCardName == Pcsc.CardName.MifareStandard4K))
                {
                    // Handle MIFARE Standard/Classic
                    LogMessage("MIFARE Standard/Classic card detected");
                    var mfStdAccess = new MifareStandard.AccessHandler(connection);
                    var uid         = await mfStdAccess.GetUidAsync();

                    LogMessage("UID:  " + BitConverter.ToString(uid));

                    ushort maxAddress = 0;
                    switch (cardIdentification.PcscCardName)
                    {
                    case Pcsc.CardName.MifareStandard1K:
                        maxAddress = 0x3f;
                        break;

                    case Pcsc.CardName.MifareStandard4K:
                        maxAddress = 0xff;
                        break;
                    }
                    await mfStdAccess.LoadKeyAsync(MifareStandard.DefaultKeys.FactoryDefault);

                    for (ushort address = 0; address <= maxAddress; address++)
                    {
                        var response = await mfStdAccess.ReadAsync(address, Pcsc.GeneralAuthenticate.GeneralAuthenticateKeyType.MifareKeyA);

                        LogMessage("Block " + address.ToString() + " " + BitConverter.ToString(response));
                    }
                }
                else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                         (cardIdentification.PcscCardName == Pcsc.CardName.ICODE1 ||
                          cardIdentification.PcscCardName == Pcsc.CardName.ICODESLI ||
                          cardIdentification.PcscCardName == Pcsc.CardName.iCodeSL2))
                {
                    // Handle ISO15693
                    LogMessage("ISO15693 card detected");
                    var iso15693Access = new Iso15693.AccessHandler(connection);
                    var uid            = await iso15693Access.GetUidAsync();

                    LogMessage("UID:  " + BitConverter.ToString(uid));
                }

                connection.Dispose();
            }
            catch (Exception ex)
            {
                LogMessage("Exception handling card: " + ex.ToString(), NotifyType.ErrorMessage);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Sample code to hande a couple of different cards based on the identification process
        /// </summary>
        /// <returns>None</returns>
        private async Task HandleCard(SmartCard card, SmartCardReader sender)
        {
            string UID = "";
            Int64  id  = 0;

            try
            {
                // Connect to the card
                using (SmartCardConnection connection = await card.ConnectAsync())
                {
                    // Try to identify what type of card it was
                    IccDetection cardIdentification = new IccDetection(card, connection);
                    await cardIdentification.DetectCardTypeAync();

                    LogMessage("Connected to card\r\nPC/SC device class: " + cardIdentification.PcscDeviceClass.ToString());
                    LogMessage("Card name: " + cardIdentification.PcscCardName.ToString());
                    LogMessage("ATR: " + BitConverter.ToString(cardIdentification.Atr));

                    if ((cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass) &&
                        (cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightC ||
                         cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralight ||
                         cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightEV1))
                    {
                        // Handle MIFARE Ultralight
                        MifareUltralight.AccessHandler mifareULAccess = new MifareUltralight.AccessHandler(connection);

                        // Each read should get us 16 bytes/4 blocks, so doing
                        // 4 reads will get us all 64 bytes/16 blocks on the card
                        for (byte i = 0; i < 4; i++)
                        {
                            byte[] response = await mifareULAccess.ReadAsync((byte)(4 * i));

                            LogMessage("Block " + (4 * i).ToString() + " to Block " + (4 * i + 3).ToString() + " " + BitConverter.ToString(response));
                        }

                        byte[] responseUid = await mifareULAccess.GetUidAsync();

                        UID = BitConverter.ToString(responseUid);
                        //await Notify("UID: " + BitConverter.ToString(responseUid));
                    }
                    else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.MifareDesfire)
                    {
                        // Handle MIFARE DESfire
                        Desfire.AccessHandler desfireAccess = new Desfire.AccessHandler(connection);
                        Desfire.CardDetails   desfire       = await desfireAccess.ReadCardDetailsAsync();

                        LogMessage("DesFire Card Details:  " + Environment.NewLine + desfire.ToString());
                    }
                    else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                             cardIdentification.PcscCardName == Pcsc.CardName.FeliCa)
                    {
                        // Handle Felica
                        LogMessage("Felica card detected");
                        var felicaAccess = new Felica.AccessHandler(connection);
                        var uid          = await felicaAccess.GetUidAsync();

                        UID = BitConverter.ToString(uid);
                        //await Notify("UID: " + BitConverter.ToString(uid));
                    }
                    else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                             (cardIdentification.PcscCardName == Pcsc.CardName.MifareStandard1K || cardIdentification.PcscCardName == Pcsc.CardName.MifareStandard4K))
                    {
                        // Handle MIFARE Standard/Classic
                        LogMessage("MIFARE Standard/Classic card detected");
                        var mfStdAccess = new MifareStandard.AccessHandler(connection);
                        var uid         = await mfStdAccess.GetUidAsync();

                        UID = BitConverter.ToString(uid);;
                        //await Notify("UID: " + BitConverter.ToString(uid));

                        ushort maxAddress = 0;
                        switch (cardIdentification.PcscCardName)
                        {
                        case Pcsc.CardName.MifareStandard1K:
                            maxAddress = 0x3f;
                            break;

                        case Pcsc.CardName.MifareStandard4K:
                            maxAddress = 0xff;
                            break;
                        }
                        await mfStdAccess.LoadKeyAsync(MifareStandard.DefaultKeys.FactoryDefault);

                        for (ushort address = 0; address <= maxAddress; address++)
                        {
                            var response = await mfStdAccess.ReadAsync(address, Pcsc.GeneralAuthenticate.GeneralAuthenticateKeyType.MifareKeyA);

                            LogMessage("Block " + address.ToString() + " " + BitConverter.ToString(response));
                        }
                    }
                    else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass &&
                             (cardIdentification.PcscCardName == Pcsc.CardName.ICODE1 ||
                              cardIdentification.PcscCardName == Pcsc.CardName.ICODESLI ||
                              cardIdentification.PcscCardName == Pcsc.CardName.iCodeSL2))
                    {
                        // Handle ISO15693
                        LogMessage("ISO15693 card detected");
                        var iso15693Access = new Iso15693.AccessHandler(connection);
                        var uid            = await iso15693Access.GetUidAsync();

                        UID = BitConverter.ToString(uid);
                        //await Notify("UID: " + BitConverter.ToString(uid));
                    }
                    else
                    {
                        // Unknown card type
                        // Note that when using the XDE emulator the card's ATR and type is not passed through, so we'll
                        // end up here even for known card types if using the XDE emulator

                        // Some cards might still let us query their UID with the PC/SC command, so let's try:
                        var apduRes = await connection.TransceiveAsync(new Pcsc.GetUid());

                        if (!apduRes.Succeeded)
                        {
                            LogMessage("Failure getting UID of card, " + apduRes.ToString());
                        }
                        else
                        {
                            LogMessage("UID:  " + BitConverter.ToString(apduRes.ResponseData));
                            UID = BitConverter.ToString(apduRes.ResponseData);
                        }
                    }

                    // START MANAGING SUP STOCK

                    // UID
                    if (UID != "")
                    {
                        id = ToUID(UID);
                        bool found = false;
                        int  i     = 0;
                        // check if ID is in left list
                        foreach (var it in AwaySUP)
                        {
                            i++;
                            if (it.IsSameID(id))
                            {
                                found = true;
                                // set price according to dT
                                int Price = it.GetPrice();

                                //wait for validation, then move from left to stock
                                await Notify("! Arrivé, durée = " + it.strTime + "   Prix: " + Price + " CHF");


                                //move from Left to Stock
                                try
                                {
                                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                                                () =>
                                    {
                                        // Your UI update code goes here
                                        StockSUP.Add(it);
                                        AwaySUP.Remove(it);

                                        StockShow.UpdateLayout();
                                        LeftShow.UpdateLayout();
                                    }
                                                                                                                                );
                                }
                                catch (Exception ex)
                                {
                                    await Notify("Error swapping from away to stock" + ex.ToString());
                                }
                            }
                        }
                        i = 0;

                        // check if ID is in stock list
                        if (!found)
                        {
                            foreach (var it in StockSUP)
                            {
                                i++;
                                if (it.IsSameID(id))
                                {
                                    found = true;
                                    // start time
                                    await Notify("! Valide, près à partir !", "Départ");

                                    i = 0;
                                    it.StartTimer();

                                    //move from stock to left list

                                    try
                                    {
                                        await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                                                    () =>
                                        {
                                            // Your UI update code goes here!
                                            AwaySUP.Add(it);
                                            StockSUP.Remove(it);

                                            StockShow.UpdateLayout();
                                            LeftShow.UpdateLayout();
                                        }
                                                                                                                                    );
                                    }
                                    catch (Exception ex)
                                    {
                                        await Notify("Error swapping from stock to away" + ex.ToString());
                                    }
                                }
                            }
                        }
                        // else, adding to stock list

                        if (!found)
                        {
                            if (isNewTagNewSUP)
                            {
                                await Notify("! Nouvelle planche ajoutée.");

                                isNewTagNewSUP = false;
                                try
                                {
                                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                                                () =>
                                    {
                                        // Your UI update code goes here!
                                        StockSUP.Add(new SUP(id, SUPCategory[selN]));
                                    }
                                                                                                                                );
                                }
                                catch (Exception ex)
                                {
                                    await Notify("Error adding to stock" + ex.ToString());
                                }
                                showNbStock.Text = StockSUP.Count.ToString();

                                StockShow.UpdateLayout();
                                LeftShow.UpdateLayout();
                            }
                            else
                            {
                                await Notify("! Cette planche n'est pas répértoriée !");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogMessage("Exception handling card: " + ex.ToString(), NotifyType.ErrorMessage);
            }
        }
Ejemplo n.º 19
0
        private void Initialize()
        {
            sectors = new Sector[MaxSectors];
            mad = null;
            mad2 = null;
            cardInfo = null;

            ActiveSector = -1;
        }
Ejemplo n.º 20
0
 public async Task<IccDetection> GetCardInfo()
 {
     if (cardInfo == null)
         cardInfo = await Reader.GetCardInfo();
     return cardInfo;
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Sample code to hande a couple of different cards based on the identification process
        /// </summary>
        /// <returns>None</returns>
        private async Task HandleCard(SmartCard card)
        {
            try
            {
                // Clear the messages
                //MainPage.Current.NotifyUser(String.Empty, NotifyType.StatusMessage, true);

                // Connect to the card
                using (SmartCardConnection connection = await card.ConnectAsync())
                {
                    // Try to identify what type of card it was
                    IccDetection cardIdentification = new IccDetection(card, connection);
                    await cardIdentification.DetectCardTypeAync();

                    //Connected to card
                    //LogMessage("Connected to card\r\nPC/SC device class: " + cardIdentification.PcscDeviceClass.ToString());

                    //Card name
                    //LogMessage("Card name: " + cardIdentification.PcscCardName.ToString());

                    //If card is "MIFARE DEFIRE" (our case)
                    if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.MifareDesfire)
                    {
                        // Handle MIFARE DESfire
                        Desfire.AccessHandler desfireAccess = new Desfire.AccessHandler(connection);

                        // Get all data from card
                        Desfire.CardDetails desfire = await desfireAccess.ReadCardDetailsAsync();

                        // Get UID from object desfire
                        var UID = BitConverter.ToString(desfire.UID);
                        //LogMessage(UID, NotifyType.StatusMessage);
                        ShowToastNotification(UID);
                        PerformAuthentication();
                        //LogMessage("DesFire Card Details:  " + Environment.NewLine + desfire.ToString());
                    }
                    else
                    {
                        // Unknown card type
                        // Note that when using the XDE emulator the card's ATR and type is not passed through, so we'll
                        // end up here even for known card types if using the XDE emulator

                        // Some cards might still let us query their UID with the PC/SC command, so let's try:
                        var apduRes = await connection.TransceiveAsync(new Pcsc.GetUid());

                        if (!apduRes.Succeeded)
                        {
                            ShowToastNotification("Failure getting UID of card, " + apduRes.ToString());
                        }
                        else
                        {
                            ShowToastNotification("UID:  " + BitConverter.ToString(apduRes.ResponseData));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ShowToastNotification("Exception handling card: " + ex.ToString());
            }
        }