Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotating device id representation in TLV Additional Data needs to be aligned with the spec #9455

Merged
merged 78 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
5ad2124
Merge pull request #1 from project-chip/master
hnnajh Nov 25, 2020
2da216b
RotatingId: version0
hnnajh Nov 26, 2020
d7be05e
RotatingId: version1
hnnajh Dec 2, 2020
88bc2a4
Merge pull request #2 from project-chip/master
hnnajh Dec 3, 2020
ceffd58
RotatingId: version0
hnnajh Nov 26, 2020
4b6f8e1
RotatingId: version1
hnnajh Dec 2, 2020
c3ea235
Fix Darwin host build (#3990)
kpschoedel Nov 25, 2020
9ca3ff1
Add '-Wextra' to compiler flags (#3902)
vivien-apple Nov 26, 2020
2f053df
Implement Level Control Cluster (#3806)
markus-becker-tridonic-com Nov 27, 2020
ae38666
Fix Rendezvous over BLE after recent changes (#4012)
Damian-Nordic Nov 30, 2020
5563c31
[thread] fix invalid configuration of active dataset (#4008)
LuDuda Nov 30, 2020
3fecde7
Fix data loss or crash in TCPEndPoint with LwIP (#4022)
kpschoedel Nov 30, 2020
f7e0ea1
Update lighting-app gen/ folder with ZAP generated content (#4010)
vivien-apple Nov 30, 2020
1d731f0
Fix segmentation fault error in response echo message (#3984)
yufengwangca Nov 30, 2020
a23bfef
Add back Android default build coverage & fix the build (#3966)
mspang Nov 30, 2020
ade5ac5
Update all-clusters-app gen/ folder with ZAP generated content (#3963)
vivien-apple Nov 30, 2020
eea78f6
Move src/inet/tests to auto-test-driver generation (#3997)
andy31415 Dec 1, 2020
307a5e8
Rename TestUtils to UnitTestRegistration. (#4021)
andy31415 Dec 1, 2020
2c9a83e
Update src/lib/core/tests to auto-test-driver generation (#3991)
andy31415 Dec 1, 2020
b6e404b
Cleanup zap chip-helper.js (#3973)
jepenven-silabs Dec 1, 2020
35e3a39
Move src/transport/tests to auto-test-driver generation (#3999)
andy31415 Dec 1, 2020
abc5d4f
Use CHIPDeviceController instead of CHIPDeviceController_deprecated (…
vivien-apple Dec 1, 2020
449afa8
Implement the missing part of Exchange Header in Transport layer (#4017)
yufengwangca Dec 1, 2020
e1ba0f5
Remove duplicated send flag defines and put ExchangeMgr/ExchangeConte…
yufengwangca Dec 1, 2020
2f5c829
Move src/lib/asn1/tests and src/ble/tests to auto-test-driver generat…
andy31415 Dec 1, 2020
15e719c
Some conversions to use PacketBufferHandle (#4011)
kpschoedel Dec 1, 2020
7808bda
Move src/system/tests to auto-test-driver generation (#4000)
andy31415 Dec 1, 2020
d76cb70
Remove explicit "all" target from root build file (#3967)
mspang Dec 1, 2020
1d3dca5
Make src/setup_payload compile with -Werror=conversion (#4032)
bzbarsky-apple Dec 2, 2020
6c8a429
Add SSID and password to chip-tool pairing (#4054)
kpschoedel Dec 2, 2020
3e00e8b
Get temperature-measurement and all-clusters-app to use examples/comm…
vivien-apple Dec 2, 2020
41c3739
Add all Thread ULA addresses to the lwip interface (#4053)
gjc13 Dec 2, 2020
e1ad532
Remove src/lib/message. (#4055)
andy31415 Dec 2, 2020
7fc7861
[ChipTool] Add Payload Parse Command (#3696)
lijujayakumar Dec 3, 2020
41c6ba6
rename ParseCommand to QRCodeParseCommand
hnnajh Dec 3, 2020
7007273
adding AdditionalDataParseCommand version 0
hnnajh Dec 4, 2020
0047e36
Adding parsing logic + logging
hnnajh Dec 8, 2020
b06b7f1
adding another parsing method
hnnajh Dec 8, 2020
6087ea2
Basic Parsing is DONE
hnnajh Dec 9, 2020
084c33c
fixing memory issue
hnnajh Dec 9, 2020
c9d6327
removing some logs
hnnajh Dec 9, 2020
e31af94
removing more logs
hnnajh Dec 9, 2020
cf6a24b
minor update
hnnajh Dec 10, 2020
73dd14d
Merge branch 'rotating-id-test' of https://github.com/hnnajh/connecte…
hnnajh Dec 10, 2020
2f54dd8
Add RotatingDeviceId to DNS-SD
hnnajh Dec 10, 2020
89a01bc
Merge branch 'rotating-id-test' of https://github.com/hnnajh/connecte…
hnnajh Dec 10, 2020
3e1a4b9
Merge pull request #3 from project-chip/master
hnnajh Dec 10, 2020
0235d05
Merge pull request #4 from hnnajh/rotating-id-test
hnnajh Dec 10, 2020
9d74100
Revert "Merge pull request #4 from hnnajh/rotating-id-test"
hnnajh Dec 10, 2020
86e1bbe
Merge pull request #13 from project-chip/master
hnnajh Jan 15, 2021
a122ae1
Merge pull request #31 from project-chip/master
hnnajh Apr 21, 2021
2f199d5
Merge pull request #32 from project-chip/master
hnnajh May 29, 2021
48bc70b
Merge pull request #35 from project-chip/master
hnnajh Jun 25, 2021
2583353
Merge pull request #36 from project-chip/master
hnnajh Jul 8, 2021
0cba65f
Merge pull request #37 from project-chip/master
hnnajh Jul 13, 2021
02791f8
Merge pull request #38 from project-chip/master
hnnajh Sep 2, 2021
d9ca943
Storing RI in Octet String + Adding Binary format for BLE
hnnajh Sep 2, 2021
e0ab5ac
Fixing rotating id parser + adding unittests
hnnajh Sep 3, 2021
e3cd973
restyling
hnnajh Sep 3, 2021
d3b818b
refactoring rotating id unit tests
hnnajh Sep 3, 2021
b283e19
Added more unit tests for Rotating Device Id
hnnajh Sep 7, 2021
43fc79c
Merge pull request #40 from project-chip/master
hnnajh Sep 7, 2021
dd2c3fe
Merge branch 'rotating_id_fixes' of https://github.com/hnnajh/connect…
hnnajh Sep 7, 2021
15465da
updated styling
hnnajh Sep 7, 2021
c55adc8
refactor RI tests
hnnajh Sep 8, 2021
76ed850
Added RI Unittest + more validation
hnnajh Sep 13, 2021
5987be6
applying restyling
hnnajh Sep 13, 2021
4c3a170
Fix CI
hnnajh Sep 13, 2021
3864131
update styling
hnnajh Sep 13, 2021
16ac687
Fix CI
hnnajh Sep 13, 2021
bb5a872
Update Styling
hnnajh Sep 13, 2021
1459a18
Fix CI
hnnajh Sep 13, 2021
0f31bbf
Restyling
hnnajh Sep 14, 2021
f731cda
Merge branch 'master' into rotating_id_fixes
hnnajh Sep 14, 2021
13b4676
Fixing nits
hnnajh Sep 16, 2021
42b1519
Using MutableByteSpan in RI generation
hnnajh Sep 16, 2021
9c1ce35
Merge branch 'rotating_id_fixes' of https://github.com/hnnajh/connect…
hnnajh Sep 16, 2021
ce70777
Fixing nits
hnnajh Sep 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions examples/chip-tool/commands/payload/AdditionalDataParseCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "AdditionalDataParseCommand.h"
#include <math.h>
#include <setup_payload/AdditionalDataPayload.h>
#include <setup_payload/AdditionalDataPayloadParser.h>
#include <string>
Expand All @@ -26,22 +27,16 @@ using namespace ::chip::SetupPayloadData;

CHIP_ERROR AdditionalDataParseCommand::Run()
{
std::vector<uint8_t> payloadData;
AdditionalDataPayload resultPayload;
CHIP_ERROR err = CHIP_NO_ERROR;
std::string payloadString(mPayload);

// Decode input payload
size_t len = payloadString.length();
size_t additionalDataPayloadBytesLength = static_cast<size_t>(ceil(strlen(mPayload) / 2));
hnnajh marked this conversation as resolved.
Show resolved Hide resolved
std::unique_ptr<uint8_t[]> additionalDataPayloadBytes(new uint8_t[additionalDataPayloadBytesLength]);

for (size_t i = 0; i < len; i += 2)
{
auto str = payloadString.substr(i, 2);
uint8_t x = (uint8_t) stoi(str, 0, 16);
payloadData.push_back(x);
}
size_t bufferSize =
chip::Encoding::HexToBytes(mPayload, strlen(mPayload), additionalDataPayloadBytes.get(), additionalDataPayloadBytesLength);

err = AdditionalDataPayloadParser(payloadData.data(), (uint32_t) payloadData.size()).populatePayload(resultPayload);
err = AdditionalDataPayloadParser(additionalDataPayloadBytes.get(), bufferSize).populatePayload(resultPayload);
SuccessOrExit(err);

ChipLogProgress(chipTool, "AdditionalDataParseCommand, RotatingDeviceId=%s", resultPayload.rotatingDeviceId.c_str());
Expand Down
1 change: 1 addition & 0 deletions src/app/server/Mdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#if CHIP_ENABLE_ROTATING_DEVICE_ID
#include <setup_payload/AdditionalDataPayloadGenerator.h>
#endif
#include <system/TimeSource.h>
#include <transport/FabricTable.h>

#include <app/server/Server.h>
Expand Down
1 change: 1 addition & 0 deletions src/setup_payload/AdditionalDataPayloadGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ CHIP_ERROR AdditionalDataPayloadGenerator::generateRotatingDeviceIdAsHexString(
rotatingDeviceIdBufferTemp, ArraySize(rotatingDeviceIdBufferTemp),
rotatingDeviceIdBufferSizeTemp));

VerifyOrReturnError(rotatingDeviceIdBufferSize >= RotatingDeviceId::kHexMaxLength, CHIP_ERROR_BUFFER_TOO_SMALL);
ReturnErrorOnFailure(BytesToUppercaseHexString(rotatingDeviceIdBufferTemp, rotatingDeviceIdBufferSizeTemp,
rotatingDeviceIdBuffer, rotatingDeviceIdBufferSize));
rotatingDeviceIdValueOutputSize = rotatingDeviceIdBufferSizeTemp * 2;
chrisdecenzo marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
1 change: 1 addition & 0 deletions src/setup_payload/AdditionalDataPayloadGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class AdditionalDataPayloadGenerator
* @param rotatingDeviceIdBuffer rotating device id buffer
* @param rotatingDeviceIdBufferSize the current size of the supplied buffer
* @param rotatingDeviceIdValueOutputSize the number of chars making up the actual value of the returned rotating device id
* excluding the null terminator
*
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise.
*
Expand Down
4 changes: 2 additions & 2 deletions src/setup_payload/AdditionalDataPayloadParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AdditionalDataPayloadParser
{
private:
const uint8_t * mPayloadBufferData;
const uint32_t mPayloadBufferLength;
const size_t mPayloadBufferLength;

public:
/**
Expand All @@ -49,7 +49,7 @@ class AdditionalDataPayloadParser
* it needs to outlive the lifetime of this parse.
* @param[in] payloadBufferLength The buffer data length for the additional data payload.
*/
AdditionalDataPayloadParser(const uint8_t * payloadBufferData, const uint32_t payloadBufferLength) :
AdditionalDataPayloadParser(const uint8_t * payloadBufferData, const size_t payloadBufferLength) :
mPayloadBufferData(payloadBufferData), mPayloadBufferLength(payloadBufferLength)
{}

Expand Down
54 changes: 33 additions & 21 deletions src/setup_payload/tests/TestAdditionalDataPayload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
*/

#include <math.h>
#include <memory>
#include <nlunit-test.h>
#include <stdio.h>

Expand Down Expand Up @@ -49,6 +51,7 @@ constexpr char kAdditionalDataPayloadWithRotatingDeviceIdAndMaxLifetimeCounter[]
constexpr char kRotatingDeviceId[] = "0A001998AB7130E38B7E9A401CFE9F7B79AF";
constexpr uint16_t kLifetimeCounter = 10;
constexpr uint16_t kAdditionalDataPayloadLength = 51;
constexpr uint16_t kShortRotatingIdLength = 5;

CHIP_ERROR GenerateAdditionalDataPayload(nlTestSuite * inSuite, uint16_t lifetimeCounter, const char * serialNumberBuffer,
size_t serialNumberBufferSize, BitFlags<AdditionalDataFields> additionalDataFields,
Expand Down Expand Up @@ -77,23 +80,14 @@ CHIP_ERROR GenerateAdditionalDataPayload(nlTestSuite * inSuite, uint16_t lifetim
return err;
}

CHIP_ERROR ParseAdditionalDataPayload(const char * additionalDataPayload,
CHIP_ERROR ParseAdditionalDataPayload(const char * additionalDataPayload, size_t additionalDataPayloadLength,
chip::SetupPayloadData::AdditionalDataPayload & outPayload)
{
std::vector<uint8_t> payloadData;
std::string payloadString(additionalDataPayload);

// Decode input payload
size_t len = payloadString.length();

for (size_t i = 0; i < len; i += 2)
{
auto str = payloadString.substr(i, 2);
uint8_t x = (uint8_t) stoi(str, 0, 16);
payloadData.push_back(x);
}

return AdditionalDataPayloadParser(payloadData.data(), (uint32_t) payloadData.size()).populatePayload(outPayload);
size_t additionalDataPayloadBytesLength = static_cast<size_t>(ceil(additionalDataPayloadLength / 2));
hnnajh marked this conversation as resolved.
Show resolved Hide resolved
std::unique_ptr<uint8_t[]> additionalDataPayloadBytes(new uint8_t[additionalDataPayloadBytesLength]);
size_t bufferSize = chip::Encoding::HexToBytes(additionalDataPayload, additionalDataPayloadLength,
additionalDataPayloadBytes.get(), additionalDataPayloadBytesLength);
return AdditionalDataPayloadParser(additionalDataPayloadBytes.get(), bufferSize).populatePayload(outPayload);
}

void TestGeneratingAdditionalDataPayloadWithRotatingDeviceId(nlTestSuite * inSuite, void * inContext)
Expand Down Expand Up @@ -175,35 +169,52 @@ void TestGeneratingRotatingDeviceIdAsStringWithNullInputs(nlTestSuite * inSuite,
NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INVALID_ARGUMENT);
}

void TestGeneratingRotatingDeviceIdWithSmallBuffer(nlTestSuite * inSuite, void * inContext)
{
CHIP_ERROR err = CHIP_NO_ERROR;
char rotatingDeviceIdHexBuffer[kShortRotatingIdLength];
size_t rotatingDeviceIdValueOutputSize = 0;
err = AdditionalDataPayloadGenerator().generateRotatingDeviceIdAsHexString(
kLifetimeCounter, kSerialNumber, strlen(kSerialNumber), rotatingDeviceIdHexBuffer, ArraySize(rotatingDeviceIdHexBuffer),
rotatingDeviceIdValueOutputSize);
NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL);
}

void TestParsingAdditionalDataPayloadWithRotatingDeviceId(nlTestSuite * inSuite, void * inContext)
{
chip::SetupPayloadData::AdditionalDataPayload resultPayload;
NL_TEST_ASSERT(inSuite, ParseAdditionalDataPayload(kAdditionalDataPayloadWithRotatingDeviceId, resultPayload) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite,
ParseAdditionalDataPayload(kAdditionalDataPayloadWithRotatingDeviceId,
strlen(kAdditionalDataPayloadWithRotatingDeviceId), resultPayload) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, strcmp(resultPayload.rotatingDeviceId.c_str(), kRotatingDeviceId) == 0);
}

void TestParsingAdditionalDataPayloadWithoutRotatingDeviceId(nlTestSuite * inSuite, void * inContext)
{
chip::SetupPayloadData::AdditionalDataPayload resultPayload;
NL_TEST_ASSERT(inSuite,
ParseAdditionalDataPayload(kAdditionalDataPayloadWithoutRotatingDeviceId, resultPayload) == CHIP_NO_ERROR);
ParseAdditionalDataPayload(kAdditionalDataPayloadWithoutRotatingDeviceId,
strlen(kAdditionalDataPayloadWithoutRotatingDeviceId),
resultPayload) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, strcmp(resultPayload.rotatingDeviceId.c_str(), "") == 0);
}

void TestParsingAdditionalDataPayloadWithInvalidRotatingDeviceIdLength(nlTestSuite * inSuite, void * inContext)
{
chip::SetupPayloadData::AdditionalDataPayload resultPayload;
NL_TEST_ASSERT(inSuite,
ParseAdditionalDataPayload(kAdditionalDataPayloadWithInvalidRotatingDeviceIdLength, resultPayload) ==
CHIP_ERROR_TLV_UNDERRUN);
ParseAdditionalDataPayload(kAdditionalDataPayloadWithInvalidRotatingDeviceIdLength,
strlen(kAdditionalDataPayloadWithInvalidRotatingDeviceIdLength),
resultPayload) == CHIP_ERROR_TLV_UNDERRUN);
}

void TestParsingAdditionalDataPayloadWithLongRotatingDeviceId(nlTestSuite * inSuite, void * inContext)
{
chip::SetupPayloadData::AdditionalDataPayload resultPayload;
NL_TEST_ASSERT(inSuite,
ParseAdditionalDataPayload(kAdditionalDataPayloadWithLongRotatingDeviceId, resultPayload) ==
CHIP_ERROR_INVALID_STRING_LENGTH);
ParseAdditionalDataPayload(kAdditionalDataPayloadWithLongRotatingDeviceId,
strlen(kAdditionalDataPayloadWithLongRotatingDeviceId),
resultPayload) == CHIP_ERROR_INVALID_STRING_LENGTH);
}

/**
Expand All @@ -218,6 +229,7 @@ const nlTest sTests[] =
NL_TEST_DEF("Test Generating Additional Data Payload without Rotatin gDevice Id", TestGeneratingAdditionalDataPayloadWithoutRotatingDeviceId),
NL_TEST_DEF("Test Generating Rotating Device Id as string", TestGeneratingRotatingDeviceIdAsString),
NL_TEST_DEF("Test Generating Rotating Device Id as string with null/invalid inputs", TestGeneratingRotatingDeviceIdAsStringWithNullInputs),
NL_TEST_DEF("Test Generating Rotating Device Id as string with small buffer", TestGeneratingRotatingDeviceIdWithSmallBuffer),
NL_TEST_DEF("Test Parsing Additional Data Payload with Rotating Device Id", TestParsingAdditionalDataPayloadWithRotatingDeviceId),
NL_TEST_DEF("Test Parsing Additional Data Payload without Rotating Device Id", TestParsingAdditionalDataPayloadWithoutRotatingDeviceId),
NL_TEST_DEF("Test Parsing Additional Data Payload with Invalid Rotating Device Id Length", TestParsingAdditionalDataPayloadWithInvalidRotatingDeviceIdLength),
Expand Down