Skip to content

Commit 63c4709

Browse files
v1.3 Commissioner Passcode field for Linux and Android tv-casting-apps (#33038)
1 parent e48e04a commit 63c4709

File tree

13 files changed

+55
-21
lines changed

13 files changed

+55
-21
lines changed

examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/DiscoveryExampleFragment.java

+4
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ private String getCastingPlayerButtonText(CastingPlayer player) {
350350
? (aux.isEmpty() ? "" : ", ") + "Device Type: " + player.getDeviceType()
351351
: "";
352352
aux += (aux.isEmpty() ? "" : ", ") + "Resolved IP?: " + (player.getIpAddresses().size() > 0);
353+
aux +=
354+
(aux.isEmpty() ? "" : ", ")
355+
+ "Supports Commissioner Generated Passcode: "
356+
+ (player.getSupportsCommissionerGeneratedPasscode());
353357

354358
aux = aux.isEmpty() ? aux : "\n" + aux;
355359
return main + aux;

examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingPlayer.java

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public interface CastingPlayer {
4949

5050
long getDeviceType();
5151

52+
boolean getSupportsCommissionerGeneratedPasscode();
53+
5254
List<Endpoint> getEndpoints();
5355

5456
@Override

examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/MatterCastingPlayer.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class MatterCastingPlayer implements CastingPlayer {
4747
private int productId;
4848
private int vendorId;
4949
private long deviceType;
50+
private boolean supportsCommissionerGeneratedPasscode;
51+
5052
protected long _cppCastingPlayer;
5153

5254
public MatterCastingPlayer(
@@ -59,7 +61,8 @@ public MatterCastingPlayer(
5961
int port,
6062
int productId,
6163
int vendorId,
62-
long deviceType) {
64+
long deviceType,
65+
boolean supportsCommissionerGeneratedPasscode) {
6366
this.connected = connected;
6467
this.deviceId = deviceId;
6568
this.hostName = hostName;
@@ -70,6 +73,7 @@ public MatterCastingPlayer(
7073
this.productId = productId;
7174
this.vendorId = vendorId;
7275
this.deviceType = deviceType;
76+
this.supportsCommissionerGeneratedPasscode = supportsCommissionerGeneratedPasscode;
7377
}
7478

7579
/**
@@ -131,6 +135,11 @@ public long getDeviceType() {
131135
return this.deviceType;
132136
}
133137

138+
@Override
139+
public boolean getSupportsCommissionerGeneratedPasscode() {
140+
return this.supportsCommissionerGeneratedPasscode;
141+
}
142+
134143
@Override
135144
public native List<Endpoint> getEndpoints();
136145

examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/Converters-JNI.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ jobject convertCastingPlayerFromCppToJava(matter::casting::memory::Strong<core::
151151
// Get the constructor for the com/matter/casting/core/MatterCastingPlayer Java class
152152
jmethodID constructor =
153153
env->GetMethodID(matterCastingPlayerJavaClass, "<init>",
154-
"(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;IIIJ)V");
154+
"(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;IIIJZ)V");
155155
if (constructor == nullptr)
156156
{
157157
ChipLogError(AppServer, "convertCastingPlayerFromCppToJava() could not locate MatterCastingPlayer Java class constructor");
@@ -186,7 +186,8 @@ jobject convertCastingPlayerFromCppToJava(matter::casting::memory::Strong<core::
186186
env->NewStringUTF(player->GetId()), env->NewStringUTF(player->GetHostName()),
187187
env->NewStringUTF(player->GetDeviceName()), env->NewStringUTF(player->GetInstanceName()),
188188
jIpAddressList, (jint) (player->GetPort()), (jint) (player->GetProductId()),
189-
(jint) (player->GetVendorId()), (jlong) (player->GetDeviceType()));
189+
(jint) (player->GetVendorId()), (jlong) (player->GetDeviceType()),
190+
static_cast<jboolean>(player->GetSupportsCommissionerGeneratedPasscode()));
190191
if (jMatterCastingPlayer == nullptr)
191192
{
192193
ChipLogError(AppServer, "convertCastingPlayerFromCppToJava(): Could not create MatterCastingPlayer Java object");

examples/tv-casting-app/linux/simple-app-helper.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ DiscoveryDelegateImpl * DiscoveryDelegateImpl::GetInstance()
4545

4646
void DiscoveryDelegateImpl::HandleOnAdded(matter::casting::memory::Strong<matter::casting::core::CastingPlayer> player)
4747
{
48+
ChipLogProgress(AppServer, "DiscoveryDelegateImpl::HandleOnAdded() called");
4849
if (commissionersCount == 0)
4950
{
5051
ChipLogProgress(AppServer, "Select discovered Casting Player (start index = 0) to request commissioning");
@@ -58,7 +59,7 @@ void DiscoveryDelegateImpl::HandleOnAdded(matter::casting::memory::Strong<matter
5859

5960
void DiscoveryDelegateImpl::HandleOnUpdated(matter::casting::memory::Strong<matter::casting::core::CastingPlayer> player)
6061
{
61-
ChipLogProgress(AppServer, "Updated CastingPlayer with ID: %s", player->GetId());
62+
ChipLogProgress(AppServer, "DiscoveryDelegateImpl::HandleOnUpdated() Updated CastingPlayer with ID: %s", player->GetId());
6263
}
6364

6465
void InvokeContentLauncherLaunchURL(matter::casting::memory::Strong<matter::casting::core::Endpoint> endpoint)

examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ bool CastingPlayer::ContainsDesiredEndpoint(core::CastingPlayer * cachedCastingP
236236

237237
void CastingPlayer::LogDetail() const
238238
{
239+
ChipLogProgress(AppServer, "CastingPlayer::LogDetail() called");
239240
if (strlen(mAttributes.id) != 0)
240241
{
241242
ChipLogDetail(AppServer, "\tID: %s", mAttributes.id);
@@ -281,6 +282,8 @@ void CastingPlayer::LogDetail() const
281282
{
282283
ChipLogDetail(AppServer, "\tDevice Type: %" PRIu32, mAttributes.deviceType);
283284
}
285+
ChipLogDetail(AppServer, "\tSupports Commissioner Generated Passcode: %s",
286+
mAttributes.supportsCommissionerGeneratedPasscode ? "true" : "false");
284287
if (mAttributes.nodeId > 0)
285288
{
286289
ChipLogDetail(AppServer, "\tNode ID: 0x" ChipLogFormatX64, ChipLogValueX64(mAttributes.nodeId));

examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ class CastingPlayerAttributes
5656
char deviceName[chip::Dnssd::kMaxDeviceNameLen + 1] = {};
5757
char hostName[chip::Dnssd::kHostNameMaxLength + 1] = {};
5858
char instanceName[chip::Dnssd::Commission::kInstanceNameMaxLength + 1] = {};
59-
unsigned int numIPs; // number of valid IP addresses
59+
unsigned int numIPs; // Number of valid IP addresses
6060
chip::Inet::IPAddress ipAddresses[chip::Dnssd::CommonResolutionData::kMaxIPAddresses];
6161
chip::Inet::InterfaceId interfaceId;
6262
uint16_t port;
6363
uint16_t productId;
6464
uint16_t vendorId;
6565
uint32_t deviceType;
66+
bool supportsCommissionerGeneratedPasscode;
6667

6768
chip::NodeId nodeId = 0;
6869
chip::FabricIndex fabricIndex = 0;
@@ -182,6 +183,8 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>
182183

183184
uint32_t GetDeviceType() const { return mAttributes.deviceType; }
184185

186+
bool GetSupportsCommissionerGeneratedPasscode() const { return mAttributes.supportsCommissionerGeneratedPasscode; }
187+
185188
chip::NodeId GetNodeId() const { return mAttributes.nodeId; }
186189

187190
chip::FabricIndex GetFabricIndex() const { return mAttributes.fabricIndex; }

examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::Discover
9393
{
9494
attributes.ipAddresses[j] = nodeData.resolutionData.ipAddress[j];
9595
}
96-
attributes.interfaceId = nodeData.resolutionData.interfaceId;
97-
attributes.port = nodeData.resolutionData.port;
98-
attributes.productId = nodeData.nodeData.productId;
99-
attributes.vendorId = nodeData.nodeData.vendorId;
100-
attributes.deviceType = nodeData.nodeData.deviceType;
96+
attributes.interfaceId = nodeData.resolutionData.interfaceId;
97+
attributes.port = nodeData.resolutionData.port;
98+
attributes.productId = nodeData.nodeData.productId;
99+
attributes.vendorId = nodeData.nodeData.vendorId;
100+
attributes.deviceType = nodeData.nodeData.deviceType;
101+
attributes.supportsCommissionerGeneratedPasscode = nodeData.nodeData.supportsCommissionerGeneratedPasscode;
101102

102103
memory::Strong<CastingPlayer> player = std::make_shared<CastingPlayer>(attributes);
103104

examples/tv-casting-app/tv-casting-common/support/CastingStore.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ std::vector<core::CastingPlayer> CastingStore::ReadAll()
182182
continue;
183183
}
184184

185+
if (castingPlayerContainerTagNum == kCastingPlayerSupportsCommissionerGeneratedPasscodeTag)
186+
{
187+
err = reader.Get(attributes.supportsCommissionerGeneratedPasscode);
188+
VerifyOrReturnValue(err == CHIP_NO_ERROR, std::vector<core::CastingPlayer>(),
189+
ChipLogError(AppServer, "TLVReader.Get failed %" CHIP_ERROR_FORMAT, err.Format()));
190+
continue;
191+
}
192+
185193
if (castingPlayerContainerTagNum == kCastingPlayerPortTag)
186194
{
187195
err = reader.Get(attributes.port);
@@ -472,6 +480,8 @@ CHIP_ERROR CastingStore::WriteAll(std::vector<core::CastingPlayer> castingPlayer
472480
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerVendorIdTag), castingPlayer.GetVendorId()));
473481
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerProductIdTag), castingPlayer.GetProductId()));
474482
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerDeviceTypeIdTag), castingPlayer.GetDeviceType()));
483+
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerSupportsCommissionerGeneratedPasscodeTag),
484+
castingPlayer.GetSupportsCommissionerGeneratedPasscode()));
475485
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerPortTag), castingPlayer.GetPort()));
476486
ReturnErrorOnFailure(tlvWriter.PutBytes(chip::TLV::ContextTag(kCastingPlayerInstanceNameTag),
477487
(const uint8_t *) castingPlayer.GetInstanceName(),

examples/tv-casting-app/tv-casting-common/support/CastingStore.h

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class CastingStore : public chip::FabricTable::Delegate
9797
kCastingPlayerEndpointServerListContainerTag,
9898
kCastingPlayerEndpointServerClusterIdTag,
9999

100+
kCastingPlayerSupportsCommissionerGeneratedPasscodeTag,
101+
100102
kContextTagMaxNum = UINT8_MAX
101103
};
102104

src/lib/dnssd/TxtFields.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void GetPairingInstruction(const ByteSpan & value, char * pairingInstruction)
185185

186186
uint8_t GetCommissionerPasscode(const ByteSpan & value)
187187
{
188-
return MakeU8FromAsciiDecimal(value);
188+
return MakeBoolFromAsciiDecimal(value);
189189
}
190190

191191
Optional<System::Clock::Milliseconds32> GetRetryInterval(const ByteSpan & value)
@@ -256,7 +256,7 @@ void FillNodeDataFromTxt(const ByteSpan & key, const ByteSpan & val, DnssdNodeDa
256256
nodeData.pairingHint = Internal::GetPairingHint(val);
257257
break;
258258
case TxtFieldKey::kCommissionerPasscode:
259-
nodeData.commissionerPasscode = Internal::GetCommissionerPasscode(val);
259+
nodeData.supportsCommissionerGeneratedPasscode = Internal::GetCommissionerPasscode(val);
260260
break;
261261
default:
262262
break;

src/lib/dnssd/Types.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ struct DnssdNodeData
214214
uint16_t productId = 0;
215215
uint16_t pairingHint = 0;
216216
uint8_t commissioningMode = 0;
217-
uint8_t commissionerPasscode = 0;
217+
bool supportsCommissionerGeneratedPasscode = false;
218218
uint8_t rotatingId[kMaxRotatingIdLen] = {};
219219
char instanceName[Commission::kInstanceNameMaxLength + 1] = {};
220220
char deviceName[kMaxDeviceNameLen + 1] = {};
@@ -272,10 +272,8 @@ struct DnssdNodeData
272272
ChipLogDetail(Discovery, "\tInstance Name: %s", instanceName);
273273
}
274274
ChipLogDetail(Discovery, "\tCommissioning Mode: %u", commissioningMode);
275-
if (commissionerPasscode > 0)
276-
{
277-
ChipLogDetail(Discovery, "\tCommissioner Passcode: %u", commissionerPasscode);
278-
}
275+
ChipLogDetail(Discovery, "\tSupports Commissioner Generated Passcode: %s",
276+
supportsCommissionerGeneratedPasscode ? "true" : "false");
279277
}
280278
};
281279

src/lib/dnssd/tests/TestTxtFields.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ bool NodeDataIsEmpty(const DiscoveredNodeData & node)
309309
node.nodeData.pairingHint != 0 || node.resolutionData.mrpRetryIntervalIdle.HasValue() ||
310310
node.resolutionData.mrpRetryIntervalActive.HasValue() || node.resolutionData.mrpRetryActiveThreshold.HasValue() ||
311311
node.resolutionData.isICDOperatingAsLIT.HasValue() || node.resolutionData.supportsTcp ||
312-
node.nodeData.commissionerPasscode != 0)
312+
node.nodeData.supportsCommissionerGeneratedPasscode != 0)
313313
{
314314
return false;
315315
}
@@ -360,12 +360,12 @@ void TestFillDiscoveredNodeDataFromTxt(nlTestSuite * inSuite, void * inContext)
360360
filled.nodeData.commissioningMode = 0;
361361
NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled));
362362

363-
// Commissioning mode
363+
// Supports Commissioner Generated Passcode
364364
strcpy(key, "CP");
365365
strcpy(val, "1");
366366
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData);
367-
NL_TEST_ASSERT(inSuite, filled.nodeData.commissionerPasscode == 1);
368-
filled.nodeData.commissionerPasscode = 0;
367+
NL_TEST_ASSERT(inSuite, filled.nodeData.supportsCommissionerGeneratedPasscode == true);
368+
filled.nodeData.supportsCommissionerGeneratedPasscode = false;
369369
NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled));
370370

371371
// Device type

0 commit comments

Comments
 (0)