Skip to content

Commit

Permalink
Merge branch 'master' into idm-4.2-troubleshoot
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-marquez-csa authored May 22, 2024
2 parents 1b265c0 + 78b6ae5 commit d92f839
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 25 deletions.
9 changes: 9 additions & 0 deletions examples/tv-app/android/java/MyUserPrompter-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ bool JNIMyUserPrompter::DisplaysPasscodeAndQRCode()
return false;
}

/**
* Called to prompt the user for consent to allow the app commissioneeName/vendorId/productId to be installed.
* For example "[commissioneeName] is requesting permission to install app to this TV, approve?"
*/
void JNIMyUserPrompter::PromptForAppInstallOKPermission(uint16_t vendorId, uint16_t productId, const char * commissioneeName)
{
ChipLogError(Zcl, "JNIMyUserPrompter::PromptForAppInstallOKPermission Needs Implementation");
}

/**
* Called to display the given setup passcode to the user,
* for commissioning the given commissioneeName with the given vendorId and productId,
Expand Down
1 change: 1 addition & 0 deletions examples/tv-app/android/java/MyUserPrompter-JNI.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class JNIMyUserPrompter : public UserPrompter
void PromptForCommissionOKPermission(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override;
void PromptForCommissionPasscode(uint16_t vendorId, uint16_t productId, const char * commissioneeName, uint16_t pairingHint,
const char * pairingInstruction) override;
void PromptForAppInstallOKPermission(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override;
void HidePromptsOnCancel(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override;
bool DisplaysPasscodeAndQRCode() override;
void PromptWithCommissionerPasscode(uint16_t vendorId, uint16_t productId, const char * commissioneeName, uint32_t passcode,
Expand Down
5 changes: 5 additions & 0 deletions examples/tv-app/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ id):
$ app add 9050 (vendor id 9050)
$ app remove 1

You can also install or uninstall the app by using commands:

$ app install 65521 32768
$ app uninstall 65521 32768

As an app platform, local apps can be used to facilitate commissioning using
their AccountLogin clusters. The dummy apps have hardcoded setup codes - on a
real device, these apps would communicate with a cloud service to obtain the
Expand Down
17 changes: 10 additions & 7 deletions examples/tv-app/tv-common/include/AppTv.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class DLL_EXPORT ContentAppImpl : public ContentApp
KeypadInputDelegate * GetKeypadInputDelegate() override { return &mKeypadInputDelegate; };
MediaPlaybackDelegate * GetMediaPlaybackDelegate() override { return &mMediaPlaybackDelegate; };
TargetNavigatorDelegate * GetTargetNavigatorDelegate() override { return &mTargetNavigatorDelegate; };
bool MatchesPidVid(uint16_t productId, uint16_t vendorId)
{
return vendorId == mApplicationBasicDelegate.HandleGetVendorId() &&
productId == mApplicationBasicDelegate.HandleGetProductId();
}

protected:
ApplicationBasicManager mApplicationBasicDelegate;
Expand Down Expand Up @@ -138,15 +143,13 @@ class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
uint16_t productId) override;

void AddAdminVendorId(uint16_t vendorId);
// Add the app to the list of mContentApps
void InstallContentApp(uint16_t vendorId, uint16_t productId);
// Remove the app from the list of mContentApps
bool UninstallContentApp(uint16_t vendorId, uint16_t productId);

protected:
ContentAppImpl mContentApps[APP_LIBRARY_SIZE] = {
ContentAppImpl("Vendor1", 1, "exampleid", 11, "Version1", "34567890"),
ContentAppImpl("Vendor2", 65521, "exampleString", 32768, "Version2", "20202021"),
ContentAppImpl("Vendor3", 9050, "App3", 22, "Version3", "20202021"),
ContentAppImpl("TestSuiteVendor", 1111, "applicationId", 22, "v2", "20202021")
};

std::vector<std::unique_ptr<ContentAppImpl>> mContentApps;
std::vector<uint16_t> mAdminVendorIds{};
};

Expand Down
49 changes: 49 additions & 0 deletions examples/tv-app/tv-common/shell/AppTvShellCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,55 @@ static CHIP_ERROR AppPlatformHandler(int argc, char ** argv)

return CHIP_NO_ERROR;
}
else if (strcmp(argv[0], "install") == 0)
{
if (argc < 2)
{
return PrintAllCommands();
}
char * eptr;

uint16_t vid = (uint16_t) strtol(argv[1], &eptr, 10);
uint16_t pid = 0;
if (argc >= 3)
{
pid = (uint16_t) strtol(argv[2], &eptr, 10);
}
ContentAppFactoryImpl * factory = GetContentAppFactoryImpl();
factory->InstallContentApp(vid, pid);

ChipLogProgress(DeviceLayer, "installed an app");

return CHIP_NO_ERROR;
}
else if (strcmp(argv[0], "uninstall") == 0)
{
if (argc < 2)
{
return PrintAllCommands();
}
char * eptr;

uint16_t vid = (uint16_t) strtol(argv[1], &eptr, 10);
uint16_t pid = 0;
if (argc >= 3)
{
pid = (uint16_t) strtol(argv[2], &eptr, 10);
}
ContentAppFactoryImpl * factory = GetContentAppFactoryImpl();
bool isAppUninstalled = factory->UninstallContentApp(vid, pid);

if (isAppUninstalled)
{
ChipLogProgress(DeviceLayer, "uninstalled an app");
}
else
{
ChipLogProgress(DeviceLayer, "app not found.");
}

return CHIP_NO_ERROR;
}
else if (strcmp(argv[0], "add") == 0)
{
if (argc < 2)
Expand Down
93 changes: 87 additions & 6 deletions examples/tv-app/tv-common/src/AppTv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ class MyUserPrompter : public UserPrompter

// tv should override this with a dialog prompt
inline void PromptCommissioningFailed(const char * commissioneeName, CHIP_ERROR error) override { return; }

// tv should override this with a dialog prompt
inline void PromptForAppInstallOKPermission(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override
{
return;
}
};

MyUserPrompter gMyUserPrompter;
Expand Down Expand Up @@ -146,6 +152,16 @@ class MyPasscodeService : public PasscodeService
};
MyPasscodeService gMyPasscodeService;

class MyAppInstallationService : public AppInstallationService
{
bool LookupTargetContentApp(uint16_t vendorId, uint16_t productId) override
{
return ContentAppPlatform::GetInstance().LoadContentAppByClient(vendorId, productId) != nullptr;
}
};

MyAppInstallationService gMyAppInstallationService;

class MyPostCommissioningListener : public PostCommissioningListener
{
void CommissioningCompleted(uint16_t vendorId, uint16_t productId, NodeId nodeId, Messaging::ExchangeManager & exchangeMgr,
Expand Down Expand Up @@ -527,19 +543,23 @@ ContentApp * ContentAppFactoryImpl::LoadContentApp(const CatalogVendorApp & vend
{
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl: LoadContentAppByAppId catalogVendorId=%d applicationId=%s ",
vendorApp.catalogVendorId, vendorApp.applicationId);
int index = 0;

for (size_t i = 0; i < ArraySize(mContentApps); ++i)
for (auto & contentApp : mContentApps)
{
auto & app = mContentApps[i];

ChipLogProgress(DeviceLayer, " Looking next=%s ", app.GetApplicationBasicDelegate()->GetCatalogVendorApp()->applicationId);
if (app.GetApplicationBasicDelegate()->GetCatalogVendorApp()->Matches(vendorApp))
auto app = contentApp.get();

ChipLogProgress(DeviceLayer, " Looking next=%s ", app->GetApplicationBasicDelegate()->GetCatalogVendorApp()->applicationId);
if (app->GetApplicationBasicDelegate()->GetCatalogVendorApp()->Matches(vendorApp))
{
ContentAppPlatform::GetInstance().AddContentApp(&app, &contentAppEndpoint, Span<DataVersion>(gDataVersions[i]),
ContentAppPlatform::GetInstance().AddContentApp(app, &contentAppEndpoint, Span<DataVersion>(gDataVersions[index]),
Span<const EmberAfDeviceType>(gContentAppDeviceType));
return &app;
return app;
}
index++;
}

ChipLogProgress(DeviceLayer, "LoadContentAppByAppId NOT FOUND catalogVendorId=%d applicationId=%s ", vendorApp.catalogVendorId,
vendorApp.applicationId);

Expand All @@ -551,6 +571,62 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId)
mAdminVendorIds.push_back(vendorId);
}

void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t productId)
{
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl: InstallContentApp vendorId=%d productId=%d ", vendorId, productId);
if (vendorId == 1 && productId == 11)
{
mContentApps.emplace_back(
std::make_unique<ContentAppImpl>("Vendor1", vendorId, "exampleid", productId, "Version1", "34567890"));
}
else if (vendorId == 65521 && productId == 32768)
{
mContentApps.emplace_back(
std::make_unique<ContentAppImpl>("Vendor2", vendorId, "exampleString", productId, "Version2", "20202021"));
}
else if (vendorId == 9050 && productId == 22)
{
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("Vendor3", vendorId, "App3", productId, "Version3", "20202021"));
}
else if (vendorId == 1111 && productId == 22)
{
mContentApps.emplace_back(
std::make_unique<ContentAppImpl>("TestSuiteVendor", vendorId, "applicationId", productId, "v2", "20202021"));
}
else
{
mContentApps.emplace_back(
std::make_unique<ContentAppImpl>("NewAppVendor", vendorId, "newAppApplicationId", productId, "v2", "20202021"));
}
}

bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t productId)
{
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl: UninstallContentApp vendorId=%d productId=%d ", vendorId, productId);

int index = 0;
for (auto & contentApp : mContentApps)
{

auto app = contentApp.get();

ChipLogProgress(DeviceLayer, "Looking next vid=%d pid=%d", app->GetApplicationBasicDelegate()->HandleGetVendorId(),
app->GetApplicationBasicDelegate()->HandleGetProductId());

if (app->MatchesPidVid(productId, vendorId))
{
ChipLogProgress(DeviceLayer, "Found an app vid=%d pid=%d. Uninstalling it.",
app->GetApplicationBasicDelegate()->HandleGetVendorId(),
app->GetApplicationBasicDelegate()->HandleGetProductId());
mContentApps.erase(mContentApps.begin() + index);
return true;
}

index++;
}
return false;
}

Access::Privilege ContentAppFactoryImpl::GetVendorPrivilege(uint16_t vendorId)
{
for (size_t i = 0; i < mAdminVendorIds.size(); ++i)
Expand Down Expand Up @@ -607,6 +683,10 @@ CHIP_ERROR AppTvInit()
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
ContentAppPlatform::GetInstance().SetupAppPlatform();
ContentAppPlatform::GetInstance().SetContentAppFactory(&gFactory);
gFactory.InstallContentApp((uint16_t) 1, (uint16_t) 11);
gFactory.InstallContentApp((uint16_t) 65521, (uint16_t) 32768);
gFactory.InstallContentApp((uint16_t) 9050, (uint16_t) 22);
gFactory.InstallContentApp((uint16_t) 1111, (uint16_t) 22);
uint16_t value;
if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(value) != CHIP_NO_ERROR)
{
Expand All @@ -623,6 +703,7 @@ CHIP_ERROR AppTvInit()
if (cdc != nullptr)
{
cdc->SetPasscodeService(&gMyPasscodeService);
cdc->SetAppInstallationService(&gMyAppInstallationService);
cdc->SetUserPrompter(&gMyUserPrompter);
cdc->SetPostCommissioningListener(&gMyPostCommissioningListener);
}
Expand Down
32 changes: 21 additions & 11 deletions src/app/tests/suites/certification/Test_TC_OPCREDS_3_7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ tests:
saveAs: TH1_Fabric_Index

- label:
"Step 3.2: TH1 does a non-fabric-filtered read of the Fabrics
attribute from the Node Operational Credentials cluster. Save the
FabricIndex for TH1 as TH1_Fabric_Index for future use."
"Step 3.2: TH1 does a fabric-filtered read of the Fabrics attribute
from the Node Operational Credentials cluster. Save the FabricIndex
for TH1 as TH1_Fabric_Index for future use."
identity: "alpha"
command: "readAttribute"
cluster: "Operational Credentials"
attribute: "Fabrics"
fabricFiltered: false
fabricFiltered: true
response:
value: [{ "FabricIndex": TH1_Fabric_Index, "Label": "" }]
constraints:
Expand Down Expand Up @@ -237,20 +237,30 @@ tests:

# verification: ""
- label:
"Step 13: TH2 does a non-fabric-filtered read of the Fabrics attribute
"Step 13a: TH1 does a fabric-filtered read of the Fabrics attribute
from the Node Operational Credentials cluster"
nodeId: 0x43211234
command: "readAttribute"
cluster: "Operational Credentials"
attribute: "Fabrics"
fabricFiltered: true
response:
value: [{ "FabricIndex": TH1_Fabric_Index, "Label": "" }]
constraints:
type: list

# verification: ""
- label:
"Step 13b: TH2 does a fabric-filtered read of the Fabrics attribute
from the Node Operational Credentials cluster"
identity: "beta"
nodeId: 0x43211234
command: "readAttribute"
cluster: "Operational Credentials"
attribute: "Fabrics"
fabricFiltered: false
fabricFiltered: true
response:
value:
[
{ "FabricIndex": TH1_Fabric_Index, "Label": "" },
{ "FabricIndex": TH2_Fabric_Index, "Label": "" },
]
value: [{ "FabricIndex": TH2_Fabric_Index, "Label": "" }]
constraints:
type: list

Expand Down
30 changes: 30 additions & 0 deletions src/controller/CommissionerDiscoveryController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,34 @@ void CommissionerDiscoveryController::InternalOk()
ChipLogError(AppServer, "UX InternalOk: could not find instance=%s", mCurrentInstance);
return;
}

if (mAppInstallationService == nullptr)
{
ChipLogError(AppServer, "UX InternalOk: no app installation service");
return;
}

if (!mAppInstallationService->LookupTargetContentApp(client->GetVendorId(), client->GetProductId()))
{
ChipLogDetail(AppServer, "UX InternalOk: app not installed.");

// notify client that app will be installed
CommissionerDeclaration cd;
cd.SetErrorCode(CommissionerDeclaration::CdError::kAppInstallConsentPending);
mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));

// dialog
ChipLogDetail(Controller, "------PROMPT USER: %s is requesting to install app on this TV. vendorId=%d, productId=%d",
client->GetDeviceName(), client->GetVendorId(), client->GetProductId());

if (mUserPrompter != nullptr)
{
mUserPrompter->PromptForAppInstallOKPermission(client->GetVendorId(), client->GetProductId(), client->GetDeviceName());
}
ChipLogDetail(Controller, "------Via Shell Enter: app install <pid> <vid>");
return;
}

if (client->GetUDCClientProcessingState() != UDCClientProcessingState::kPromptingUser)
{
ChipLogError(AppServer, "UX InternalOk: invalid state for ok");
Expand All @@ -244,6 +272,7 @@ void CommissionerDiscoveryController::InternalOk()
CharSpan rotatingIdSpan(rotatingIdBuffer, 2 * rotatingIdLength);

uint8_t targetAppCount = client->GetNumTargetAppInfos();

if (targetAppCount > 0)
{
ChipLogDetail(AppServer, "UX InternalOk: checking for each target app specified");
Expand Down Expand Up @@ -583,6 +612,7 @@ void CommissionerDiscoveryController::Cancel()
}
client->SetUDCClientProcessingState(UDCClientProcessingState::kUserDeclined);
mPendingConsent = false;
ResetState();
}

void CommissionerDiscoveryController::CommissioningSucceeded(uint16_t vendorId, uint16_t productId, NodeId nodeId,
Expand Down
Loading

0 comments on commit d92f839

Please sign in to comment.