Skip to content

Commit

Permalink
Merge pull request #4 from hnnajh/rotating-id-test
Browse files Browse the repository at this point in the history
Update Rotating id test from local master
  • Loading branch information
hnnajh authored Dec 10, 2020
2 parents 3e1a4b9 + 89a01bc commit 0235d05
Show file tree
Hide file tree
Showing 18 changed files with 698 additions and 11 deletions.
3 changes: 2 additions & 1 deletion examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ executable("chip-tool") {
"commands/common/NetworkCommand.cpp",
"commands/echo/EchoCommand.cpp",
"commands/pairing/PairingCommand.cpp",
"commands/payload/ParseCommand.cpp",
"commands/payload/QRCodeParseCommand.cpp",
"commands/payload/AdditionalDataParseCommand.cpp",
"config/PersistentStorage.cpp",
"main.cpp",
]
Expand Down
37 changes: 37 additions & 0 deletions examples/chip-tool/commands/payload/AdditionalDataParseCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2020 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.
*
*/

#include "AdditionalDataParseCommand.h"

#include <setup_payload/AdditionalDataPayloadParser.h>
#include <setup_payload/AdditionalDataPayload.h>

using namespace ::chip;

CHIP_ERROR AdditionalDataParseCommand::Run(PersistentStorage & storage, NodeId localId, NodeId remoteId)
{
std::string payload(mPayload);
AdditionalDataPayload resultPayload;
CHIP_ERROR err = CHIP_NO_ERROR;
SuccessOrExit(err);
ChipLogProgress(chipTool, "AdditionalDataParseCommand, payload=%s", payload.c_str());

err = AdditionalDataPayloadParser(payload).populatePayload(resultPayload);
exit:
return err;
}
31 changes: 31 additions & 0 deletions examples/chip-tool/commands/payload/AdditionalDataParseCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2020 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 "../common/Command.h"

class AdditionalDataParseCommand : public Command
{
public:
AdditionalDataParseCommand() : Command("parse-additional-data") { AddArgument("payload", &mPayload); }
CHIP_ERROR Run(PersistentStorage & storage, NodeId localId, NodeId remoteId) override;

private:
char * mPayload;
};
6 changes: 4 additions & 2 deletions examples/chip-tool/commands/payload/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

#pragma once

#include "ParseCommand.h"
#include "QRCodeParseCommand.h"
#include "AdditionalDataParseCommand.h"

void registerCommandsPayload(Commands & commands)
{
const char * clusterName = "Payload";
commands_list clusterCommands = {
make_unique<ParseCommand>(),
make_unique<QRCodeParseCommand>(),
make_unique<AdditionalDataParseCommand>()
};

commands.Register(clusterName, clusterCommands);
Expand Down
104 changes: 104 additions & 0 deletions examples/chip-tool/commands/payload/QRCodeParseCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2020 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.
*
*/

#include "QRCodeParseCommand.h"
#include <setup_payload/ManualSetupPayloadParser.h>
#include <setup_payload/QRCodeSetupPayloadParser.h>
#include <setup_payload/SetupPayload.h>

using namespace ::chip;

CHIP_ERROR QRCodeParseCommand::Run(PersistentStorage & storage, NodeId localId, NodeId remoteId)
{
std::string codeString(mCode);
SetupPayload payload;

CHIP_ERROR err = CHIP_NO_ERROR;
err = Parse(codeString, payload);
SuccessOrExit(err);

err = Print(payload);
SuccessOrExit(err);
exit:
return err;
}

CHIP_ERROR QRCodeParseCommand::Print(chip::SetupPayload payload)
{
std::string serialNumber;
std::vector<OptionalQRCodeInfo> optionalVendorData;
CHIP_ERROR err = CHIP_NO_ERROR;

ChipLogProgress(SetupPayload, "RequiresCustomFlow: %u", payload.requiresCustomFlow);
ChipLogProgress(SetupPayload, "VendorID: %u", payload.vendorID);
ChipLogProgress(SetupPayload, "Version: %u", payload.version);
ChipLogProgress(SetupPayload, "ProductID: %u", payload.productID);
ChipLogProgress(SetupPayload, "Discriminator: %u", payload.discriminator);
ChipLogProgress(SetupPayload, "SetUpPINCode: %u", payload.setUpPINCode);
ChipLogProgress(SetupPayload, "RendezvousInformation: %u", payload.rendezvousInformation);

if (payload.getSerialNumber(serialNumber) == CHIP_NO_ERROR)
{
ChipLogProgress(SetupPayload, "SerialNumber: %s", serialNumber.c_str());
}

optionalVendorData = payload.getAllOptionalVendorData();
for (const OptionalQRCodeInfo & info : optionalVendorData)
{
if (info.type == optionalQRCodeInfoTypeString)
{
ChipLogProgress(SetupPayload, "OptionalQRCodeInfo: tag=%u,string value=%s", info.tag, info.data.c_str());
}
else if (info.type == optionalQRCodeInfoTypeInt32)
{
ChipLogProgress(SetupPayload, "OptionalQRCodeInfo: tag=%u,int value=%u", info.tag, info.int32);
}
else
{
err = CHIP_ERROR_INVALID_ARGUMENT;
}
}

SuccessOrExit(err);

exit:
return err;
}

CHIP_ERROR QRCodeParseCommand::Parse(std::string codeString, chip::SetupPayload & payload)
{

CHIP_ERROR err = CHIP_NO_ERROR;
if (IsQRCode(codeString))
{
ChipLogDetail(SetupPayload, "Parsing base41Representation: %s", codeString.c_str());
err = QRCodeSetupPayloadParser(codeString).populatePayload(payload);
}
else
{
ChipLogDetail(SetupPayload, "Parsing decimalRepresentation: %s", codeString.c_str());
err = ManualSetupPayloadParser(codeString).populatePayload(payload);
}

return err;
}

bool QRCodeParseCommand::IsQRCode(std::string codeString)
{
return codeString.rfind(QRCODE_PREFIX) == 0;
}
36 changes: 36 additions & 0 deletions examples/chip-tool/commands/payload/QRCodeParseCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2020 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 "../common/Command.h"
#include <setup_payload/SetupPayload.h>

class QRCodeParseCommand : public Command
{
public:
QRCodeParseCommand() : Command("parse-qr-code") { AddArgument("code", &mCode); }
CHIP_ERROR Run(PersistentStorage & storage, NodeId localId, NodeId remoteId) override;

private:
char * mCode;
CHIP_ERROR Parse(std::string codeString, chip::SetupPayload & payload);
CHIP_ERROR Print(chip::SetupPayload payload);
bool IsQRCode(std::string codeString);
const std::string QRCODE_PREFIX = "CH:";
};
7 changes: 7 additions & 0 deletions src/ble/BLEEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,13 @@ void BLEEndPoint::FinalizeClose(uint8_t oldState, uint8_t flags, BLE_ERROR err)
// If unsubscribe fails, release BLE connection and free end point immediately.
Free();
}
if (!mBle->mPlatformDelegate->UnsubscribeCharacteristic(mConnObj, &CHIP_BLE_SVC_ID, &mBle->CHIP_BLE_CHAR_3_ID))
{
ChipLogError(Ble, "BtpEngine unsub failed");

// If unsubscribe fails, release BLE connection and free end point immediately.
Free();
}
else if (mConnObj != BLE_CONNECTION_UNINITIALIZED)
{
// Unsubscribe request was sent successfully, and a confirmation wasn't spontaneously generated or
Expand Down
12 changes: 8 additions & 4 deletions src/ble/BleLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ const ChipBleUUID BleLayer::CHIP_BLE_CHAR_2_ID = { { // 18EE2EF5-263D-4559-959F-
0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42,
0x9F, 0x9D, 0x12 } };

const ChipBleUUID BleLayer::CHIP_BLE_CHAR_3_ID = { { // 18EE2EF5-263D-4559-959F-4F9C429F9D13
0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42,
0x9F, 0x9D, 0x13 } };

void BleLayerObject::Release()
{
// Decrement the ref count. When it reaches zero, NULL out the pointer to the chip::System::Layer
Expand Down Expand Up @@ -600,7 +604,7 @@ bool BleLayer::HandleSubscribeReceived(BLE_CONNECTION_OBJECT connObj, const Chip
return false;
}

if (UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId))
if (UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId) || UUIDsMatch(&CHIP_BLE_CHAR_3_ID, charId))
{
// Find end point already associated with BLE connection, if any.
BLEEndPoint * endPoint = sBLEEndPointPool.Find(connObj);
Expand All @@ -625,7 +629,7 @@ bool BleLayer::HandleSubscribeComplete(BLE_CONNECTION_OBJECT connObj, const Chip
return false;
}

if (UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId))
if (UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId) || UUIDsMatch(&CHIP_BLE_CHAR_3_ID, charId))
{
BLEEndPoint * endPoint = sBLEEndPointPool.Find(connObj);

Expand All @@ -649,7 +653,7 @@ bool BleLayer::HandleUnsubscribeReceived(BLE_CONNECTION_OBJECT connObj, const Ch
return false;
}

if (UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId))
if (UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId) || UUIDsMatch(&CHIP_BLE_CHAR_3_ID, charId))
{
// Find end point already associated with BLE connection, if any.
BLEEndPoint * endPoint = sBLEEndPointPool.Find(connObj);
Expand All @@ -674,7 +678,7 @@ bool BleLayer::HandleUnsubscribeComplete(BLE_CONNECTION_OBJECT connObj, const Ch
return false;
}

if (UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId))
if (UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId) || UUIDsMatch(&CHIP_BLE_CHAR_3_ID, charId))
{
// Find end point already associated with BLE connection, if any.
BLEEndPoint * endPoint = sBLEEndPointPool.Find(connObj);
Expand Down
2 changes: 2 additions & 0 deletions src/ble/BleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ class DLL_EXPORT BleLayer
static const ChipBleUUID CHIP_BLE_CHAR_1_ID;
// UUID of CHIP service characteristic used for peripheral indications.
static const ChipBleUUID CHIP_BLE_CHAR_2_ID;
// UUID of CHIP service charadteristic used for additional data
static const ChipBleUUID CHIP_BLE_CHAR_3_ID;

BleConnectionDelegate * mConnectionDelegate;
BlePlatformDelegate * mPlatformDelegate;
Expand Down
7 changes: 4 additions & 3 deletions src/lib/core/CHIPTLVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,6 @@ CHIP_ERROR TLVReader::ReadElement()
mElemLenOrVal = LittleEndian::Read64(p);
break;
}

return VerifyElement();
}

Expand All @@ -1368,13 +1367,15 @@ CHIP_ERROR TLVReader::VerifyElement()
}
else
{
if (mElemTag == UnknownImplicitTag)
if (mElemTag == UnknownImplicitTag) {
return CHIP_ERROR_UNKNOWN_IMPLICIT_TLV_TAG;
}
switch (mContainerType)
{
case kTLVType_NotSpecified:
if (IsContextTag(mElemTag))
if (IsContextTag(mElemTag)) {
return CHIP_ERROR_INVALID_TLV_TAG;
}
break;
case kTLVType_Structure:
if (mElemTag == AnonymousTag)
Expand Down
8 changes: 7 additions & 1 deletion src/lib/mdns/DiscoveryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ CHIP_ERROR DiscoveryManager::PublishUnprovisionedDevice(chip::Inet::IPAddressTyp
char discriminatorBuf[5]; // hex representation of 16-bit discriminator
char vendorProductBuf[10]; // "FFFF+FFFF"
// TODO: The text entry will be updated in the spec, update accordingly.
TextEntry entries[2] = {
TextEntry entries[3] = {
{ "D", nullptr, 0 },
{ "VP", nullptr, 0 },
{ "RI", nullptr, 0}
};

VerifyOrExit(mMdnsInitialized, error = CHIP_ERROR_INCORRECT_STATE);
Expand All @@ -189,6 +190,11 @@ CHIP_ERROR DiscoveryManager::PublishUnprovisionedDevice(chip::Inet::IPAddressTyp
entries[0].mDataSize = strnlen(discriminatorBuf, sizeof(discriminatorBuf));
entries[1].mData = reinterpret_cast<const uint8_t *>(vendorProductBuf);
entries[1].mDataSize = strnlen(discriminatorBuf, sizeof(vendorProductBuf));
// Rotating Device ID
entries[2].mData = reinterpret_cast<const uint8_t *>("112233445566");
entries[2].mDataSize = strnlen("112233445566", sizeof("112233445566"));


service.mTextEntryies = entries;
service.mTextEntrySize = sizeof(entries) / sizeof(TextEntry);
service.mPort = CHIP_PORT;
Expand Down
1 change: 1 addition & 0 deletions src/lib/support/logging/CHIPLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ enum LogModule
kLogModule_Shell,
kLogModule_DeviceLayer,
kLogModule_SetupPayload,
kLogModule_AdditionalDataPayload,
kLogModule_AppServer,
kLogModule_Discovery,

Expand Down
Loading

0 comments on commit 0235d05

Please sign in to comment.