Skip to content

Commit a210940

Browse files
authored
Merge branch 'master' into feature/fix-invalid-pid-vid
2 parents adbaa3f + daa2a57 commit a210940

File tree

51 files changed

+1416
-1188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1416
-1188
lines changed

examples/fabric-admin/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ fabrics.
1414
For Linux host example:
1515

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

2021
For Raspberry Pi 4 example:

examples/fabric-admin/scripts/run_fabric_sync.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
77
DEFAULT_ADMIN_CHOICES=(
88
"./fabric-admin"
99
"out/debug/standalone/fabric-admin"
10-
"out/linux-x64-fabric-admin/fabric-admin"
11-
"out/darwin-arm64-fabric-admin/fabric-admin"
10+
"out/linux-x64-fabric-admin-rpc/fabric-admin"
11+
"out/darwin-arm64-fabric-admin-rpc/fabric-admin"
1212
)
1313
DEFAULT_BRIDGE_CHOICES=(
1414
"./fabric-bridge-app"
1515
"out/debug/standalone/fabric-bridge-app"
16-
"out/linux-x64-fabric-bridge-app/fabric-bridge-app"
17-
"out/darwin-arm64-fabric-bridge-app/fabric-bridge-app"
16+
"out/linux-x64-fabric-bridge-rpc/fabric-bridge-app"
17+
"out/darwin-arm64-fabric-bridge-rpc/fabric-bridge-app"
1818
)
1919
FABRIC_ADMIN_LOG="/tmp/fabric_admin.log"
2020
FABRIC_BRIDGE_APP_LOG="/tmp/fabric_bridge_app.log"

examples/fabric-admin/scripts/stop_fabric_sync.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ if [ ! -z "$fabric_bridge_app_pid" ]; then
2020
fi
2121

2222
# Remove /tmp/chip_* files and directories
23-
sudo rm -rf /tmp/chip_*
23+
rm -rf /tmp/chip_*
2424
echo "Removed /tmp/chip_* files and directories"

examples/fabric-bridge-app/fabric-bridge-common/include/CHIPProjectAppConfig.h

+3
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@
3232

3333
// include the CHIPProjectConfig from config/standalone
3434
#include <CHIPProjectConfig.h>
35+
36+
// Allows app options (ports) to be configured on launch of app
37+
#define CHIP_DEVICE_ENABLE_PORT_PARAMS 1

examples/fabric-bridge-app/linux/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ defined:
9191
### For Linux host example:
9292

9393
```
94-
./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")'
94+
source scripts/activate.sh
95+
./scripts/build/build_examples.py --target linux-x64-fabric-bridge-rpc build
9596
```
9697

9798
### For Raspberry Pi 4 example:

examples/fabric-bridge-app/linux/args.gni

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ chip_project_config_include = "<CHIPProjectAppConfig.h>"
2121
chip_system_project_config_include = "<SystemProjectConfig.h>"
2222

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

2727
matter_enable_tracing_support = true

examples/rvc-app/linux/RvcAppCommandDelegate.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ void RvcAppCommandHandler::OnAddServiceAreaArea(Json::Value jsonValue)
216216
if (jsonValue.isMember("LandmarkTag"))
217217
{
218218
DataModel::Nullable<Globals::RelativePositionTag> relativePositionTag = DataModel::NullNullable;
219-
if (jsonValue.isMember("PositionTag"))
219+
if (jsonValue.isMember("RelativePositionTag"))
220220
{
221-
relativePositionTag = Globals::RelativePositionTag(jsonValue["PositionTag"].asUInt());
221+
relativePositionTag = Globals::RelativePositionTag(jsonValue["RelativePositionTag"].asUInt());
222222
}
223223

224224
area.SetLandmarkInfo(Globals::LandmarkTag(jsonValue["LandmarkTag"].asUInt()), relativePositionTag);

examples/rvc-app/rvc-common/rvc-app.matter

+2-2
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ provisional cluster ServiceArea = 336 {
14581458

14591459
struct LandmarkInfoStruct {
14601460
LandmarkTag landmarkTag = 0;
1461-
nullable RelativePositionTag positionTag = 1;
1461+
nullable RelativePositionTag relativePositionTag = 1;
14621462
}
14631463

14641464
struct AreaInfoStruct {
@@ -1469,7 +1469,7 @@ provisional cluster ServiceArea = 336 {
14691469
struct AreaStruct {
14701470
int32u areaID = 0;
14711471
nullable int32u mapID = 1;
1472-
AreaInfoStruct areaDesc = 2;
1472+
AreaInfoStruct areaInfo = 2;
14731473
}
14741474

14751475
struct MapStruct {

examples/tv-app/android/App/content-app/src/main/java/com/example/contentapp/CommandResponseHolder.java

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ private CommandResponseHolder() {
3131
Clusters.AccountLogin.Id,
3232
Clusters.AccountLogin.Commands.GetSetupPIN.ID,
3333
"{\"0\":\"20202021\"}");
34+
setResponseValue(
35+
Clusters.AccountLogin.Id,
36+
Clusters.AccountLogin.Commands.Login.ID,
37+
// 0 is for success, you can return 1 for failure
38+
"{\"Status\":0}");
39+
setResponseValue(
40+
Clusters.AccountLogin.Id,
41+
Clusters.AccountLogin.Commands.Logout.ID,
42+
// 0 is for success, you can return 1 for failure
43+
"{\"Status\":0}");
3444
};
3545

3646
public static CommandResponseHolder getInstance() {

examples/tv-app/android/App/content-app/src/main/java/com/example/contentapp/receiver/MatterCommandReceiver.java

+17
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import android.content.BroadcastReceiver;
55
import android.content.Context;
66
import android.content.Intent;
7+
import android.provider.Settings;
78
import android.util.Log;
89
import com.example.contentapp.AttributeHolder;
910
import com.example.contentapp.CommandResponseHolder;
1011
import com.example.contentapp.MainActivity;
1112
import com.example.contentapp.matter.MatterAgentClient;
13+
import com.matter.tv.app.api.Clusters;
1214
import com.matter.tv.app.api.MatterIntentConstants;
1315

1416
public class MatterCommandReceiver extends BroadcastReceiver {
@@ -44,6 +46,21 @@ public void onReceive(Context context, Intent intent) {
4446
.append(command)
4547
.toString();
4648
Log.d(TAG, message);
49+
50+
int pinCode =
51+
Settings.Secure.getInt(context.getContentResolver(), "matter_pin_code", 20202021);
52+
Log.d(TAG, "Retrieved pin code:" + pinCode);
53+
54+
CommandResponseHolder.getInstance()
55+
.setResponseValue(
56+
Clusters.AccountLogin.Id,
57+
Clusters.AccountLogin.Commands.GetSetupPIN.ID,
58+
"{\""
59+
+ Clusters.AccountLogin.Commands.GetSetupPINResponse.Fields.SetupPIN
60+
+ "\":\""
61+
+ pinCode
62+
+ "\"}");
63+
4764
String response =
4865
CommandResponseHolder.getInstance().getCommandResponse(clusterId, commandId);
4966

examples/tv-app/android/include/account-login/AccountLoginManager.cpp

+77-10
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,105 @@
2424
#include <lib/core/DataModelTypes.h>
2525

2626
using namespace std;
27+
using namespace chip::app::Clusters;
2728
using namespace chip::app::Clusters::AccountLogin;
2829
using Status = chip::Protocols::InteractionModel::Status;
2930

31+
namespace {
32+
33+
const auto loginTempAccountIdentifierFieldId =
34+
to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kTempAccountIdentifier));
35+
const auto loginSetupPINFieldId = to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kSetupPIN));
36+
const auto loginNodeFieldId = to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kNode));
37+
const auto logoutNodeFieldId = to_string(chip::to_underlying(AccountLogin::Commands::Logout::Fields::kNode));
38+
39+
string charSpanToString(const CharSpan & charSpan)
40+
{
41+
return { charSpan.data(), charSpan.size() };
42+
}
43+
44+
std::string serializeLoginCommand(AccountLogin::Commands::Login::Type cmd)
45+
{
46+
return R"({")" + loginTempAccountIdentifierFieldId + R"(":")" + charSpanToString(cmd.tempAccountIdentifier) + R"(",)" + R"(")" +
47+
loginSetupPINFieldId + R"(":")" + charSpanToString(cmd.setupPIN) + R"(",)" + R"(")" + loginNodeFieldId + R"(":")" +
48+
to_string(cmd.node.Value()) + R"("})";
49+
}
50+
51+
std::string serializeLogoutCommand(AccountLogin::Commands::Logout::Type cmd)
52+
{
53+
return R"({")" + logoutNodeFieldId + R"(":")" + to_string(cmd.node.Value()) + R"("})";
54+
}
55+
56+
} // namespace
57+
3058
AccountLoginManager::AccountLoginManager(ContentAppCommandDelegate * commandDelegate, const char * setupPin) :
3159
mCommandDelegate(commandDelegate)
3260
{
3361
CopyString(mSetupPin, sizeof(mSetupPin), setupPin);
3462
}
3563

36-
bool AccountLoginManager::HandleLogin(const CharSpan & tempAccountIdentifier, const CharSpan & setupPin,
64+
bool AccountLoginManager::HandleLogin(const CharSpan & tempAccountIdentifier, const CharSpan & setupPIN,
3765
const chip::Optional<chip::NodeId> & nodeId)
3866
{
3967
ChipLogProgress(DeviceLayer, "AccountLoginManager::HandleLogin called for endpoint %d", mEndpointId);
40-
string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size());
41-
string setupPinString(setupPin.data(), setupPin.size());
4268

43-
if (strcmp(mSetupPin, setupPinString.c_str()) == 0)
69+
if (mCommandDelegate == nullptr)
4470
{
45-
ChipLogProgress(Zcl, "AccountLoginManager::HandleLogin success");
46-
return true;
71+
ChipLogError(Zcl, "CommandDelegate not found");
72+
return false;
4773
}
48-
else
74+
75+
if (tempAccountIdentifier.empty() || setupPIN.empty() || !nodeId.HasValue())
4976
{
50-
ChipLogProgress(Zcl, "AccountLoginManager::HandleLogin failed expected pin %s", mSetupPin);
77+
ChipLogError(Zcl, "Invalid parameters");
5178
return false;
5279
}
80+
81+
Json::Value response;
82+
bool commandHandled = true;
83+
AccountLogin::Commands::Login::Type cmd = { tempAccountIdentifier, setupPIN, nodeId };
84+
85+
auto status = mCommandDelegate->InvokeCommand(mEndpointId, AccountLogin::Id, AccountLogin::Commands::Login::Id,
86+
serializeLoginCommand(cmd), commandHandled, response);
87+
if (status == Status::Success)
88+
{
89+
// Format status response to verify that response is non-failure.
90+
status = mCommandDelegate->FormatStatusResponse(response);
91+
}
92+
ChipLogProgress(Zcl, "AccountLoginManager::HandleLogin command returned with status: %d", chip::to_underlying(status));
93+
return status == chip::Protocols::InteractionModel::Status::Success;
5394
}
5495

5596
bool AccountLoginManager::HandleLogout(const chip::Optional<chip::NodeId> & nodeId)
5697
{
57-
// TODO: Insert your code here to send logout request
58-
return true;
98+
ChipLogProgress(DeviceLayer, "AccountLoginManager::HandleLogout called for endpoint %d", mEndpointId);
99+
100+
if (mCommandDelegate == nullptr)
101+
{
102+
ChipLogError(Zcl, "CommandDelegate not found");
103+
return false;
104+
}
105+
106+
if (!nodeId.HasValue())
107+
{
108+
ChipLogError(Zcl, "Invalid parameters");
109+
return false;
110+
}
111+
112+
Json::Value response;
113+
bool commandHandled = true;
114+
AccountLogin::Commands::Logout::Type cmd = { nodeId };
115+
116+
auto status = mCommandDelegate->InvokeCommand(mEndpointId, AccountLogin::Id, AccountLogin::Commands::Logout::Id,
117+
serializeLogoutCommand(cmd), commandHandled, response);
118+
119+
if (status == Status::Success)
120+
{
121+
// Format status response to verify that response is non-failure.
122+
status = mCommandDelegate->FormatStatusResponse(response);
123+
}
124+
ChipLogProgress(Zcl, "AccountLoginManager::HandleLogout command returned with status: %d", chip::to_underlying(status));
125+
return status == chip::Protocols::InteractionModel::Status::Success;
59126
}
60127

61128
void AccountLoginManager::HandleGetSetupPin(CommandResponseHelper<GetSetupPINResponse> & helper,

examples/tv-app/android/java/AppImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ void refreshConnectedClientsAcl(uint16_t vendorId, uint16_t productId, ContentAp
417417

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

422422
nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end());
423423
}

examples/tv-app/android/java/ContentAppCommandDelegate.cpp

+44-22
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,9 @@
3939
namespace chip {
4040
namespace AppPlatform {
4141

42-
using CommandHandlerInterface = chip::app::CommandHandlerInterface;
43-
using LaunchResponseType = chip::app::Clusters::ContentLauncher::Commands::LauncherResponse::Type;
44-
using PlaybackResponseType = chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type;
45-
using NavigateTargetResponseType = chip::app::Clusters::TargetNavigator::Commands::NavigateTargetResponse::Type;
46-
using GetSetupPINResponseType = chip::app::Clusters::AccountLogin::Commands::GetSetupPINResponse::Type;
47-
using Status = chip::Protocols::InteractionModel::Status;
48-
49-
const std::string FAILURE_KEY = "PlatformError";
50-
const std::string FAILURE_STATUS_KEY = "Status";
42+
const std::string FAILURE_KEY = "PlatformError";
43+
const std::string FAILURE_STATUS_KEY = "Status";
44+
const std::string RESPONSE_STATUS_KEY = "Status";
5145

5246
bool isValidJson(const char * response)
5347
{
@@ -166,6 +160,7 @@ Status ContentAppCommandDelegate::InvokeCommand(EndpointId epId, ClusterId clust
166160
ChipLogError(Zcl, "Java exception in ContentAppCommandDelegate::sendCommand");
167161
env->ExceptionDescribe();
168162
env->ExceptionClear();
163+
return chip::Protocols::InteractionModel::Status::Failure;
169164
}
170165
else
171166
{
@@ -198,7 +193,8 @@ Status ContentAppCommandDelegate::InvokeCommand(EndpointId epId, ClusterId clust
198193
}
199194
env->DeleteLocalRef(resp);
200195

201-
// handle errors from platform-app
196+
// Parse response here in case there is failure response.
197+
// Return non-success error code to indicate to caller it should not parse response.
202198
if (!value[FAILURE_KEY].empty())
203199
{
204200
value = value[FAILURE_KEY];
@@ -209,7 +205,9 @@ Status ContentAppCommandDelegate::InvokeCommand(EndpointId epId, ClusterId clust
209205
return chip::Protocols::InteractionModel::Status::Failure;
210206
}
211207

212-
return chip::Protocols::InteractionModel::Status::UnsupportedEndpoint;
208+
// Return success to indicate command has been sent, response returned and parsed successfully.
209+
// Caller has to manually parse value input/output parameter to get response status/object.
210+
return chip::Protocols::InteractionModel::Status::Success;
213211
}
214212
else
215213
{
@@ -282,20 +280,31 @@ void ContentAppCommandDelegate::FormatResponseData(CommandHandlerInterface::Hand
282280
}
283281

284282
case app::Clusters::AccountLogin::Id: {
285-
if (app::Clusters::AccountLogin::Commands::GetSetupPIN::Id != handlerContext.mRequestPath.mCommandId)
283+
switch (handlerContext.mRequestPath.mCommandId)
286284
{
287-
// No response for other commands in this cluster
285+
case app::Clusters::AccountLogin::Commands::GetSetupPIN::Id: {
286+
Status status;
287+
GetSetupPINResponseType getSetupPINresponse = FormatGetSetupPINResponse(value, status);
288+
if (status != chip::Protocols::InteractionModel::Status::Success)
289+
{
290+
handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, status);
291+
}
292+
else
293+
{
294+
handlerContext.mCommandHandler.AddResponse(handlerContext.mRequestPath, getSetupPINresponse);
295+
}
288296
break;
289297
}
290-
Status status;
291-
GetSetupPINResponseType getSetupPINresponse = FormatGetSetupPINResponse(value, status);
292-
if (status != chip::Protocols::InteractionModel::Status::Success)
293-
{
294-
handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, status);
298+
case app::Clusters::AccountLogin::Commands::Login::Id: {
299+
handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, FormatStatusResponse(value));
300+
break;
295301
}
296-
else
297-
{
298-
handlerContext.mCommandHandler.AddResponse(handlerContext.mRequestPath, getSetupPINresponse);
302+
case app::Clusters::AccountLogin::Commands::Logout::Id: {
303+
handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, FormatStatusResponse(value));
304+
break;
305+
}
306+
default:
307+
break;
299308
}
300309
break;
301310
}
@@ -388,10 +397,23 @@ GetSetupPINResponseType ContentAppCommandDelegate::FormatGetSetupPINResponse(Jso
388397
}
389398
else
390399
{
391-
getSetupPINresponse.setupPIN = "";
400+
status = chip::Protocols::InteractionModel::Status::Failure;
392401
}
393402
return getSetupPINresponse;
394403
}
395404

405+
Status ContentAppCommandDelegate::FormatStatusResponse(Json::Value value)
406+
{
407+
// check if JSON has "Status" key
408+
if (!value[RESPONSE_STATUS_KEY].empty() && !value[RESPONSE_STATUS_KEY].isUInt())
409+
{
410+
return static_cast<Protocols::InteractionModel::Status>(value.asUInt());
411+
}
412+
else
413+
{
414+
return chip::Protocols::InteractionModel::Status::Failure;
415+
}
416+
}
417+
396418
} // namespace AppPlatform
397419
} // namespace chip

0 commit comments

Comments
 (0)