Skip to content

Commit

Permalink
Merge branch 'master' into tbrm-te2-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marchemi authored Aug 23, 2024
2 parents 1b3fdcd + 010d982 commit bb69228
Show file tree
Hide file tree
Showing 61 changed files with 1,533 additions and 1,662 deletions.
3 changes: 2 additions & 1 deletion examples/fabric-admin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ fabrics.
For Linux host example:

```
./scripts/examples/gn_build_example.sh examples/fabric-admin out/debug/standalone 'import("//with_pw_rpc.gni")'
source scripts/activate.sh
./scripts/build/build_examples.py --target linux-x64-fabric-admin-rpc build
```

For Raspberry Pi 4 example:
Expand Down
8 changes: 4 additions & 4 deletions examples/fabric-admin/scripts/run_fabric_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEFAULT_ADMIN_CHOICES=(
"./fabric-admin"
"out/debug/standalone/fabric-admin"
"out/linux-x64-fabric-admin/fabric-admin"
"out/darwin-arm64-fabric-admin/fabric-admin"
"out/linux-x64-fabric-admin-rpc/fabric-admin"
"out/darwin-arm64-fabric-admin-rpc/fabric-admin"
)
DEFAULT_BRIDGE_CHOICES=(
"./fabric-bridge-app"
"out/debug/standalone/fabric-bridge-app"
"out/linux-x64-fabric-bridge-app/fabric-bridge-app"
"out/darwin-arm64-fabric-bridge-app/fabric-bridge-app"
"out/linux-x64-fabric-bridge-rpc/fabric-bridge-app"
"out/darwin-arm64-fabric-bridge-rpc/fabric-bridge-app"
)
FABRIC_ADMIN_LOG="/tmp/fabric_admin.log"
FABRIC_BRIDGE_APP_LOG="/tmp/fabric_bridge_app.log"
Expand Down
2 changes: 1 addition & 1 deletion examples/fabric-admin/scripts/stop_fabric_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ if [ ! -z "$fabric_bridge_app_pid" ]; then
fi

# Remove /tmp/chip_* files and directories
sudo rm -rf /tmp/chip_*
rm -rf /tmp/chip_*
echo "Removed /tmp/chip_* files and directories"
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@

// include the CHIPProjectConfig from config/standalone
#include <CHIPProjectConfig.h>

// Allows app options (ports) to be configured on launch of app
#define CHIP_DEVICE_ENABLE_PORT_PARAMS 1
3 changes: 2 additions & 1 deletion examples/fabric-bridge-app/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ defined:
### For Linux host example:

```
./scripts/examples/gn_build_example.sh examples/fabric-bridge-app/linux out/debug/standalone chip_config_network_layer_ble=false 'import("//with_pw_rpc.gni")'
source scripts/activate.sh
./scripts/build/build_examples.py --target linux-x64-fabric-bridge-rpc build
```

### For Raspberry Pi 4 example:
Expand Down
2 changes: 1 addition & 1 deletion examples/fabric-bridge-app/linux/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ chip_project_config_include = "<CHIPProjectAppConfig.h>"
chip_system_project_config_include = "<SystemProjectConfig.h>"

chip_project_config_include_dirs =
[ "${chip_root}/examples/bridge-app/bridge-common/include" ]
[ "${chip_root}/examples/fabric-bridge-app/fabric-bridge-common/include" ]
chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ]

matter_enable_tracing_support = true
4 changes: 2 additions & 2 deletions examples/rvc-app/linux/RvcAppCommandDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ void RvcAppCommandHandler::OnAddServiceAreaArea(Json::Value jsonValue)
if (jsonValue.isMember("LandmarkTag"))
{
DataModel::Nullable<Globals::RelativePositionTag> relativePositionTag = DataModel::NullNullable;
if (jsonValue.isMember("PositionTag"))
if (jsonValue.isMember("RelativePositionTag"))
{
relativePositionTag = Globals::RelativePositionTag(jsonValue["PositionTag"].asUInt());
relativePositionTag = Globals::RelativePositionTag(jsonValue["RelativePositionTag"].asUInt());
}

area.SetLandmarkInfo(Globals::LandmarkTag(jsonValue["LandmarkTag"].asUInt()), relativePositionTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class RvcServiceAreaDelegate : public Delegate
// command support
bool IsSetSelectedAreasAllowed(MutableCharSpan & statusText) override;

bool IsValidSelectAreasSet(const ServiceArea::Commands::SelectAreas::DecodableType & req,
ServiceArea::SelectAreasStatus & areaStatus, MutableCharSpan & statusText) override;
bool IsValidSelectAreasSet(const Span<const uint32_t> & selectedAreas, ServiceArea::SelectAreasStatus & areaStatus,
MutableCharSpan & statusText) override;

bool HandleSkipArea(uint32_t skippedArea, MutableCharSpan & skipStatusText) override;

Expand Down
9 changes: 4 additions & 5 deletions examples/rvc-app/rvc-common/rvc-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1438,9 +1438,8 @@ provisional cluster ServiceArea = 336 {
enum SelectAreasStatus : enum8 {
kSuccess = 0;
kUnsupportedArea = 1;
kDuplicatedAreas = 2;
kInvalidInMode = 3;
kInvalidSet = 4;
kInvalidInMode = 2;
kInvalidSet = 3;
}

enum SkipAreaStatus : enum8 {
Expand All @@ -1458,7 +1457,7 @@ provisional cluster ServiceArea = 336 {

struct LandmarkInfoStruct {
LandmarkTag landmarkTag = 0;
nullable RelativePositionTag positionTag = 1;
nullable RelativePositionTag relativePositionTag = 1;
}

struct AreaInfoStruct {
Expand All @@ -1469,7 +1468,7 @@ provisional cluster ServiceArea = 336 {
struct AreaStruct {
int32u areaID = 0;
nullable int32u mapID = 1;
AreaInfoStruct areaDesc = 2;
AreaInfoStruct areaInfo = 2;
}

struct MapStruct {
Expand Down
63 changes: 22 additions & 41 deletions examples/rvc-app/rvc-common/src/rvc-service-area-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,12 @@ bool RvcServiceAreaDelegate::IsSetSelectedAreasAllowed(MutableCharSpan & statusT
return (mIsSetSelectedAreasAllowedDeviceInstance->*mIsSetSelectedAreasAllowedCallback)(statusText);
};

bool RvcServiceAreaDelegate::IsValidSelectAreasSet(const Commands::SelectAreas::DecodableType & req, SelectAreasStatus & areaStatus,
bool RvcServiceAreaDelegate::IsValidSelectAreasSet(const Span<const uint32_t> & selectedAreas, SelectAreasStatus & areaStatus,
MutableCharSpan & statusText)
{
// if req is empty list return true.
if (selectedAreas.empty())
{
size_t reqSize;
if (req.newAreas.ComputeSize(&reqSize) != CHIP_NO_ERROR)
{
areaStatus = SelectAreasStatus::kInvalidSet; // todo Not sure this is the correct error to use here
CopyCharSpanToMutableCharSpan("error computing number of selected areas"_span, statusText);
return false;
}

if (reqSize == 0)
{
return true;
}
return true;
}

// If there is 1 or 0 supported maps, any combination of areas is valid.
Expand All @@ -139,42 +128,34 @@ bool RvcServiceAreaDelegate::IsValidSelectAreasSet(const Commands::SelectAreas::
}

// Check that all the requested areas are in the same map.
auto newAreasIter = req.newAreas.begin();
newAreasIter.Next();

AreaStructureWrapper tempArea;
uint32_t ignoredIndex;
if (!GetSupportedAreaById(newAreasIter.GetValue(), ignoredIndex, tempArea))
{
areaStatus = SelectAreasStatus::kUnsupportedArea;
CopyCharSpanToMutableCharSpan("unable to find selected area in supported areas"_span, statusText);
return false;
}

auto mapId = tempArea.mapID.Value(); // It is safe to call `.Value()` as we confirmed that there are at least 2 maps.

while (newAreasIter.Next())
{
if (!GetSupportedAreaById(newAreasIter.GetValue(), ignoredIndex, tempArea))
AreaStructureWrapper tempArea;
uint32_t ignoredIndex;
if (!GetSupportedAreaById(selectedAreas[0], ignoredIndex, tempArea))
{
areaStatus = SelectAreasStatus::kUnsupportedArea;
CopyCharSpanToMutableCharSpan("unable to find selected area in supported areas"_span, statusText);
return false;
}

if (tempArea.mapID.Value() != mapId)
auto mapId = tempArea.mapID.Value(); // It is safe to call `.Value()` as we confirmed that there are at least 2 maps.

for (const auto & areaId : selectedAreas.SubSpan(1))
{
areaStatus = SelectAreasStatus::kInvalidSet;
CopyCharSpanToMutableCharSpan("all selected areas must be in the same map"_span, statusText);
return false;
}
}
if (!GetSupportedAreaById(areaId, ignoredIndex, tempArea))
{
areaStatus = SelectAreasStatus::kUnsupportedArea;
CopyCharSpanToMutableCharSpan("unable to find selected area in supported areas"_span, statusText);
return false;
}

if (CHIP_NO_ERROR != newAreasIter.GetStatus())
{
areaStatus = SelectAreasStatus::kInvalidSet;
CopyCharSpanToMutableCharSpan("error processing new areas."_span, statusText);
return false;
if (tempArea.mapID.Value() != mapId)
{
areaStatus = SelectAreasStatus::kInvalidSet;
CopyCharSpanToMutableCharSpan("all selected areas must be in the same map"_span, statusText);
return false;
}
}
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ private CommandResponseHolder() {
Clusters.AccountLogin.Id,
Clusters.AccountLogin.Commands.GetSetupPIN.ID,
"{\"0\":\"20202021\"}");
setResponseValue(
Clusters.AccountLogin.Id,
Clusters.AccountLogin.Commands.Login.ID,
// 0 is for success, you can return 1 for failure
"{\"Status\":0}");
setResponseValue(
Clusters.AccountLogin.Id,
Clusters.AccountLogin.Commands.Logout.ID,
// 0 is for success, you can return 1 for failure
"{\"Status\":0}");
};

public static CommandResponseHolder getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.util.Log;
import com.example.contentapp.AttributeHolder;
import com.example.contentapp.CommandResponseHolder;
import com.example.contentapp.MainActivity;
import com.example.contentapp.matter.MatterAgentClient;
import com.matter.tv.app.api.Clusters;
import com.matter.tv.app.api.MatterIntentConstants;

public class MatterCommandReceiver extends BroadcastReceiver {
Expand Down Expand Up @@ -44,6 +46,21 @@ public void onReceive(Context context, Intent intent) {
.append(command)
.toString();
Log.d(TAG, message);

int pinCode =
Settings.Secure.getInt(context.getContentResolver(), "matter_pin_code", 20202021);
Log.d(TAG, "Retrieved pin code:" + pinCode);

CommandResponseHolder.getInstance()
.setResponseValue(
Clusters.AccountLogin.Id,
Clusters.AccountLogin.Commands.GetSetupPIN.ID,
"{\""
+ Clusters.AccountLogin.Commands.GetSetupPINResponse.Fields.SetupPIN
+ "\":\""
+ pinCode
+ "\"}");

String response =
CommandResponseHolder.getInstance().getCommandResponse(clusterId, commandId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,105 @@
#include <lib/core/DataModelTypes.h>

using namespace std;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::AccountLogin;
using Status = chip::Protocols::InteractionModel::Status;

namespace {

const auto loginTempAccountIdentifierFieldId =
to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kTempAccountIdentifier));
const auto loginSetupPINFieldId = to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kSetupPIN));
const auto loginNodeFieldId = to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kNode));
const auto logoutNodeFieldId = to_string(chip::to_underlying(AccountLogin::Commands::Logout::Fields::kNode));

string charSpanToString(const CharSpan & charSpan)
{
return { charSpan.data(), charSpan.size() };
}

std::string serializeLoginCommand(AccountLogin::Commands::Login::Type cmd)
{
return R"({")" + loginTempAccountIdentifierFieldId + R"(":")" + charSpanToString(cmd.tempAccountIdentifier) + R"(",)" + R"(")" +
loginSetupPINFieldId + R"(":")" + charSpanToString(cmd.setupPIN) + R"(",)" + R"(")" + loginNodeFieldId + R"(":")" +
to_string(cmd.node.Value()) + R"("})";
}

std::string serializeLogoutCommand(AccountLogin::Commands::Logout::Type cmd)
{
return R"({")" + logoutNodeFieldId + R"(":")" + to_string(cmd.node.Value()) + R"("})";
}

} // namespace

AccountLoginManager::AccountLoginManager(ContentAppCommandDelegate * commandDelegate, const char * setupPin) :
mCommandDelegate(commandDelegate)
{
CopyString(mSetupPin, sizeof(mSetupPin), setupPin);
}

bool AccountLoginManager::HandleLogin(const CharSpan & tempAccountIdentifier, const CharSpan & setupPin,
bool AccountLoginManager::HandleLogin(const CharSpan & tempAccountIdentifier, const CharSpan & setupPIN,
const chip::Optional<chip::NodeId> & nodeId)
{
ChipLogProgress(DeviceLayer, "AccountLoginManager::HandleLogin called for endpoint %d", mEndpointId);
string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size());
string setupPinString(setupPin.data(), setupPin.size());

if (strcmp(mSetupPin, setupPinString.c_str()) == 0)
if (mCommandDelegate == nullptr)
{
ChipLogProgress(Zcl, "AccountLoginManager::HandleLogin success");
return true;
ChipLogError(Zcl, "CommandDelegate not found");
return false;
}
else

if (tempAccountIdentifier.empty() || setupPIN.empty() || !nodeId.HasValue())
{
ChipLogProgress(Zcl, "AccountLoginManager::HandleLogin failed expected pin %s", mSetupPin);
ChipLogError(Zcl, "Invalid parameters");
return false;
}

Json::Value response;
bool commandHandled = true;
AccountLogin::Commands::Login::Type cmd = { tempAccountIdentifier, setupPIN, nodeId };

auto status = mCommandDelegate->InvokeCommand(mEndpointId, AccountLogin::Id, AccountLogin::Commands::Login::Id,
serializeLoginCommand(cmd), commandHandled, response);
if (status == Status::Success)
{
// Format status response to verify that response is non-failure.
status = mCommandDelegate->FormatStatusResponse(response);
}
ChipLogProgress(Zcl, "AccountLoginManager::HandleLogin command returned with status: %d", chip::to_underlying(status));
return status == chip::Protocols::InteractionModel::Status::Success;
}

bool AccountLoginManager::HandleLogout(const chip::Optional<chip::NodeId> & nodeId)
{
// TODO: Insert your code here to send logout request
return true;
ChipLogProgress(DeviceLayer, "AccountLoginManager::HandleLogout called for endpoint %d", mEndpointId);

if (mCommandDelegate == nullptr)
{
ChipLogError(Zcl, "CommandDelegate not found");
return false;
}

if (!nodeId.HasValue())
{
ChipLogError(Zcl, "Invalid parameters");
return false;
}

Json::Value response;
bool commandHandled = true;
AccountLogin::Commands::Logout::Type cmd = { nodeId };

auto status = mCommandDelegate->InvokeCommand(mEndpointId, AccountLogin::Id, AccountLogin::Commands::Logout::Id,
serializeLogoutCommand(cmd), commandHandled, response);

if (status == Status::Success)
{
// Format status response to verify that response is non-failure.
status = mCommandDelegate->FormatStatusResponse(response);
}
ChipLogProgress(Zcl, "AccountLoginManager::HandleLogout command returned with status: %d", chip::to_underlying(status));
return status == chip::Protocols::InteractionModel::Status::Success;
}

void AccountLoginManager::HandleGetSetupPin(CommandResponseHelper<GetSetupPINResponse> & helper,
Expand Down
2 changes: 1 addition & 1 deletion examples/tv-app/android/java/AppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void refreshConnectedClientsAcl(uint16_t vendorId, uint16_t productId, ContentAp

for (const auto & allowedVendor : app->GetApplicationBasicDelegate()->GetAllowedVendorList())
{
std::set<NodeId> tempNodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForAllowVendorId(allowedVendor);
std::set<NodeId> tempNodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForAllowedVendorId(allowedVendor);

nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end());
}
Expand Down
Loading

0 comments on commit bb69228

Please sign in to comment.