Skip to content

Commit 4fe0f8d

Browse files
chrisdecenzorestyled-io[bot]restyled-commits
authored
Fix TV commissioning and control (project-chip#30904)
* tv2 fixes * debug CI failure * address comments, add code to debug CI * add code to debug CI * add code to debug CI * Restyled by clang-format (project-chip#30960) Co-authored-by: Restyled.io <commits@restyled.io> * revert CI debug --------- Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 8e3d98c commit 4fe0f8d

File tree

6 files changed

+155
-60
lines changed

6 files changed

+155
-60
lines changed

examples/platform/linux/CommissionerMain.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ CHIP_ERROR InitCommissioner(uint16_t commissionerPort, uint16_t udcListenPort, F
181181
params.controllerICAC = icacSpan;
182182
params.controllerNOC = nocSpan;
183183

184-
params.defaultCommissioner = &gAutoCommissioner;
184+
params.defaultCommissioner = &gAutoCommissioner;
185+
params.enableServerInteractions = true;
185186

186187
// assign prefered feature settings
187188
CommissioningParameters commissioningParams = gAutoCommissioner.GetCommissioningParameters();

src/protocols/user_directed_commissioning/UDCClientState.h

+24-11
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ enum class UDCClientProcessingState : uint8_t
4343

4444
using PeerAddress = ::chip::Transport::PeerAddress;
4545

46+
/**
47+
* Represents information in the TargetAppList of the Identification Declaration message
48+
*/
49+
struct TargetAppInfo
50+
{
51+
uint16_t vendorId = 0;
52+
uint16_t productId = 0;
53+
};
54+
4655
/**
4756
* Defines the handling state of a UDC Client.
4857
*
@@ -99,25 +108,29 @@ class UDCClientState
99108
uint16_t GetPairingHint() const { return mPairingHint; }
100109
void SetPairingHint(uint16_t pairingHint) { mPairingHint = pairingHint; }
101110

102-
bool GetAppVendorId(size_t index, uint16_t & vid) const
111+
bool GetTargetAppInfo(uint8_t index, TargetAppInfo & info) const
103112
{
104-
if (index < mNumAppVendorIds)
113+
if (index < mNumTargetAppInfos)
105114
{
106-
vid = mAppVendorIds[index];
115+
info.vendorId = mTargetAppInfos[index].vendorId;
116+
info.productId = mTargetAppInfos[index].productId;
107117
return true;
108118
}
109119
return false;
110120
}
111-
size_t GetNumAppVendorIds() const { return mNumAppVendorIds; }
121+
size_t GetNumTargetAppInfos() const { return mNumTargetAppInfos; }
112122

113-
void AddAppVendorId(uint16_t vid)
123+
bool AddTargetAppInfo(TargetAppInfo vid)
114124
{
115-
if (mNumAppVendorIds >= sizeof(mAppVendorIds))
125+
if (mNumTargetAppInfos >= sizeof(mTargetAppInfos))
116126
{
117127
// already at max
118-
return;
128+
return false;
119129
}
120-
mAppVendorIds[mNumAppVendorIds++] = vid;
130+
mTargetAppInfos[mNumTargetAppInfos].vendorId = vid.vendorId;
131+
mTargetAppInfos[mNumTargetAppInfos].productId = vid.productId;
132+
mNumTargetAppInfos++;
133+
return true;
121134
}
122135

123136
UDCClientProcessingState GetUDCClientProcessingState() const { return mUDCClientProcessingState; }
@@ -183,9 +196,9 @@ class UDCClientState
183196
char mPairingInst[chip::Dnssd::kMaxPairingInstructionLen + 1] = {};
184197
uint16_t mPairingHint = 0;
185198

186-
constexpr static size_t kMaxAppVendorIds = 10;
187-
size_t mNumAppVendorIds = 0; // number of vendor Ids
188-
uint16_t mAppVendorIds[kMaxAppVendorIds];
199+
constexpr static size_t kMaxTargetAppInfos = 10;
200+
uint8_t mNumTargetAppInfos = 0; // number of vendor Ids
201+
TargetAppInfo mTargetAppInfos[kMaxTargetAppInfos];
189202

190203
bool mNoPasscode = false;
191204
bool mCdUponPasscodeDialog = false;

src/protocols/user_directed_commissioning/UserDirectedCommissioning.h

+30-22
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class DLL_EXPORT IdentificationDeclaration
8181
bool HasDiscoveryInfo()
8282
{
8383
return mVendorId != 0 || mProductId != 0 || mCdPort != 0 || strlen(mDeviceName) > 0 || GetRotatingIdLength() > 0 ||
84-
mNumAppVendorIds > 0 || mNoPasscode || mCdUponPasscodeDialog || mCommissionerPasscode || mCommissionerPasscodeReady;
84+
mNumTargetAppInfos > 0 || mNoPasscode || mCdUponPasscodeDialog || mCommissionerPasscode || mCommissionerPasscodeReady;
8585
}
8686

8787
const char * GetDeviceName() const { return mDeviceName; }
@@ -105,25 +105,29 @@ class DLL_EXPORT IdentificationDeclaration
105105
memcpy(mRotatingId, rotatingId, mRotatingIdLen);
106106
}
107107

108-
bool GetAppVendorId(uint8_t index, uint16_t & vid) const
108+
bool GetTargetAppInfo(uint8_t index, TargetAppInfo & info) const
109109
{
110-
if (index < mNumAppVendorIds)
110+
if (index < mNumTargetAppInfos)
111111
{
112-
vid = mAppVendorIds[index];
112+
info.vendorId = mTargetAppInfos[index].vendorId;
113+
info.productId = mTargetAppInfos[index].productId;
113114
return true;
114115
}
115116
return false;
116117
}
117-
size_t GetNumAppVendorIds() const { return mNumAppVendorIds; }
118+
size_t GetNumTargetAppInfos() const { return mNumTargetAppInfos; }
118119

119-
void AddAppVendorId(uint16_t vid)
120+
bool AddTargetAppInfo(TargetAppInfo vid)
120121
{
121-
if (mNumAppVendorIds >= sizeof(mAppVendorIds))
122+
if (mNumTargetAppInfos >= sizeof(mTargetAppInfos))
122123
{
123124
// already at max
124-
return;
125+
return false;
125126
}
126-
mAppVendorIds[mNumAppVendorIds++] = vid;
127+
mTargetAppInfos[mNumTargetAppInfos].vendorId = vid.vendorId;
128+
mTargetAppInfos[mNumTargetAppInfos].productId = vid.productId;
129+
mNumTargetAppInfos++;
130+
return true;
127131
}
128132

129133
const char * GetPairingInst() const { return mPairingInst; }
@@ -170,12 +174,12 @@ class DLL_EXPORT IdentificationDeclaration
170174
client->SetRotatingId(GetRotatingId(), GetRotatingIdLength());
171175
client->SetPairingInst(GetPairingInst());
172176
client->SetPairingHint(GetPairingHint());
173-
for (uint8_t i = 0; i < GetNumAppVendorIds(); i++)
177+
for (uint8_t i = 0; i < GetNumTargetAppInfos(); i++)
174178
{
175-
uint16_t vid;
176-
if (GetAppVendorId(i, vid))
179+
TargetAppInfo info;
180+
if (GetTargetAppInfo(i, info))
177181
{
178-
client->AddAppVendorId(vid);
182+
client->AddTargetAppInfo(info);
179183
}
180184
}
181185

@@ -214,9 +218,10 @@ class DLL_EXPORT IdentificationDeclaration
214218
Encoding::BytesToUppercaseHexString(mRotatingId, mRotatingIdLen, rotatingIdString, sizeof(rotatingIdString));
215219
ChipLogDetail(AppServer, "\trotating id: %s", rotatingIdString);
216220
}
217-
for (uint8_t i = 0; i < mNumAppVendorIds; i++)
221+
for (uint8_t i = 0; i < mNumTargetAppInfos; i++)
218222
{
219-
ChipLogDetail(AppServer, "\tapp vendor id [%d]: %u", i, mAppVendorIds[i]);
223+
ChipLogDetail(AppServer, "\tapp vendor id / product id [%d]: %u/%u", i, mTargetAppInfos[i].vendorId,
224+
mTargetAppInfos[i].productId);
220225
}
221226
if (strlen(mPairingInst) != 0)
222227
{
@@ -256,13 +261,16 @@ class DLL_EXPORT IdentificationDeclaration
256261
{
257262
kVendorIdTag = 1,
258263
kProductIdTag,
259-
kNameTag,
260-
kRotatingIdTag,
261-
kCdPortTag,
264+
kDeviceNameTag,
265+
kDeviceTypeTag,
262266
kPairingInstTag,
263267
kPairingHintTag,
264-
kAppVendorIdListTag,
268+
kRotatingIdTag,
269+
kCdPortTag,
270+
kTargetAppListTag,
271+
kTargetAppTag,
265272
kAppVendorIdTag,
273+
kAppProductIdTag,
266274
kNoPasscodeTag,
267275
kCdUponPasscodeDialogTag,
268276
kCommissionerPasscodeTag,
@@ -281,9 +289,9 @@ class DLL_EXPORT IdentificationDeclaration
281289
uint8_t mRotatingId[chip::Dnssd::kMaxRotatingIdLen];
282290
size_t mRotatingIdLen = 0;
283291

284-
constexpr static size_t kMaxAppVendorIds = 10;
285-
uint8_t mNumAppVendorIds = 0; // number of vendor Ids
286-
uint16_t mAppVendorIds[kMaxAppVendorIds];
292+
constexpr static size_t kMaxTargetAppInfos = 10;
293+
uint8_t mNumTargetAppInfos = 0; // number of vendor Ids
294+
TargetAppInfo mTargetAppInfos[kMaxTargetAppInfos];
287295

288296
char mPairingInst[chip::Dnssd::kMaxPairingInstructionLen + 1] = {};
289297
uint16_t mPairingHint = 0;

src/protocols/user_directed_commissioning/UserDirectedCommissioningClient.cpp

+21-5
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ uint32_t IdentificationDeclaration::WritePayload(uint8_t * payloadBuffer, size_t
120120

121121
VerifyOrExit(CHIP_NO_ERROR == (err = writer.Put(chip::TLV::ContextTag(kVendorIdTag), GetVendorId())), LogErrorOnFailure(err));
122122
VerifyOrExit(CHIP_NO_ERROR == (err = writer.Put(chip::TLV::ContextTag(kProductIdTag), GetProductId())), LogErrorOnFailure(err));
123-
VerifyOrExit(CHIP_NO_ERROR == (err = writer.PutString(chip::TLV::ContextTag(kNameTag), mDeviceName)), LogErrorOnFailure(err));
123+
VerifyOrExit(CHIP_NO_ERROR == (err = writer.PutString(chip::TLV::ContextTag(kDeviceNameTag), mDeviceName)),
124+
LogErrorOnFailure(err));
124125
VerifyOrExit(CHIP_NO_ERROR == (err = writer.PutString(chip::TLV::ContextTag(kPairingInstTag), mPairingInst)),
125126
LogErrorOnFailure(err));
126127
VerifyOrExit(CHIP_NO_ERROR == (err = writer.Put(chip::TLV::ContextTag(kPairingHintTag), mPairingHint)), LogErrorOnFailure(err));
@@ -134,12 +135,22 @@ uint32_t IdentificationDeclaration::WritePayload(uint8_t * payloadBuffer, size_t
134135
// AppVendorIdList
135136
VerifyOrExit(
136137
CHIP_NO_ERROR ==
137-
(err = writer.StartContainer(chip::TLV::ContextTag(kAppVendorIdListTag), chip::TLV::kTLVType_List, listContainerType)),
138+
(err = writer.StartContainer(chip::TLV::ContextTag(kTargetAppListTag), chip::TLV::kTLVType_List, listContainerType)),
138139
LogErrorOnFailure(err));
139-
for (size_t i = 0; i < mNumAppVendorIds; i++)
140+
for (size_t i = 0; i < mNumTargetAppInfos; i++)
140141
{
141-
VerifyOrExit(CHIP_NO_ERROR == (err = writer.Put(chip::TLV::ContextTag(kAppVendorIdTag), mAppVendorIds[i])),
142+
// start the TargetApp structure
143+
VerifyOrExit(CHIP_NO_ERROR ==
144+
(err = writer.StartContainer(chip::TLV::ContextTag(kTargetAppTag), chip::TLV::kTLVType_Structure,
145+
outerContainerType)),
146+
LogErrorOnFailure(err));
147+
// add the vendor Id
148+
VerifyOrExit(CHIP_NO_ERROR == (err = writer.Put(chip::TLV::ContextTag(kAppVendorIdTag), mTargetAppInfos[i].vendorId)),
149+
LogErrorOnFailure(err));
150+
VerifyOrExit(CHIP_NO_ERROR == (err = writer.Put(chip::TLV::ContextTag(kAppProductIdTag), mTargetAppInfos[i].productId)),
142151
LogErrorOnFailure(err));
152+
// end the TargetApp structure
153+
VerifyOrExit(CHIP_NO_ERROR == (err = writer.EndContainer(outerContainerType)), LogErrorOnFailure(err));
143154
}
144155
VerifyOrExit(CHIP_NO_ERROR == (err = writer.EndContainer(listContainerType)), LogErrorOnFailure(err));
145156

@@ -180,7 +191,12 @@ CHIP_ERROR CommissionerDeclaration::ReadPayload(uint8_t * udcPayload, size_t pay
180191
while ((err = reader.Next()) == CHIP_NO_ERROR)
181192
{
182193
chip::TLV::Tag containerTag = reader.GetTag();
183-
uint8_t tagNum = static_cast<uint8_t>(chip::TLV::TagNumFromTag(containerTag));
194+
if (!TLV::IsContextTag(containerTag))
195+
{
196+
ChipLogError(AppServer, "Unexpected non-context TLV tag.");
197+
return CHIP_ERROR_INVALID_TLV_TAG;
198+
}
199+
uint8_t tagNum = static_cast<uint8_t>(chip::TLV::TagNumFromTag(containerTag));
184200

185201
switch (tagNum)
186202
{

src/protocols/user_directed_commissioning/UserDirectedCommissioningServer.cpp

+55-9
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ CHIP_ERROR IdentificationDeclaration::ReadPayload(uint8_t * udcPayload, size_t p
209209
while ((err = reader.Next()) == CHIP_NO_ERROR)
210210
{
211211
chip::TLV::Tag containerTag = reader.GetTag();
212-
uint8_t tagNum = static_cast<uint8_t>(chip::TLV::TagNumFromTag(containerTag));
212+
if (!TLV::IsContextTag(containerTag))
213+
{
214+
ChipLogError(AppServer, "Unexpected non-context TLV tag.");
215+
return CHIP_ERROR_INVALID_TLV_TAG;
216+
}
217+
uint8_t tagNum = static_cast<uint8_t>(chip::TLV::TagNumFromTag(containerTag));
213218

214219
switch (tagNum)
215220
{
@@ -225,7 +230,7 @@ CHIP_ERROR IdentificationDeclaration::ReadPayload(uint8_t * udcPayload, size_t p
225230
// port
226231
err = reader.Get(mCdPort);
227232
break;
228-
case kNameTag:
233+
case kDeviceNameTag:
229234
// deviceName
230235
err = reader.GetString(mDeviceName, sizeof(mDeviceName));
231236
break;
@@ -242,25 +247,66 @@ CHIP_ERROR IdentificationDeclaration::ReadPayload(uint8_t * udcPayload, size_t p
242247
mRotatingIdLen = reader.GetLength();
243248
err = reader.GetBytes(mRotatingId, sizeof(mRotatingId));
244249
break;
245-
case kAppVendorIdListTag:
250+
case kTargetAppListTag:
246251
// app vendor list
247252
{
253+
ChipLogProgress(AppServer, "TLV found an applist");
248254
chip::TLV::TLVType listContainerType = chip::TLV::kTLVType_List;
249255
ReturnErrorOnFailure(reader.EnterContainer(listContainerType));
250256

251-
while ((err = reader.Next()) == CHIP_NO_ERROR && mNumAppVendorIds < sizeof(mAppVendorIds))
257+
while ((err = reader.Next()) == CHIP_NO_ERROR && mNumTargetAppInfos < sizeof(mTargetAppInfos))
252258
{
253259
containerTag = reader.GetTag();
254-
tagNum = static_cast<uint8_t>(chip::TLV::TagNumFromTag(containerTag));
255-
if (tagNum == kAppVendorIdTag)
260+
if (!TLV::IsContextTag(containerTag))
261+
{
262+
ChipLogError(AppServer, "Unexpected non-context TLV tag.");
263+
return CHIP_ERROR_INVALID_TLV_TAG;
264+
}
265+
tagNum = static_cast<uint8_t>(chip::TLV::TagNumFromTag(containerTag));
266+
if (tagNum == kTargetAppTag)
267+
{
268+
ReturnErrorOnFailure(reader.EnterContainer(outerContainerType));
269+
uint16_t appVendorId = 0;
270+
uint16_t appProductId = 0;
271+
272+
while ((err = reader.Next()) == CHIP_NO_ERROR)
273+
{
274+
containerTag = reader.GetTag();
275+
if (!TLV::IsContextTag(containerTag))
276+
{
277+
ChipLogError(AppServer, "Unexpected non-context TLV tag.");
278+
return CHIP_ERROR_INVALID_TLV_TAG;
279+
}
280+
tagNum = static_cast<uint8_t>(chip::TLV::TagNumFromTag(containerTag));
281+
if (tagNum == kAppVendorIdTag)
282+
{
283+
err = reader.Get(appVendorId);
284+
}
285+
else if (tagNum == kAppProductIdTag)
286+
{
287+
err = reader.Get(appProductId);
288+
}
289+
}
290+
if (err == CHIP_END_OF_TLV)
291+
{
292+
ChipLogProgress(AppServer, "TLV end of struct TLV");
293+
ReturnErrorOnFailure(reader.ExitContainer(outerContainerType));
294+
}
295+
if (appVendorId != 0)
296+
{
297+
mTargetAppInfos[mNumTargetAppInfos].vendorId = appVendorId;
298+
mTargetAppInfos[mNumTargetAppInfos].productId = appProductId;
299+
mNumTargetAppInfos++;
300+
}
301+
}
302+
else
256303
{
257-
err = reader.Get(mAppVendorIds[mNumAppVendorIds]);
258-
mNumAppVendorIds++;
304+
ChipLogError(AppServer, "unrecognized tag %d", tagNum);
259305
}
260306
}
261307
if (err == CHIP_END_OF_TLV)
262308
{
263-
ChipLogError(AppServer, "TLV end of array TLV");
309+
ChipLogProgress(AppServer, "TLV end of array");
264310
ReturnErrorOnFailure(reader.ExitContainer(listContainerType));
265311
}
266312
}

0 commit comments

Comments
 (0)