Exemplo n.º 1
0
        private void MifareUltralightQuickCheck()
        {
            if (!isTask)
            {
                using (RFiDDevice device = new RFiDDevice(settings.DefaultSpecification.DefaultReaderProvider))
                {
                    Mouse.OverrideCursor = Cursors.Wait;

                    foreach (RFiDChipChildLayerViewModel cnVM in this.Children)
                    {
                        if (device.ReadMifareUltralightSinglePage(cnVM.PageNumber) == ERROR.NoError)
                        {
                            string dataToShow = ByteConverter.HexToString(device.MifareUltralightPageData);

                            for (int i = (ByteConverter.HexToString(device.MifareUltralightPageData).Length) - 2; i > 0; i -= 2)
                            {
                                dataToShow = dataToShow.Insert(i, " ");
                            }

                            cnVM.Children.Add(
                                new RFiDChipGrandChildLayerViewModel(
                                    string.Format("Data: {0}", dataToShow)));

                            cnVM.IsAuthenticated = true;
                        }
                        else
                        {
                            cnVM.IsAuthenticated = false;
                            continue;
                        }

                        foreach (RFiDChipGrandChildLayerViewModel gcVM in cnVM.Children.Where(x => x.MifareClassicDataBlock != null))
                        {
                            if (device.Sector.DataBlock.Any(x => x.DataBlockNumberSectorBased == gcVM.DataBlockNumber))                             // (gcVM.DataBlockContent != null)
                            {
                                if (device.Sector.DataBlock.First(x => x.DataBlockNumberSectorBased == gcVM.DataBlockNumber).Data != null)
                                {
                                    gcVM.MifareClassicDataBlock.Data = device.Sector.DataBlock.First(x => x.DataBlockNumberSectorBased == gcVM.DataBlockNumber).Data;                                     //device.currentSector[gcVM.DataBlockNumber];
                                    gcVM.IsAuthenticated             = true;
                                }
                                else
                                {
                                    gcVM.IsAuthenticated = false;
                                }
                            }
                            else
                            {
                                gcVM.IsAuthenticated = false;
                            }
                        }
                    }

                    this.IsExpanded = true;

                    Mouse.OverrideCursor = null;
                }
            }
        }
Exemplo n.º 2
0
        private void MifareClassicQuickCheck()
        {
            if (!isTask)
            {
                using (RFiDDevice device = new RFiDDevice(settings.DefaultSpecification.DefaultReaderProvider))
                {
                    Mouse.OverrideCursor = Cursors.Wait;

                    foreach (RFiDChipChildLayerViewModel cnVM in this.Children)
                    {
                        foreach (string key in settings.DefaultSpecification.MifareClassicDefaultQuickCheckKeys)
                        {
                            //TODO Try all Keys and add the result somewhere in the treeview

                            if (device.ReadMiFareClassicSingleSector(cnVM.SectorNumber, key, key) == ERROR.NoError)
                            {
                                cnVM.Children.Add(new RFiDChipGrandChildLayerViewModel(string.Format("Key: {0}", key)));
                                cnVM.IsAuthenticated = true;
                            }
                            else
                            {
                                cnVM.IsAuthenticated = false;
                                continue;
                            }
                            break;
                        }

                        foreach (RFiDChipGrandChildLayerViewModel gcVM in cnVM.Children.Where(x => x.MifareClassicDataBlock != null))
                        {
                            if (device.Sector.DataBlock.Any(x => x.DataBlockNumberSectorBased == gcVM.DataBlockNumber))                             // (gcVM.DataBlockContent != null)
                            {
                                if (device.Sector.DataBlock.First(x => x.DataBlockNumberSectorBased == gcVM.DataBlockNumber).Data != null)
                                {
                                    gcVM.MifareClassicDataBlock.Data = device.Sector.DataBlock.First(x => x.DataBlockNumberSectorBased == gcVM.DataBlockNumber).Data;                                     //device.currentSector[gcVM.DataBlockNumber];
                                    gcVM.IsAuthenticated             = true;
                                }
                                else
                                {
                                    gcVM.IsAuthenticated = false;
                                }
                            }
                            else
                            {
                                gcVM.IsAuthenticated = false;
                            }
                        }
                    }

                    this.IsExpanded = true;

                    Mouse.OverrideCursor = null;
                }
            }
        }
Exemplo n.º 3
0
        public SetupViewModel(RFiDDevice _device)
        {
            using (SettingsReaderWriter settings = new SettingsReaderWriter())
            {
                device = _device;

                selectedReader = settings.DefaultSpecification.DefaultReaderProvider;

                ConnectToReaderCommand.Execute(null);
            }
        }
Exemplo n.º 4
0
        private void EraseDesfireCard()
        {
            if (!isTask)
            {
                using (RFiDDevice device = new RFiDDevice(settings.DefaultSpecification.DefaultReaderProvider))
                {
                    Mouse.OverrideCursor = Cursors.Wait;

                    this.IsExpanded = true;

                    Mouse.OverrideCursor = null;
                }
            }
        }
Exemplo n.º 5
0
        private void OnNewReadDataCommand()
        {
            //Mouse.OverrideCursor = Cursors.Wait;
            TaskErr = ERROR.Empty;

            Task classicTask =
                new Task(() =>
            {
                using (RFiDDevice device = RFiDDevice.Instance)
                {
                    if (device != null && device.ReadChipPublic() == ERROR.NoError)
                    {
                        StatusText = string.Format("{0}: {1}\n", DateTime.Now, ResourceLoader.getResource(""));
                    }

                    else
                    {
                        TaskErr = ERROR.DeviceNotReadyError;
                        return;
                    }

                    RaisePropertyChanged("ChildNodeViewModelTemp");

                    return;
                }
            });

            classicTask.Start();

            classicTask.ContinueWith((x) =>
            {
                //Mouse.OverrideCursor = null;

                if (TaskErr == ERROR.NoError)
                {
                    IsTaskCompletedSuccessfully = true;
                }
                else
                {
                    IsTaskCompletedSuccessfully = false;
                }
            });
        }
Exemplo n.º 6
0
        public void ReadSectorWithCustoms()
        {
            using (RFiDDevice device = new RFiDDevice())
            {
                IsSelected = true;

                this.dialogs.Add(new MifareClassicSetupViewModel(this, dialogs)
                {
                    Caption = String.Format("{0} UID:[{1}] Type:[{2}]",
                                            ResourceLoader.getResource("mifareAuthSettingsDialogCaption"),
                                            Parent.UidNumber,
                                            Parent.CardType),

                    IsClassicAuthInfoEnabled = true,

                    OnOk = (sender) =>
                    {
                        //databaseReaderWriter.WriteDatabase((sender.ViewModelContext as RFiDChipChildLayerViewModel)._sectorModel);
                    },

                    OnCancel = (sender) =>
                    {
                        sender.Close();
                    },

                    OnAuth = (sender) =>
                    {
                        //readerModel.ReadMiFareClassicSingleSector(sectorVM.SectorNumber, sender.selectedClassicKeyAKey, sender.selectedClassicKeyBKey);
                        this.IsAuthenticated = device.SectorSuccesfullyAuth;
                        foreach (RFiDChipGrandChildLayerViewModel gcVM in this.Children)
                        {
                        }
                    },

                    OnCloseRequest = (sender) =>
                    {
                        sender.Close();
                    }
                });
            }
        }
Exemplo n.º 7
0
        private void OnNewWriteDataCommand()
        {
            //Mouse.OverrideCursor = Cursors.Wait;

            TaskErr = ERROR.Empty;

            Task classicTask =
                new Task(() =>
            {
                using (RFiDDevice device = RFiDDevice.Instance)
                {
                    StatusText = string.Format("{0}: {1}\n", DateTime.Now, ResourceLoader.getResource("textBoxStatusTextBoxDllLoaded"));
                }
            });

            if (TaskErr == ERROR.Empty)
            {
                TaskErr = ERROR.DeviceNotReadyError;

                classicTask.ContinueWith((x) =>
                {
                    //Mouse.OverrideCursor = null;

                    if (TaskErr == ERROR.NoError)
                    {
                        IsTaskCompletedSuccessfully = true;
                    }
                    else
                    {
                        IsTaskCompletedSuccessfully = false;
                    }
                });                                          //TaskScheduler.FromCurrentSynchronizationContext()

                classicTask.Start();
            }

            return;
        }
Exemplo n.º 8
0
        private void MifareDesfireQuickCheck()
        {
            if (!isTask)
            {
                using (RFiDDevice device = RFiDDevice.Instance)
                {
                    if (device != null && device.GetMiFareDESFireChipAppIDs() == ERROR.NoError)
                    {
                        Mouse.OverrideCursor = Cursors.Wait;

                        var appIDs = device.AppIDList;

                        Children.Clear();

                        Children.Add(
                            new RFiDChipChildLayerViewModel(
                                string.Format("Available Space: {0}Byte", device.FreeMemory)));

                        Children.Add(
                            new RFiDChipChildLayerViewModel(
                                new MifareDesfireAppModel(0), this, CardType, dialogs));

                        foreach (uint appID in appIDs)
                        {
                            if (appID == 0)
                            {
                                continue;
                            }

                            Children.Add(new RFiDChipChildLayerViewModel(new MifareDesfireAppModel(appID), this, CardType, dialogs));

                            if (device.GetMifareDesfireAppSettings(settings.DefaultSpecification.MifareDesfireDefaultSecuritySettings.First(x => x.KeyType == KeyType_MifareDesFireKeyType.DefaultDesfireCardApplicationMasterKey).Key,
                                                                   settings.DefaultSpecification.MifareDesfireDefaultSecuritySettings.First(x => x.KeyType == KeyType_MifareDesFireKeyType.DefaultDesfireCardApplicationMasterKey).EncryptionType,
                                                                   0, (int)appID) == ERROR.NoError)
                            {
                                Children.First(x => x.AppID == appID).Children.Add(new RFiDChipGrandChildLayerViewModel(string.Format("Available Keys: {0}", device.MaxNumberOfAppKeys)));
                                Children.First(x => x.AppID == appID).Children.Add(new RFiDChipGrandChildLayerViewModel(string.Format("Key Settings: {0}", Enum.GetName(typeof(DESFireKeySettings), (device.DesfireAppKeySetting & (DESFireKeySettings)0xF0)))));

                                Children.First(x => x.AppID == appID).Children.Add(new RFiDChipGrandChildLayerViewModel(string.Format("Allow Change MK: {0}", (device.DesfireAppKeySetting & (DESFireKeySettings)0x01) == (DESFireKeySettings)0x01 ? "yes" : "no")));
                                Children.First(x => x.AppID == appID).Children.Add(new RFiDChipGrandChildLayerViewModel(string.Format("Allow Listing without MK: {0}", (device.DesfireAppKeySetting & (DESFireKeySettings)0x02) == (DESFireKeySettings)0x02 ? "yes" : "no")));
                                Children.First(x => x.AppID == appID).Children.Add(new RFiDChipGrandChildLayerViewModel(string.Format("Allow Create/Delete without MK: {0}", (device.DesfireAppKeySetting & (DESFireKeySettings)0x04) == (DESFireKeySettings)0x04 ? "yes" : "no")));
                                Children.First(x => x.AppID == appID).Children.Add(new RFiDChipGrandChildLayerViewModel(string.Format("Allow Change Config: {0}", (device.DesfireAppKeySetting & (DESFireKeySettings)0x08) == (DESFireKeySettings)0x08 ? "yes" : "no")));
                            }

                            //TODO add grandchild fileid
                            if (device.GetMifareDesfireFileList(
                                    settings.DefaultSpecification.MifareDesfireDefaultSecuritySettings.First(x => x.KeyType == KeyType_MifareDesFireKeyType.DefaultDesfireCardApplicationMasterKey).Key,
                                    settings.DefaultSpecification.MifareDesfireDefaultSecuritySettings.First(x => x.KeyType == KeyType_MifareDesFireKeyType.DefaultDesfireCardApplicationMasterKey).EncryptionType,
                                    0, (int)appID) == ERROR.NoError)
                            {
                                foreach (byte fileID in device.FileIDList)
                                {
                                    Children.First(x => x.AppID == appID).Children.Add(new RFiDChipGrandChildLayerViewModel(new MifareDesfireFileModel(null, fileID), Children.First(x => x.AppID == appID)));

                                    if (device.GetMifareDesfireFileSettings(settings.DefaultSpecification.MifareDesfireDefaultSecuritySettings.First(x => x.KeyType == KeyType_MifareDesFireKeyType.DefaultDesfireCardApplicationMasterKey).Key,
                                                                            settings.DefaultSpecification.MifareDesfireDefaultSecuritySettings.First(x => x.KeyType == KeyType_MifareDesFireKeyType.DefaultDesfireCardApplicationMasterKey).EncryptionType,
                                                                            0, (int)appID, fileID) == ERROR.NoError)
                                    {
                                        RFiDChipGrandChildLayerViewModel grandChild = Children.First(x => x.AppID == appID).Children.First(y => (y.DesfireFile != null ? y.DesfireFile.FileID : -1) == fileID);

                                        grandChild.Children.Add(new RFiDChipGrandGrandChildLayerViewModel(string.Format("FileType: {0}", Enum.GetName(typeof(FileType_MifareDesfireFileType), device.DesfireFileSetting.FileType)), grandChild));
                                        grandChild.Children.Add(new RFiDChipGrandGrandChildLayerViewModel(string.Format("FileSize: {0}Bytes", device.DesfireFileSetting.dataFile.fileSize.ToString()), grandChild));
                                        grandChild.Children.Add(new RFiDChipGrandGrandChildLayerViewModel(string.Format("EncryptionMode: {0}", Enum.GetName(typeof(EncryptionMode), device.DesfireFileSetting.comSett)), grandChild));
                                        grandChild.Children.Add(new RFiDChipGrandGrandChildLayerViewModel(string.Format("Read: {0}", Enum.GetName(typeof(TaskAccessRights), ((device.DesfireFileSetting.accessRights[1] & 0xF0) >> 4))), grandChild));
                                        grandChild.Children.Add(new RFiDChipGrandGrandChildLayerViewModel(string.Format("Write: {0}", Enum.GetName(typeof(TaskAccessRights), device.DesfireFileSetting.accessRights[1] & 0x0F)), grandChild));
                                        grandChild.Children.Add(new RFiDChipGrandGrandChildLayerViewModel(string.Format("RW: {0}", Enum.GetName(typeof(TaskAccessRights), ((device.DesfireFileSetting.accessRights[0] & 0xF0) >> 4))), grandChild));                                   //lsb, upper nibble
                                        grandChild.Children.Add(new RFiDChipGrandGrandChildLayerViewModel(string.Format("Change: {0}", Enum.GetName(typeof(TaskAccessRights), device.DesfireFileSetting.accessRights[0] & 0x0F)), grandChild));                                        //lsb , lower nibble
                                    }
                                }
                            }
                        }

                        if (device.AuthToMifareDesfireApplication("00000000000000000000000000000000", DESFireKeyType.DF_KEY_AES, 0) == ERROR.NoError ||
                            device.AuthToMifareDesfireApplication("00000000000000000000000000000000", DESFireKeyType.DF_KEY_3K3DES, 0) == ERROR.NoError ||
                            device.AuthToMifareDesfireApplication("00000000000000000000000000000000", DESFireKeyType.DF_KEY_DES, 0) == ERROR.NoError)
                        {
                            Children.First(x => x.AppID == 0).Children.Add(new RFiDChipGrandChildLayerViewModel("PICC MasterKey NOT Set"));
                        }
                        else
                        {
                            Children.First(x => x.AppID == 0).Children.Add(new RFiDChipGrandChildLayerViewModel("PICC SECURED, MasterKey Unkown"));
                        }

                        IsExpanded = true;

                        Mouse.OverrideCursor = null;
                    }
                }
            }
        }