forked from nanoframework/nanoFramework.IoT.Device
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configuration.cs
73 lines (65 loc) · 2.58 KB
/
Configuration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Iot.Device.Card.Ultralight
{
/// <summary>
/// The different configuration elements
/// </summary>
public class Configuration
{
/// <summary>
/// Create a default Configuration
/// </summary>
public Configuration()
{
Mirror = new MirrorConfiguration();
Authentication = new AuthenticationConfiguration();
NfcCounter = new NfcCounterConfiguration();
}
/// <summary>
/// Gets or sets the Mirror configuration.
/// </summary>
public MirrorConfiguration Mirror { get; set; }
/// <summary>
/// Gets or sets the Authentication configuration.
/// </summary>
public AuthenticationConfiguration Authentication { get; set; }
/// <summary>
/// Gets or sets the NFC counter configuration
/// </summary>
public NfcCounterConfiguration NfcCounter { get; set; }
/// <summary>
/// Is the strong Mirror Modulation Mode enabled
/// </summary>
public bool IsStrongModulation { get; set; }
/// <summary>
/// Is the sleep mode enabled
/// </summary>
public bool IsSleepEnabled { get; set; }
/// <summary>
/// Field Detect Pin mode
/// </summary>
public FieldDetectPin FieldDetectPin { get; set; }
/// <summary>
/// Serialize the configuration in a 8 bytes array skipping Password and Pack
/// </summary>
/// <returns>The serialized byte array</returns>
internal byte[] Serialize()
{
byte[] data = new byte[8];
data[0] = (byte)((byte)(Mirror.MirrorType) << 6);
data[0] |= (byte)(Mirror.Position << 4);
data[0] |= (byte)(IsStrongModulation ? 0b0000_0100 : 0);
data[0] |= (byte)(IsSleepEnabled ? 0b0000_1000 : 0);
data[0] |= (byte)FieldDetectPin;
data[2] = Mirror.Page;
data[3] = Authentication.AuthenticationPageRequirement;
data[4] = (byte)(Authentication.IsReadWriteAuthenticationRequired ? 0b1000_0000 : 0);
data[4] |= (byte)(Authentication.IsWritingLocked ? 0b0100_0000 : 0);
data[4] |= (byte)(NfcCounter.IsEnabled ? 0b0001_0000 : 0);
data[4] |= (byte)(NfcCounter.IsPasswordProtected ? 0b0000_1000 : 0);
data[4] |= Authentication.MaximumNumberOfPossibleTries;
return data;
}
}
}