Skip to content

Commit

Permalink
v1.3 Commissioner Passcode field for Linux and Android tv-casting-apps (
Browse files Browse the repository at this point in the history
  • Loading branch information
pgregorr-amazon authored Apr 22, 2024
1 parent e48e04a commit 63c4709
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ private String getCastingPlayerButtonText(CastingPlayer player) {
? (aux.isEmpty() ? "" : ", ") + "Device Type: " + player.getDeviceType()
: "";
aux += (aux.isEmpty() ? "" : ", ") + "Resolved IP?: " + (player.getIpAddresses().size() > 0);
aux +=
(aux.isEmpty() ? "" : ", ")
+ "Supports Commissioner Generated Passcode: "
+ (player.getSupportsCommissionerGeneratedPasscode());

aux = aux.isEmpty() ? aux : "\n" + aux;
return main + aux;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public interface CastingPlayer {

long getDeviceType();

boolean getSupportsCommissionerGeneratedPasscode();

List<Endpoint> getEndpoints();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class MatterCastingPlayer implements CastingPlayer {
private int productId;
private int vendorId;
private long deviceType;
private boolean supportsCommissionerGeneratedPasscode;

protected long _cppCastingPlayer;

public MatterCastingPlayer(
Expand All @@ -59,7 +61,8 @@ public MatterCastingPlayer(
int port,
int productId,
int vendorId,
long deviceType) {
long deviceType,
boolean supportsCommissionerGeneratedPasscode) {
this.connected = connected;
this.deviceId = deviceId;
this.hostName = hostName;
Expand All @@ -70,6 +73,7 @@ public MatterCastingPlayer(
this.productId = productId;
this.vendorId = vendorId;
this.deviceType = deviceType;
this.supportsCommissionerGeneratedPasscode = supportsCommissionerGeneratedPasscode;
}

/**
Expand Down Expand Up @@ -131,6 +135,11 @@ public long getDeviceType() {
return this.deviceType;
}

@Override
public boolean getSupportsCommissionerGeneratedPasscode() {
return this.supportsCommissionerGeneratedPasscode;
}

@Override
public native List<Endpoint> getEndpoints();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ jobject convertCastingPlayerFromCppToJava(matter::casting::memory::Strong<core::
// Get the constructor for the com/matter/casting/core/MatterCastingPlayer Java class
jmethodID constructor =
env->GetMethodID(matterCastingPlayerJavaClass, "<init>",
"(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;IIIJ)V");
"(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;IIIJZ)V");
if (constructor == nullptr)
{
ChipLogError(AppServer, "convertCastingPlayerFromCppToJava() could not locate MatterCastingPlayer Java class constructor");
Expand Down Expand Up @@ -186,7 +186,8 @@ jobject convertCastingPlayerFromCppToJava(matter::casting::memory::Strong<core::
env->NewStringUTF(player->GetId()), env->NewStringUTF(player->GetHostName()),
env->NewStringUTF(player->GetDeviceName()), env->NewStringUTF(player->GetInstanceName()),
jIpAddressList, (jint) (player->GetPort()), (jint) (player->GetProductId()),
(jint) (player->GetVendorId()), (jlong) (player->GetDeviceType()));
(jint) (player->GetVendorId()), (jlong) (player->GetDeviceType()),
static_cast<jboolean>(player->GetSupportsCommissionerGeneratedPasscode()));
if (jMatterCastingPlayer == nullptr)
{
ChipLogError(AppServer, "convertCastingPlayerFromCppToJava(): Could not create MatterCastingPlayer Java object");
Expand Down
3 changes: 2 additions & 1 deletion examples/tv-casting-app/linux/simple-app-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ DiscoveryDelegateImpl * DiscoveryDelegateImpl::GetInstance()

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

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

void InvokeContentLauncherLaunchURL(matter::casting::memory::Strong<matter::casting::core::Endpoint> endpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ bool CastingPlayer::ContainsDesiredEndpoint(core::CastingPlayer * cachedCastingP

void CastingPlayer::LogDetail() const
{
ChipLogProgress(AppServer, "CastingPlayer::LogDetail() called");
if (strlen(mAttributes.id) != 0)
{
ChipLogDetail(AppServer, "\tID: %s", mAttributes.id);
Expand Down Expand Up @@ -281,6 +282,8 @@ void CastingPlayer::LogDetail() const
{
ChipLogDetail(AppServer, "\tDevice Type: %" PRIu32, mAttributes.deviceType);
}
ChipLogDetail(AppServer, "\tSupports Commissioner Generated Passcode: %s",
mAttributes.supportsCommissionerGeneratedPasscode ? "true" : "false");
if (mAttributes.nodeId > 0)
{
ChipLogDetail(AppServer, "\tNode ID: 0x" ChipLogFormatX64, ChipLogValueX64(mAttributes.nodeId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ class CastingPlayerAttributes
char deviceName[chip::Dnssd::kMaxDeviceNameLen + 1] = {};
char hostName[chip::Dnssd::kHostNameMaxLength + 1] = {};
char instanceName[chip::Dnssd::Commission::kInstanceNameMaxLength + 1] = {};
unsigned int numIPs; // number of valid IP addresses
unsigned int numIPs; // Number of valid IP addresses
chip::Inet::IPAddress ipAddresses[chip::Dnssd::CommonResolutionData::kMaxIPAddresses];
chip::Inet::InterfaceId interfaceId;
uint16_t port;
uint16_t productId;
uint16_t vendorId;
uint32_t deviceType;
bool supportsCommissionerGeneratedPasscode;

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

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

bool GetSupportsCommissionerGeneratedPasscode() const { return mAttributes.supportsCommissionerGeneratedPasscode; }

chip::NodeId GetNodeId() const { return mAttributes.nodeId; }

chip::FabricIndex GetFabricIndex() const { return mAttributes.fabricIndex; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::Discover
{
attributes.ipAddresses[j] = nodeData.resolutionData.ipAddress[j];
}
attributes.interfaceId = nodeData.resolutionData.interfaceId;
attributes.port = nodeData.resolutionData.port;
attributes.productId = nodeData.nodeData.productId;
attributes.vendorId = nodeData.nodeData.vendorId;
attributes.deviceType = nodeData.nodeData.deviceType;
attributes.interfaceId = nodeData.resolutionData.interfaceId;
attributes.port = nodeData.resolutionData.port;
attributes.productId = nodeData.nodeData.productId;
attributes.vendorId = nodeData.nodeData.vendorId;
attributes.deviceType = nodeData.nodeData.deviceType;
attributes.supportsCommissionerGeneratedPasscode = nodeData.nodeData.supportsCommissionerGeneratedPasscode;

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

Expand Down
10 changes: 10 additions & 0 deletions examples/tv-casting-app/tv-casting-common/support/CastingStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ std::vector<core::CastingPlayer> CastingStore::ReadAll()
continue;
}

if (castingPlayerContainerTagNum == kCastingPlayerSupportsCommissionerGeneratedPasscodeTag)
{
err = reader.Get(attributes.supportsCommissionerGeneratedPasscode);
VerifyOrReturnValue(err == CHIP_NO_ERROR, std::vector<core::CastingPlayer>(),
ChipLogError(AppServer, "TLVReader.Get failed %" CHIP_ERROR_FORMAT, err.Format()));
continue;
}

if (castingPlayerContainerTagNum == kCastingPlayerPortTag)
{
err = reader.Get(attributes.port);
Expand Down Expand Up @@ -472,6 +480,8 @@ CHIP_ERROR CastingStore::WriteAll(std::vector<core::CastingPlayer> castingPlayer
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerVendorIdTag), castingPlayer.GetVendorId()));
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerProductIdTag), castingPlayer.GetProductId()));
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerDeviceTypeIdTag), castingPlayer.GetDeviceType()));
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerSupportsCommissionerGeneratedPasscodeTag),
castingPlayer.GetSupportsCommissionerGeneratedPasscode()));
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerPortTag), castingPlayer.GetPort()));
ReturnErrorOnFailure(tlvWriter.PutBytes(chip::TLV::ContextTag(kCastingPlayerInstanceNameTag),
(const uint8_t *) castingPlayer.GetInstanceName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class CastingStore : public chip::FabricTable::Delegate
kCastingPlayerEndpointServerListContainerTag,
kCastingPlayerEndpointServerClusterIdTag,

kCastingPlayerSupportsCommissionerGeneratedPasscodeTag,

kContextTagMaxNum = UINT8_MAX
};

Expand Down
4 changes: 2 additions & 2 deletions src/lib/dnssd/TxtFields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void GetPairingInstruction(const ByteSpan & value, char * pairingInstruction)

uint8_t GetCommissionerPasscode(const ByteSpan & value)
{
return MakeU8FromAsciiDecimal(value);
return MakeBoolFromAsciiDecimal(value);
}

Optional<System::Clock::Milliseconds32> GetRetryInterval(const ByteSpan & value)
Expand Down Expand Up @@ -256,7 +256,7 @@ void FillNodeDataFromTxt(const ByteSpan & key, const ByteSpan & val, DnssdNodeDa
nodeData.pairingHint = Internal::GetPairingHint(val);
break;
case TxtFieldKey::kCommissionerPasscode:
nodeData.commissionerPasscode = Internal::GetCommissionerPasscode(val);
nodeData.supportsCommissionerGeneratedPasscode = Internal::GetCommissionerPasscode(val);
break;
default:
break;
Expand Down
8 changes: 3 additions & 5 deletions src/lib/dnssd/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ struct DnssdNodeData
uint16_t productId = 0;
uint16_t pairingHint = 0;
uint8_t commissioningMode = 0;
uint8_t commissionerPasscode = 0;
bool supportsCommissionerGeneratedPasscode = false;
uint8_t rotatingId[kMaxRotatingIdLen] = {};
char instanceName[Commission::kInstanceNameMaxLength + 1] = {};
char deviceName[kMaxDeviceNameLen + 1] = {};
Expand Down Expand Up @@ -272,10 +272,8 @@ struct DnssdNodeData
ChipLogDetail(Discovery, "\tInstance Name: %s", instanceName);
}
ChipLogDetail(Discovery, "\tCommissioning Mode: %u", commissioningMode);
if (commissionerPasscode > 0)
{
ChipLogDetail(Discovery, "\tCommissioner Passcode: %u", commissionerPasscode);
}
ChipLogDetail(Discovery, "\tSupports Commissioner Generated Passcode: %s",
supportsCommissionerGeneratedPasscode ? "true" : "false");
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/lib/dnssd/tests/TestTxtFields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ bool NodeDataIsEmpty(const DiscoveredNodeData & node)
node.nodeData.pairingHint != 0 || node.resolutionData.mrpRetryIntervalIdle.HasValue() ||
node.resolutionData.mrpRetryIntervalActive.HasValue() || node.resolutionData.mrpRetryActiveThreshold.HasValue() ||
node.resolutionData.isICDOperatingAsLIT.HasValue() || node.resolutionData.supportsTcp ||
node.nodeData.commissionerPasscode != 0)
node.nodeData.supportsCommissionerGeneratedPasscode != 0)
{
return false;
}
Expand Down Expand Up @@ -360,12 +360,12 @@ void TestFillDiscoveredNodeDataFromTxt(nlTestSuite * inSuite, void * inContext)
filled.nodeData.commissioningMode = 0;
NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled));

// Commissioning mode
// Supports Commissioner Generated Passcode
strcpy(key, "CP");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData);
NL_TEST_ASSERT(inSuite, filled.nodeData.commissionerPasscode == 1);
filled.nodeData.commissionerPasscode = 0;
NL_TEST_ASSERT(inSuite, filled.nodeData.supportsCommissionerGeneratedPasscode == true);
filled.nodeData.supportsCommissionerGeneratedPasscode = false;
NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled));

// Device type
Expand Down

0 comments on commit 63c4709

Please sign in to comment.