Skip to content

Commit 014ae24

Browse files
committed
misc. commissioning fixes
1 parent 69869a0 commit 014ae24

File tree

8 files changed

+72
-9
lines changed

8 files changed

+72
-9
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// MatterDotNet Copyright (C) 2025
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU Affero General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or any later version.
6+
// This program is distributed in the hope that it will be useful,
7+
// but WITHOUT ANY WARRANTY, without even the implied warranty of
8+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9+
// See the GNU Affero General Public License for more details.
10+
// You should have received a copy of the GNU Affero General Public License
11+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
12+
13+
namespace MatterDotNet.OperationalDiscovery
14+
{
15+
/// <summary>
16+
/// Device Commissioning Mode
17+
/// </summary>
18+
public enum CommissioningMode
19+
{
20+
/// <summary>
21+
/// Device cannot be commissioined
22+
/// </summary>
23+
None = 0,
24+
/// <summary>
25+
/// Device is in Basic Commissioning Mode
26+
/// </summary>
27+
Basic = 1,
28+
/// <summary>
29+
/// Device is in Dynamic Commissioning Mode (with dynamically generated PIN)
30+
/// </summary>
31+
Dynamic = 2,
32+
}
33+
}

MatterDotNet/OperationalDiscovery/ODNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public record ODNode
3030
public uint Vendor { get; set; }
3131
public uint Product { get; set; }
3232
public ushort Descriminator { get; set; }
33-
public bool Commissionable { get; set; }
33+
public CommissioningMode CommissioningMode { get; set; }
3434
}
3535
}

MatterDotNet/OperationalDiscovery/SupportedTransportMode.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,24 @@ namespace MatterDotNet.OperationalDiscovery
1515
/// <summary>
1616
/// Supported node IP transport
1717
/// </summary>
18+
[Flags]
1819
public enum SupportedTransportMode
1920
{
2021
/// <summary>
2122
/// MRP Only
2223
/// </summary>
2324
None = 0,
2425
/// <summary>
26+
/// Deprecated
27+
/// </summary>
28+
Reserved = 1,
29+
/// <summary>
2530
/// TCP in Client Mode
2631
/// </summary>
27-
TCPClient = 1,
32+
TCPClient = 2,
2833
/// <summary>
2934
/// TCP in Server Mode
3035
/// </summary>
31-
TCPServer = 2
36+
TCPServer = 4
3237
}
3338
}

MatterDotNet/Protocol/Payloads/Frame.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ public void Serialize(PayloadWriter stream, SessionContext session)
6565
{
6666
PayloadWriter secureStream = new PayloadWriter(temp);
6767
Message.Serialize(secureStream);
68-
SecureSession? secureContext = session as SecureSession;
68+
SecureSession secureContext = (SecureSession)session;
6969
Span<byte> nonce = new byte[Crypto.NONCE_LENGTH_BYTES];
7070
stream.GetPayload().Span.Slice(3, 5).CopyTo(nonce);
7171
if ((Security & SecurityFlags.GroupSession) == SecurityFlags.GroupSession)
7272
BinaryPrimitives.WriteUInt64LittleEndian(nonce.Slice(5, 8), SourceNodeID);
73-
else if (!secureContext!.PASE)
73+
else if (!secureContext.PASE)
7474
BinaryPrimitives.WriteUInt64LittleEndian(nonce.Slice(5, 8), session.Initiator ? session.InitiatorNodeID : session.ResponderNodeID);
7575

76-
ReadOnlySpan<byte> mic = Crypto.AEAD_GenerateEncrypt(secureContext!.Initiator ? secureContext.I2RKey : secureContext.R2IKey, secureStream.GetPayload().Span, stream.GetPayload().Span, nonce);
76+
ReadOnlySpan<byte> mic = Crypto.AEAD_GenerateEncrypt(secureContext.Initiator ? secureContext.I2RKey : secureContext.R2IKey, secureStream.GetPayload().Span, stream.GetPayload().Span, nonce);
7777
stream.Write(secureStream);
7878
stream.Write(mic);
7979
if ((Security & SecurityFlags.Privacy) == SecurityFlags.Privacy)

MatterDotNet/Protocol/Payloads/Version1Payload.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,24 @@ public class Version1Payload : IPayload
3232

3333
public override string ToString()
3434
{
35-
return $"[Flags: {Flags}, Proto: {Protocol}, Op: {OpCode}, Exchange: {ExchangeID}, Ack: {AckCounter}, Content: {Payload}]";
35+
return $"[Flags: {Flags}, Proto: {Protocol}, Op: {GetOp(Protocol, OpCode)}, Exchange: {ExchangeID}, Ack: {AckCounter}, Content: {Payload}]";
36+
}
37+
38+
private string GetOp(ProtocolType protocol, byte opCode)
39+
{
40+
switch (protocol)
41+
{
42+
case ProtocolType.SecureChannel:
43+
return ((SecureOpCodes)opCode).ToString();
44+
case ProtocolType.InteractionModel:
45+
return ((IMOpCodes)opCode).ToString();
46+
case ProtocolType.BDX:
47+
return ((BDXOpCodes)opCode).ToString();
48+
case ProtocolType.UserDirectedCommissioning:
49+
return ((UDCOpCodes)opCode).ToString();
50+
default:
51+
return opCode.ToString();
52+
}
3653
}
3754

3855
public Version1Payload(IPayload? payload, byte opCode)

MatterDotNet/Protocol/Subprotocols/CASE.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using MatterDotNet.PKI;
1616
using MatterDotNet.Protocol.Cryptography;
1717
using MatterDotNet.Protocol.Payloads;
18+
using MatterDotNet.Protocol.Payloads.Flags;
1819
using MatterDotNet.Protocol.Payloads.OpCodes;
1920
using MatterDotNet.Protocol.Payloads.Status;
2021
using MatterDotNet.Protocol.Sessions;
@@ -67,6 +68,7 @@ public class CASE(SessionContext unsecureSession)
6768
};
6869

6970
Frame sigma1 = new Frame(Msg1, (byte)SecureOpCodes.CASESigma1);
71+
sigma1.Flags |= MessageFlags.SourceNodeID;
7072
await exchange.SendFrame(sigma1);
7173
resp = await exchange.Read();
7274
if (resp.Message.Payload is StatusPayload error)
@@ -159,7 +161,9 @@ public class CASE(SessionContext unsecureSession)
159161
PayloadWriter Msg3Bytes = new PayloadWriter(1024);
160162
Msg3.Serialize(Msg3Bytes);
161163

162-
await exchange.SendFrame(new Frame(Msg3, (byte)SecureOpCodes.CASESigma3));
164+
Frame sigma3 = new Frame(Msg3, (byte)SecureOpCodes.CASESigma3);
165+
sigma3.Flags |= MessageFlags.SourceNodeID;
166+
await exchange.SendFrame(sigma3);
163167
Frame? resp = await exchange.Read();
164168

165169
StatusPayload s3resp = (StatusPayload)resp.Message.Payload!;
@@ -211,6 +215,7 @@ public class CASE(SessionContext unsecureSession)
211215
};
212216

213217
Frame sigma1 = new Frame(Msg1, (byte)SecureOpCodes.CASESigma1);
218+
sigma1.Flags |= MessageFlags.SourceNodeID;
214219
await exchange.SendFrame(sigma1);
215220
resp = await exchange.Read();
216221

MatterDotNet/Protocol/Subprotocols/PASE.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private Frame GeneratePake1(PBKDFParamResp paramResp, uint passcode)
7272
BigIntegerPoint pA = spake.PAKEValues_Initiator(passcode, (int)paramResp.Pbkdf_parameters!.Iterations, paramResp.Pbkdf_parameters!.Salt);
7373
Pake1 pk1 = new Pake1() { PA = pA.ToBytes(false) };
7474
Frame frame = new Frame(pk1, (byte)SecureOpCodes.PASEPake1);
75+
frame.Flags |= MessageFlags.SourceNodeID;
7576
return frame;
7677
}
7778

@@ -86,6 +87,7 @@ private Frame GeneratePake3(Pake1 pake1, Pake2 pake2, PBKDFParamReq req, PBKDFPa
8687
CA = SessionKeys.cA
8788
};
8889
Frame frame = new Frame(pake3, (byte)SecureOpCodes.PASEPake3);
90+
frame.Flags |= MessageFlags.SourceNodeID;
8991
return frame;
9092
}
9193

@@ -100,6 +102,7 @@ private Frame GenerateParamRequest(bool hasOnboardingPayload = false)
100102
};
101103

102104
Frame frame = new Frame(req, (byte)SecureOpCodes.PBKDFParamRequest);
105+
frame.Flags |= MessageFlags.SourceNodeID;
103106
return frame;
104107
}
105108
}

MatterDotNet/Protocol/TLV/TLVReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void StartList(long listNumber = -1)
8080
public void EndContainer()
8181
{
8282
while (type != ElementType.EndOfContainer && type != ElementType.None)
83-
GetAny(tagNumber);
83+
GetAny(tagNumber, true);
8484
if (type != ElementType.EndOfContainer)
8585
throw new InvalidDataException("End structure was not found");
8686
ReadTag();

0 commit comments

Comments
 (0)