forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdentificationDeclarationOptions.h
182 lines (167 loc) · 7.8 KB
/
IdentificationDeclarationOptions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "Types.h"
#include <app/server/Dnssd.h>
#include <vector>
namespace matter {
namespace casting {
namespace core {
/**
* This class contains the optional parameters used in the IdentificationDeclaration Message, sent by the Commissionee to the
* Commissioner. The options specify information relating to the requested UDC commissioning session.
*/
class IdentificationDeclarationOptions
{
public:
/**
* Feature: Target Content Application
* Flag to instruct the Commissioner not to display a Passcode input dialog, and instead send a CommissionerDeclaration message
* if a commissioning Passcode is needed.
*/
bool mNoPasscode = false;
/**
* Feature: Coordinate Passcode Dialogs
* Flag to instruct the Commissioner to send a CommissionerDeclaration message when the Passcode input dialog on the
* Commissioner has been shown to the user.
*/
bool mCdUponPasscodeDialog = false;
/**
* Feature: Commissioner-Generated Passcode
* Flag to instruct the Commissioner to use the Commissioner-generated Passcode for commissioning.
*/
bool mCommissionerPasscode = false;
/**
* Feature: Commissioner-Generated Passcode
* Flag to indicate whether or not the Commissionee has obtained the Commissioner Passcode from the user and is therefore ready
* for commissioning.
*/
bool mCommissionerPasscodeReady = false;
/**
* Feature: Coordinate Passcode Dialogs
* Flag to indicate when the Commissionee user has decided to exit the commissioning process.
*/
bool mCancelPasscode = false;
/**
* Commissionee's (random) DNS-SD instance name. This field is mandatory and will be auto generated if not provided by the
* client.
*/
char mCommissioneeInstanceName[chip::Dnssd::Commission::kInstanceNameMaxLength + 1] = "";
CHIP_ERROR addTargetAppInfo(const chip::Protocols::UserDirectedCommissioning::TargetAppInfo & targetAppInfo)
{
ChipLogProgress(AppServer, "IdentificationDeclarationOptions::addTargetAppInfo()");
if (mTargetAppInfos.size() >= CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS)
{
ChipLogError(AppServer,
"IdentificationDeclarationOptions::addTargetAppInfo() failed to add TargetAppInfo, max vector size is %d",
CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS);
return CHIP_ERROR_NO_MEMORY;
}
mTargetAppInfos.push_back(targetAppInfo);
return CHIP_NO_ERROR;
}
std::vector<chip::Protocols::UserDirectedCommissioning::TargetAppInfo> getTargetAppInfoList() const { return mTargetAppInfos; }
void resetState()
{
mNoPasscode = false;
mCdUponPasscodeDialog = false;
mCommissionerPasscode = false;
mCommissionerPasscodeReady = false;
mCancelPasscode = false;
mTargetAppInfos.clear();
}
/**
* @brief Builds an IdentificationDeclaration message to be sent to a CastingPlayer, given the options state specified in this
* object.
*/
chip::Protocols::UserDirectedCommissioning::IdentificationDeclaration buildIdentificationDeclarationMessage()
{
ChipLogProgress(AppServer, "IdentificationDeclarationOptions::buildIdentificationDeclarationMessage()");
chip::Protocols::UserDirectedCommissioning::IdentificationDeclaration id;
std::vector<chip::Protocols::UserDirectedCommissioning::TargetAppInfo> targetAppInfos = getTargetAppInfoList();
for (size_t i = 0; i < targetAppInfos.size(); i++)
{
id.AddTargetAppInfo(targetAppInfos[i]);
}
id.SetNoPasscode(mNoPasscode);
id.SetCdUponPasscodeDialog(mCdUponPasscodeDialog);
id.SetCancelPasscode(mCancelPasscode);
id.SetCommissionerPasscode(mCommissionerPasscode);
if (mCommissionerPasscodeReady)
{
id.SetCommissionerPasscodeReady(true);
id.SetInstanceName(mCommissioneeInstanceName);
}
else
{
ChipLogProgress(AppServer,
"IdentificationDeclarationOptions::buildIdentificationDeclarationMessage() generating InstanceName");
CHIP_ERROR err = chip::app::DnssdServer::Instance().GetCommissionableInstanceName(mCommissioneeInstanceName,
sizeof(mCommissioneeInstanceName));
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer,
"IdentificationDeclarationOptions::buildIdentificationDeclarationMessage() Failed to get mdns "
"instance name error: %" CHIP_ERROR_FORMAT,
err.Format());
}
else
{
id.SetInstanceName(mCommissioneeInstanceName);
ChipLogProgress(AppServer,
"IdentificationDeclarationOptions::buildIdentificationDeclarationMessage() InstanceName set to: %s",
mCommissioneeInstanceName);
}
}
LogDetail();
return id;
}
void LogDetail()
{
ChipLogDetail(AppServer, "IdentificationDeclarationOptions::LogDetail() - cpp");
ChipLogDetail(AppServer, "IdentificationDeclarationOptions::mNoPasscode: %s",
mNoPasscode ? "true" : "false");
ChipLogDetail(AppServer, "IdentificationDeclarationOptions::mCdUponPasscodeDialog: %s",
mCdUponPasscodeDialog ? "true" : "false");
ChipLogDetail(AppServer, "IdentificationDeclarationOptions::mCommissionerPasscode: %s",
mCommissionerPasscode ? "true" : "false");
ChipLogDetail(AppServer, "IdentificationDeclarationOptions::mCommissionerPasscodeReady: %s",
mCommissionerPasscodeReady ? "true" : "false");
ChipLogDetail(AppServer, "IdentificationDeclarationOptions::mCancelPasscode: %s",
mCancelPasscode ? "true" : "false");
ChipLogDetail(AppServer, "IdentificationDeclarationOptions::mCommissioneeInstanceName: %s", mCommissioneeInstanceName);
ChipLogDetail(AppServer, "IdentificationDeclarationOptions::TargetAppInfos list:");
for (size_t i = 0; i < mTargetAppInfos.size(); i++)
{
const chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info = mTargetAppInfos[i];
ChipLogDetail(AppServer, "\t\tTargetAppInfo %d, Vendor ID: %u, Product ID: %u", int(i + 1), info.vendorId,
info.productId);
}
}
private:
/**
* Feature: Target Content Application
* The set of content app Vendor IDs (and optionally, Product IDs) that can be used for authentication.
* Also, if TargetAppInfo is passed in, VerifyOrEstablishConnection() will force User Directed Commissioning, in case the
* desired TargetApp is not found in the on-device CastingStore.
*/
std::vector<chip::Protocols::UserDirectedCommissioning::TargetAppInfo> mTargetAppInfos;
};
}; // namespace core
}; // namespace casting
}; // namespace matter