OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
Packet.cs
1using System;
2
7
8namespace OSDP.Net.Model;
9
13public class Packet : IPacket
14{
15 private readonly byte[] _rawPayloadData;
16 private readonly byte[] _rawData;
17 private readonly bool _isUsingDefaultKey;
18
23 public Packet(IncomingMessage message)
24 {
25 IncomingMessage = message;
26
27 Address = message.Address;
28 Sequence = message.Sequence;
29 if (message.MessageType == MessageType.Command)
30 {
31 CommandType = (CommandType)message.Type;
32 }
33 else
34 {
35 ReplyType = (ReplyType)message.Type;
36 }
37
38 IsUsingCrc = message.IsUsingCrc;
39 _rawPayloadData = message.Payload;
40 _rawData = message.OriginalMessageData.ToArray();
41 _isUsingDefaultKey = message.IsUsingDefaultKey;
42 }
43
48
52 public byte Address { get; }
53
57 public byte Sequence { get; }
58
62 public CommandType? CommandType { get; }
63
67 public ReplyType? ReplyType { get; }
68
72 public bool IsUsingCrc { get; }
73
82 public bool IsPayloadDecrypted => IncomingMessage.IsPayloadDecrypted;
83
87 public bool IsSecureMessage => IncomingMessage.IsSecureMessage;
88
92 public bool IsUsingDefaultKey => _isUsingDefaultKey;
93
98 public object ParsePayloadData()
99 {
101 {
102 return null;
103 }
104
105 switch (CommandType)
106 {
107 case Messages.CommandType.Poll:
108 return null;
109 case Messages.CommandType.IdReport:
110 return null;
111 case Messages.CommandType.DeviceCapabilities:
112 return null;
113 case Messages.CommandType.LocalStatus:
114 return null;
115 case Messages.CommandType.InputStatus:
116 return null;
117 case Messages.CommandType.OutputStatus:
118 return null;
119 case Messages.CommandType.ReaderStatus:
120 return null;
121 case Messages.CommandType.OutputControl:
123 case Messages.CommandType.LEDControl:
125 case Messages.CommandType.BuzzerControl:
127 case Messages.CommandType.TextOutput:
129 case Messages.CommandType.CommunicationSet:
131 case Messages.CommandType.BioRead:
133 case Messages.CommandType.BioMatch:
135 case Messages.CommandType.KeySet:
137 case Messages.CommandType.SessionChallenge:
138 return _rawPayloadData;
139 case Messages.CommandType.ServerCryptogram:
140 return _rawPayloadData;
141 case Messages.CommandType.MaxReplySize:
142 return null;
143 case Messages.CommandType.FileTransfer:
145 case Messages.CommandType.ManufacturerSpecific:
147 case Messages.CommandType.ExtendedWrite:
149 case Messages.CommandType.Abort:
150 return null;
151 case Messages.CommandType.PivData:
153 case Messages.CommandType.GenerateChallenge:
154 return null;
155 case Messages.CommandType.AuthenticateChallenge:
157 case Messages.CommandType.KeepActive:
158 return null;
159 }
160
161 switch (ReplyType)
162 {
163 case Messages.ReplyType.Ack:
164 break;
165 case Messages.ReplyType.Nak:
166 return Nak.ParseData(RawPayloadData);
167 case Messages.ReplyType.PdIdReport:
169 case Messages.ReplyType.PdCapabilitiesReport:
170 return DeviceCapabilities.ParseData(RawPayloadData);
171 case Messages.ReplyType.LocalStatusReport:
172 return LocalStatus.ParseData(RawPayloadData);
173 case Messages.ReplyType.InputStatusReport:
174 return InputStatus.ParseData(RawPayloadData);
175 case Messages.ReplyType.OutputStatusReport:
177 case Messages.ReplyType.ReaderStatusReport:
178 return ReaderStatus.ParseData(RawPayloadData);
179 case Messages.ReplyType.RawReaderData:
181 case Messages.ReplyType.FormattedReaderData:
182 break;
183 case Messages.ReplyType.KeypadData:
185 case Messages.ReplyType.PdCommunicationsConfigurationReport:
187 case Messages.ReplyType.BiometricData:
188 return BiometricReadResult.ParseData(RawPayloadData);
189 case Messages.ReplyType.BiometricMatchResult:
190 return BiometricMatchResult.ParseData(RawPayloadData);
191 case Messages.ReplyType.CrypticData:
192 return _rawPayloadData;
193 case Messages.ReplyType.InitialRMac:
194 return _rawPayloadData;
195 case Messages.ReplyType.Busy:
196 break;
197 case Messages.ReplyType.FileTransferStatus:
198 return FileTransferStatus.ParseData(RawPayloadData);
199 case Messages.ReplyType.PIVData:
201 case Messages.ReplyType.ResponseToChallenge:
202 return ChallengeResponse.ParseData(RawPayloadData, _isUsingDefaultKey);
203 case Messages.ReplyType.ManufactureSpecific:
205 case Messages.ReplyType.ExtendedRead:
207 }
208
209 return null;
210 }
211
215 public ReadOnlySpan<byte> RawPayloadData => _rawPayloadData;
216
220 public ReadOnlySpan<byte> RawData => _rawData;
221
223 ReadOnlyMemory<byte> IPacket.RawPayloadData => _rawPayloadData;
224
226 ReadOnlyMemory<byte> IPacket.RawData => _rawData;
227}
byte Type
Command/reply code of the message.
byte Sequence
Message sequence number.
ReadOnlySpan< byte > OriginalMessageData
Original byte data which includes the header, security control block, payload, MAC and CRC/Checksum s...
bool IsUsingCrc
If true, the message has a CRC suffix; otherwise it has a checksum.
bool IsUsingDefaultKey
Gets whether the incoming message is using the default key.
byte[] Payload
Returns the raw message payload.
MessageType MessageType
Type of message.
Definition Message.cs:73
byte Address
Address assigned to the device.
Definition Message.cs:68
Command data to send a request to the PD to perform a biometric scan and match.
static BiometricReadData ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
Command data to send a request to the PD to perform a biometric scan and return data.
static BiometricTemplateData ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
Command data to set the communication configuration on a PD.
static CommunicationConfiguration ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
Represents the capabilities of a device within the context of OSDP (Open Supervised Device Protocol).
Command data to set the encryption key configuration on a PD.
static EncryptionKeyConfiguration ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
Extended write (transparent mode) command data sent to a PD.
static ExtendedWrite ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
Command data to send a data fragment of a file to a PD.
static FileTransferFragment ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
Command data to get the PIV data.
Definition GetPIVData.cs:13
static GetPIVData ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
Definition GetPIVData.cs:76
Manufacture specific command data sent to a PD.
static ManufacturerSpecific ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
Represents a fragment of data for a multipart message.
static MessageDataFragment ParseData(ReadOnlySpan< byte > data, MessageDataFragmentFieldSize sizeAndOffsetFieldSize)
Parses the message payload bytes.
Command data to control the outputs of a PD.
static OutputControls ParseData(ReadOnlySpan< byte > payloadData)
Parses the message payload bytes.
Command data to control the buzzer on a PD.
static ReaderBuzzerControl ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
Command data to control the color of LEDs.
static ReaderLedControls ParseData(ReadOnlySpan< byte > payloadData)
Parses the message payload bytes.
Command data for sending text to be shown on a PD.
static ReaderTextOutput ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
CommandType? CommandType
The type of command sent or null it is a reply.
Definition Packet.cs:62
Packet(IncomingMessage message)
Initializes a new instance of the Packet class from an incoming message.
Definition Packet.cs:23
ReadOnlySpan< byte > RawData
Raw bytes of the entire message data.
Definition Packet.cs:220
bool IsPayloadDecrypted
Indicates whether the payload was successfully decrypted.
Definition Packet.cs:82
ReplyType? ReplyType
The type of reply sent or null it is a command.
Definition Packet.cs:67
bool IsSecureMessage
Indicates if the message was sent via an established secure channel.
Definition Packet.cs:87
byte Address
Address of the message.
Definition Packet.cs:52
ReadOnlySpan< byte > RawPayloadData
Raw bytes of the payload data.
Definition Packet.cs:215
bool IsUsingCrc
Is CRC being used.
Definition Packet.cs:72
object ParsePayloadData()
Parse the payload data into an object.
Definition Packet.cs:98
byte Sequence
Sequence number of the message.
Definition Packet.cs:57
IncomingMessage IncomingMessage
The underlying incoming message.
Definition Packet.cs:47
bool IsUsingDefaultKey
Indicates if the secure channel is using the default key.
Definition Packet.cs:92
A biometric match reply after a scan.
The actual communication configuration of the PD sent as a reply.
A multi-part message data fragment reply.
static DataFragmentResponse ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
The PD device capabilities data sent as a reply.
The PD identification data sent as a reply.
static DeviceIdentification ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
An extended read (transparent mode) reply.
static ExtendedRead ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
The PD file transfer status sent as a reply.
A input status report reply as defined in OSDP v2.2.2 specification.
static KeypadData ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
A local status report reply.
static ManufacturerSpecific ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
A negative reply.
Definition Nak.cs:14
A output status report reply.
static OutputStatus ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
static RawCardData ParseData(ReadOnlySpan< byte > data)
Parses the data.
A reader status report reply.
Represents a parsed OSDP packet with decoded message information.
Definition IPacket.cs:13
ReadOnlyMemory< byte > RawData
Raw bytes of the entire message data.
Definition IPacket.cs:67
ReadOnlyMemory< byte > RawPayloadData
Raw bytes of the payload data.
Definition IPacket.cs:62
MessageType
The type of message.
Definition MessageType.cs:7
MessageDataFragmentFieldSize
Defines the field size used for the MessageDataFragment.TotalSize and MessageDataFragment....
Definition Bus.cs:22