Skip to content

Commit

Permalink
Addressed comments by andy31415 and tcarmelveilleux
Browse files Browse the repository at this point in the history
  • Loading branch information
pgregorr-amazon committed May 16, 2024
1 parent 82b0cb1 commit 0b428d5
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ JNI_METHOD(jobject, verifyOrEstablishConnection)
"MatterCastingPlayer-JNI::verifyOrEstablishConnection() ConnectCallback() Connected to Casting Player "
"with device ID: %s",
playerPtr->GetId());
// The Java jSuccessCallback is expecting a Void v callback parameter which translates to a nullptr. When calling the
// Java method from C++ via JNI, passing nullptr is equivalent to passing a Void object in Java.
MatterCastingPlayerJNIMgr().mConnectionSuccessHandler.Handle(nullptr);
}
else
Expand All @@ -118,6 +120,7 @@ JNI_METHOD(jobject, verifyOrEstablishConnection)
matter::casting::core::ConnectionCallbacks connectionCallbacks;
connectionCallbacks.mOnConnectionComplete = connectCallback;

// TODO: Verify why commissioningWindowTimeoutSec is a "unsigned long long int" type. Seems too big.
castingPlayer->VerifyOrEstablishConnection(connectionCallbacks,
static_cast<unsigned long long int>(commissioningWindowTimeoutSec), idOptions);
return support::convertMatterErrorFromCppToJava(CHIP_NO_ERROR);
Expand Down
15 changes: 9 additions & 6 deletions examples/tv-casting-app/linux/simple-app-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
const uint16_t kDesiredEndpointVendorId = 65521;

DiscoveryDelegateImpl * DiscoveryDelegateImpl::_discoveryDelegateImpl = nullptr;
bool awaitingCommissionerPasscodeInput = false;
bool gAwaitingCommissionerPasscodeInput = false;
std::shared_ptr<matter::casting::core::CastingPlayer> targetCastingPlayer;

DiscoveryDelegateImpl * DiscoveryDelegateImpl::GetInstance()
Expand Down Expand Up @@ -206,13 +206,16 @@ CHIP_ERROR InitCommissionableDataProvider(LinuxCommissionableDataProvider & prov
// properly to the commissioner later, PASE will succeed.
}

// Default to minimum PBKDF iterations
// Default to the minimum PBKDF iterations (1000) for this example implementation. For TV devices and TV casting app production
// implementations, you should use a higher number of PBKDF iterations to enhance security. The default minimum iterations are
// not sufficient against brute-force and rainbow table attacks.
uint32_t spake2pIterationCount = chip::Crypto::kSpake2p_Min_PBKDF_Iterations;
if (options.spake2pIterations != 0)
{
spake2pIterationCount = options.spake2pIterations;
}
ChipLogError(Support, "PASE PBKDF iterations set to %u", static_cast<unsigned>(spake2pIterationCount));
ChipLogError(Support, "PASE PBKDF iterations set to %u. Should be set higher for a production app implementation.",
static_cast<unsigned>(spake2pIterationCount));

return provider.Init(options.spake2pVerifier, options.spake2pSalt, spake2pIterationCount, setupPasscode,
options.payload.discriminator.GetLongValue());
Expand Down Expand Up @@ -278,7 +281,7 @@ void CommissionerDeclarationCallback(const chip::Transport::PeerAddress & source
ChipLogProgress(AppServer, "Input 1245678 to use the defualt passcode.");
ChipLogProgress(AppServer, "Example: cast setcommissionerpasscode 12345678");
ChipLogProgress(AppServer, "---- Awaiting user input ----");
awaitingCommissionerPasscodeInput = true;
gAwaitingCommissionerPasscodeInput = true;
}
}

Expand Down Expand Up @@ -375,10 +378,10 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
}
char * eptr;
uint32_t passcode = (uint32_t) strtol(argv[1], &eptr, 10);
if (awaitingCommissionerPasscodeInput)
if (gAwaitingCommissionerPasscodeInput)
{
ChipLogProgress(AppServer, "CommandHandler() setcommissionerpasscode user enterd passcode: %d", passcode);
awaitingCommissionerPasscodeInput = false;
gAwaitingCommissionerPasscodeInput = false;

// Per connectedhomeip/examples/platform/linux/LinuxCommissionableDataProvider.h: We don't support overriding the
// passcode post-init (it is deprecated!). Therefore we need to initiate a new provider with the user entered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ CHIP_ERROR CastingApp::UpdateCommissionableDataProvider(chip::DeviceLayer::Commi
{
ChipLogProgress(Discovery, "CastingApp::UpdateCommissionableDataProvider()");
chip::DeviceLayer::SetCommissionableDataProvider(commissionableDataProvider);
CHIP_ERROR err = CHIP_NO_ERROR;
err = mAppParameters->SetCommissionableDataProvider(commissionableDataProvider);
return err;
return mAppParameters->SetCommissionableDataProvider(commissionableDataProvider);
}

void ReconnectHandler(CHIP_ERROR err, matter::casting::core::CastingPlayer * castingPlayer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace core {

CastingPlayer * CastingPlayer::mTargetCastingPlayer = nullptr;

// TODO: Verify why commissioningWindowTimeoutSec is a "unsigned long long int" type. Seems too big.
void CastingPlayer::VerifyOrEstablishConnection(ConnectionCallbacks connectionCallbacks,
unsigned long long int commissioningWindowTimeoutSec,
IdentificationDeclarationOptions idOptions)
Expand Down Expand Up @@ -225,12 +226,16 @@ void CastingPlayer::ContinueConnecting(ConnectionCallbacks connectionCallbacks,

void CastingPlayer::resetState(CHIP_ERROR err)
{
ChipLogProgress(AppServer, "CastingPlayer::resetState()");
support::ChipDeviceEventHandler::SetUdcStatus(false);
mConnectionState = CASTING_PLAYER_NOT_CONNECTED;
mCommissioningWindowTimeoutSec = kCommissioningWindowTimeoutSec;
mTargetCastingPlayer = nullptr;
mOnCompleted(err, nullptr);
mOnCompleted = nullptr;
if (mOnCompleted)
{
mOnCompleted(err, nullptr);
mOnCompleted = nullptr;
}
}

void CastingPlayer::Disconnect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>
ConnectCallback mOnCompleted = {};

/**
* @brief resets this CastingPlayer's state and calls mOnCompleted with the CHIP_ERROR.
* @brief resets this CastingPlayer's state and calls mOnCompleted with the CHIP_ERROR. Also, after calling mOnCompleted, it
* clears mOnCompleted by setting it to a nullptr.
*/
void resetState(CHIP_ERROR err);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ void CommissionerDeclarationHandler::SetCommissionerDeclarationCallback(
mCmmissionerDeclarationCallback_ = std::move(callback);
}

}; // namespace core
}; // namespace casting
}; // namespace matter
} // namespace core
} // namespace casting
} // namespace matter
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ class CommissionerDeclarationHandler : public chip::Protocols::UserDirectedCommi
~CommissionerDeclarationHandler() {}
};

}; // namespace core
}; // namespace casting
}; // namespace matter
} // namespace core
} // namespace casting
} // namespace matter
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ using ConnectCallback = std::function<void(CHIP_ERROR err, CastingPlayer * casti
* @param[in] source The source of the Commissioner Declaration message.
* @param[in] cd The Commissioner Declaration message.
*/
using CommissionerDeclarationCallback = std::function<void(const chip::Transport::PeerAddress & source,
chip::Protocols::UserDirectedCommissioning::CommissionerDeclaration cd)>;
using CommissionerDeclarationCallback = std::function<void(
const chip::Transport::PeerAddress & source, const chip::Protocols::UserDirectedCommissioning::CommissionerDeclaration cd)>;

/**
* @brief A container class for User Directed Commissioning (UDC) callbacks.
* @brief A container struct for User Directed Commissioning (UDC) callbacks.
*/
class ConnectionCallbacks
struct ConnectionCallbacks
{
public:
/**
Expand All @@ -57,6 +57,6 @@ class ConnectionCallbacks
CommissionerDeclarationCallback mCommissionerDeclarationCallback = nullptr;
};

}; // namespace core
}; // namespace casting
}; // namespace matter
} // namespace core
} // namespace casting
} // namespace matter

0 comments on commit 0b428d5

Please sign in to comment.