Skip to content

Commit

Permalink
Fix ble connection in Temperature Measurement app
Browse files Browse the repository at this point in the history
  • Loading branch information
“sonalipatil” committed Jun 22, 2021
1 parent 82e6290 commit fd437ab
Show file tree
Hide file tree
Showing 4 changed files with 1,279 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,77 +251,6 @@ void DispatchServerCommand(app::Command * apCommandObj, CommandId aCommandId, En
{
switch (aCommandId)
{
case ZCL_ADD_THREAD_NETWORK_COMMAND_ID: {
expectArgumentCount = 3;
chip::ByteSpan operationalDataset;
uint64_t breadcrumb;
uint32_t timeoutMs;
bool argExists[3];

memset(argExists, 0, sizeof argExists);

while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR)
{
// Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element.
// Skip this element if it is not a ContextTag, not consider it as an error if other values are valid.
if (!TLV::IsContextTag(aDataTlv.GetTag()))
{
continue;
}
currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag());
if (currentDecodeTagId < 3)
{
if (argExists[currentDecodeTagId])
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
else
{
argExists[currentDecodeTagId] = true;
validArgumentCount++;
}
}
switch (currentDecodeTagId)
{
case 0: {
const uint8_t * data = nullptr;
TLVUnpackError = aDataTlv.GetDataPtr(data);
operationalDataset = chip::ByteSpan(data, aDataTlv.GetLength());
}
break;
case 1:
TLVUnpackError = aDataTlv.Get(breadcrumb);
break;
case 2:
TLVUnpackError = aDataTlv.Get(timeoutMs);
break;
default:
// Unsupported tag, ignore it.
ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
break;
}
if (CHIP_NO_ERROR != TLVUnpackError)
{
break;
}
}

if (CHIP_END_OF_TLV == TLVError)
{
// CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error.
TLVError = CHIP_NO_ERROR;
}

if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount)
{
// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
wasHandled = emberAfNetworkCommissioningClusterAddThreadNetworkCallback(apCommandObj, operationalDataset,
breadcrumb, timeoutMs);
}
break;
}
case ZCL_ADD_WI_FI_NETWORK_COMMAND_ID: {
expectArgumentCount = 4;
chip::ByteSpan ssid;
Expand Down Expand Up @@ -742,77 +671,6 @@ void DispatchServerCommand(app::Command * apCommandObj, CommandId aCommandId, En
}
break;
}
case ZCL_UPDATE_THREAD_NETWORK_COMMAND_ID: {
expectArgumentCount = 3;
chip::ByteSpan operationalDataset;
uint64_t breadcrumb;
uint32_t timeoutMs;
bool argExists[3];

memset(argExists, 0, sizeof argExists);

while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR)
{
// Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element.
// Skip this element if it is not a ContextTag, not consider it as an error if other values are valid.
if (!TLV::IsContextTag(aDataTlv.GetTag()))
{
continue;
}
currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag());
if (currentDecodeTagId < 3)
{
if (argExists[currentDecodeTagId])
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
else
{
argExists[currentDecodeTagId] = true;
validArgumentCount++;
}
}
switch (currentDecodeTagId)
{
case 0: {
const uint8_t * data = nullptr;
TLVUnpackError = aDataTlv.GetDataPtr(data);
operationalDataset = chip::ByteSpan(data, aDataTlv.GetLength());
}
break;
case 1:
TLVUnpackError = aDataTlv.Get(breadcrumb);
break;
case 2:
TLVUnpackError = aDataTlv.Get(timeoutMs);
break;
default:
// Unsupported tag, ignore it.
ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
break;
}
if (CHIP_NO_ERROR != TLVUnpackError)
{
break;
}
}

if (CHIP_END_OF_TLV == TLVError)
{
// CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error.
TLVError = CHIP_NO_ERROR;
}

if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount)
{
// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
wasHandled = emberAfNetworkCommissioningClusterUpdateThreadNetworkCallback(apCommandObj, operationalDataset,
breadcrumb, timeoutMs);
}
break;
}
case ZCL_UPDATE_WI_FI_NETWORK_COMMAND_ID: {
expectArgumentCount = 4;
chip::ByteSpan ssid;
Expand Down
15 changes: 0 additions & 15 deletions examples/temperature-measurement-app/esp32/main/gen/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -773,13 +773,6 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(chip::app::
bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(chip::app::Command * commandObj, uint8_t location,
uint8_t * countryCode, uint64_t breadcrumb, uint32_t timeoutMs);

/**
* @brief Network Commissioning Cluster AddThreadNetwork Command callback
*/

bool emberAfNetworkCommissioningClusterAddThreadNetworkCallback(chip::app::Command * commandObj, chip::ByteSpan operationalDataset,
uint64_t breadcrumb, uint32_t timeoutMs);

/**
* @brief Network Commissioning Cluster AddWiFiNetwork Command callback
*/
Expand Down Expand Up @@ -822,14 +815,6 @@ bool emberAfNetworkCommissioningClusterRemoveNetworkCallback(chip::app::Command
bool emberAfNetworkCommissioningClusterScanNetworksCallback(chip::app::Command * commandObj, chip::ByteSpan ssid,
uint64_t breadcrumb, uint32_t timeoutMs);

/**
* @brief Network Commissioning Cluster UpdateThreadNetwork Command callback
*/

bool emberAfNetworkCommissioningClusterUpdateThreadNetworkCallback(chip::app::Command * commandObj,
chip::ByteSpan operationalDataset, uint64_t breadcrumb,
uint32_t timeoutMs);

/**
* @brief Network Commissioning Cluster UpdateWiFiNetwork Command callback
*/
Expand Down
Loading

0 comments on commit fd437ab

Please sign in to comment.