Skip to content

Commit

Permalink
Fix PC/SC reader selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxhy committed Apr 11, 2024
1 parent bb6e855 commit 146808d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 53 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private void DESFireAuthenticate()
throw new KeyStoreException("Unexpected commands type for the inserted RFID card.");
}

uint aid = BitConverter.ToUInt32(DESFireAID);
uint aid = (uint)(DESFireAID[0] << 16 | DESFireAID[1] << 8 | DESFireAID[2]);
ev1cmd.selectApplication(aid);

var key = new DESFireKey();
Expand Down
5 changes: 2 additions & 3 deletions KeyManager.Library.KeyStore.NXP_SAM.UI/LLAReaderControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@
xmlns:properties="clr-namespace:Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.Properties"
xmlns:wpfappctrls="clr-namespace:Leosac.WpfApp.Controls;assembly=WpfApp"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance domain:LLAReaderViewModel}"
d:DesignHeight="250" d:DesignWidth="400">
<StackPanel>
<ComboBox ItemsSource="{Binding ReaderProviders}" SelectedItem="{Binding ReaderProvider, ElementName=llaControl}"
<ComboBox ItemsSource="{Binding ReaderProviders, ElementName=llaControl}" SelectedItem="{Binding ReaderProvider, ElementName=llaControl, UpdateSourceTrigger=PropertyChanged}"
materialDesign:HintAssist.HelperText="{x:Static properties:Resources.ReaderProviderHelper}"
materialDesign:HintAssist.Hint="{x:Static properties:Resources.ReaderProvider}" Margin="5,5,5,10" SelectionChanged="cbReaderProvider_SelectionChanged" />
<DockPanel LastChildFill="True">
<Button DockPanel.Dock="Right" x:Name="btnRefreshReaderUnits" Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}" Width="24" Height="24" Margin="3" ToolTip="{x:Static properties:Resources.RefreshReaderUnits}" Click="btnRefreshReaderUnits_Click">
<materialDesign:PackIcon Kind="Refresh" Height="16" Width="16"/>
</Button>
<ComboBox ItemsSource="{Binding ReaderUnits}" SelectedItem="{Binding ReaderUnit, ElementName=llaControl}"
<ComboBox ItemsSource="{Binding ReaderUnits, ElementName=llaControl}" SelectedItem="{Binding ReaderUnit, ElementName=llaControl, UpdateSourceTrigger=PropertyChanged}"
materialDesign:HintAssist.HelperText="{x:Static properties:Resources.ReaderUnitHelper}"
materialDesign:HintAssist.Hint="{x:Static properties:Resources.ReaderUnit}"
materialDesign:TextFieldAssist.HasClearButton="True" Margin="5,5,5,10" />
Expand Down
37 changes: 28 additions & 9 deletions KeyManager.Library.KeyStore.NXP_SAM.UI/LLAReaderControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.Domain;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;

Expand All @@ -9,11 +10,15 @@ namespace Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI
/// </summary>
public partial class LLAReaderControl : UserControl
{
private readonly LibLogicalAccess.LibraryManager _lla;

public LLAReaderControl()
{
InitializeComponent();
_lla = LibLogicalAccess.LibraryManager.getInstance();
ReaderProviders = new ObservableCollection<string>(_lla.getAvailableReaders().ToArray());
ReaderUnits = new ObservableCollection<string>();

DataContext = new LLAReaderViewModel();
InitializeComponent();
}

public string ReaderProvider
Expand All @@ -32,20 +37,34 @@ public string ReaderUnit
public static readonly DependencyProperty ReaderUnitProperty = DependencyProperty.Register(nameof(ReaderUnit), typeof(string), typeof(LLAReaderControl),
new FrameworkPropertyMetadata(""));

private void cbReaderProvider_SelectionChanged(object sender, SelectionChangedEventArgs e)
public ObservableCollection<string> ReaderProviders { get; set; }

public ObservableCollection<string> ReaderUnits { get; set; }

public void RefreshReaderList()
{
if (DataContext is LLAReaderViewModel model)
var prevru = ReaderUnit;
ReaderUnits.Clear();
var rp = _lla.getReaderProvider(ReaderProvider);
var ruList = rp.getReaderList();
foreach (var ru in ruList)
{
ReaderUnits.Add(ru.getName());
}
if (ReaderUnits.Contains(prevru))
{
model.RefreshReaderList(this);
ReaderUnit = prevru;
}
}

private void cbReaderProvider_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
RefreshReaderList();
}

private void btnRefreshReaderUnits_Click(object sender, RoutedEventArgs e)
{
if (DataContext is LLAReaderViewModel model)
{
model.RefreshReaderList(this);
}
RefreshReaderList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
d:DataContext="{d:DesignInstance domain:SAMKeyStorePropertiesControlViewModel}"
d:DesignHeight="200" d:DesignWidth="500">
<StackPanel>
<local:LLAReaderControl ReaderProvider="{Binding SAMProperties.ReaderProvider}" ReaderUnit="{Binding SAMProperties.ReaderUnit}" />
<local:LLAReaderControl ReaderProvider="{Binding SAMProperties.ReaderProvider, Mode=TwoWay}" ReaderUnit="{Binding SAMProperties.ReaderUnit, Mode=TwoWay}" />
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="5">
<ToggleButton IsChecked="{Binding SAMProperties.AutoSwitchToAV2}" Style="{StaticResource MaterialDesignSwitchLightToggleButton}" />
<TextBlock Text="{x:Static properties:Resources.AutoSwitchToAV2}" Padding="3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<local:LLAReaderControl Grid.Row="0" Grid.ColumnSpan="2" ReaderProvider="{Binding RFIDReaderProvider}" ReaderUnit="{Binding RFIDReaderUnit}" />
<local:LLAReaderControl Grid.Row="0" Grid.ColumnSpan="2" ReaderProvider="{Binding RFIDReaderProvider, Mode=TwoWay}" ReaderUnit="{Binding RFIDReaderUnit, Mode=TwoWay}" />
<wpfappctrls:NumericUpDownControl Grid.Row="1" Grid.Column="0" MinValue="0" MaxValue="255" Margin="5"
CurrentValue="{Binding SAMDESFireKeyId, Mode=TwoWay}"
HelperText="{x:Static properties:Resources.KeyEntryIdentifierHelper}"
Expand All @@ -103,15 +103,17 @@
</StackPanel>
<TextBox Text="{Binding DESFireDivInput, Mode=TwoWay, Converter={StaticResource ByteArrayToStringConverter}}" Margin="5,5,5,10" Grid.Row="3" Grid.Column="1"
materialDesign:HintAssist.HelperText="{x:Static properties:Resources.DivInputHelper}"
materialDesign:HintAssist.Hint="{x:Static properties:Resources.DivInput}" />
materialDesign:HintAssist.Hint="{x:Static properties:Resources.DivInput}"
IsEnabled="{Binding DESFireUseDiversification}" />
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Grid.Row="4" Grid.Column="0" Margin="5">
<ToggleButton IsChecked="{Binding DESFireReadFile}" Style="{StaticResource MaterialDesignSwitchLightToggleButton}" />
<TextBlock Text="{x:Static properties:Resources.ReadFile}" Padding="3" />
</StackPanel>
<wpfappctrls:NumericUpDownControl Grid.Row="4" Grid.Column="1" MinValue="0" MaxValue="255" Margin="5"
CurrentValue="{Binding DESFireFileNo, Mode=TwoWay}"
HelperText="{x:Static properties:Resources.DESFireFileNoHelper}"
Hint="{x:Static properties:Resources.DESFireFileNo}"/>
Hint="{x:Static properties:Resources.DESFireFileNo}"
IsEnabled="{Binding DESFireReadFile}" />
<Button Content="{x:Static properties:Resources.Authenticate}" Command="{Binding DESFireAuthenticateCommand}" Grid.Row="5" Grid.ColumnSpan="2" Margin="0,30,0,0" Width="200" />
</Grid>
</StackPanel>
Expand Down

0 comments on commit 146808d

Please sign in to comment.