3 * Copyright (c) 2021 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 * This file provides a utility to generate Additional Data payload and its members
21 * (e.g. rotating device id)
26 #include <core/CHIPError.h>
27 #include <support/BitFlags.h>
28 #include <system/TLVPacketBufferBackingStore.h>
31 namespace RotatingDeviceId {
32 static constexpr unsigned kLifetimeCounterSize = 2;
33 static constexpr unsigned kHashSuffixLength = 16;
34 static constexpr unsigned kMaxLength = kLifetimeCounterSize + kHashSuffixLength;
35 static constexpr unsigned kHexMaxLength = kMaxLength * 2 + 1;
36 } // namespace RotatingDeviceId
38 enum class AdditionalDataFields : int8_t
41 RotatingDeviceId = 0x01
44 class AdditionalDataPayloadGenerator
48 AdditionalDataPayloadGenerator() {}
51 * Generate additional data payload (i.e. TLV encoded).
53 * @param lifetimeCounter lifetime counter
54 * @param serialNumberBuffer null-terminated serial number buffer
55 * @param serialNumberBufferSize size of the serial number buffer supplied.
56 * @param bufferHandle output buffer handle
57 * @param additionalDataFields bitfield for what fields should be generated in the additional data
59 * @retval #CHIP_ERROR_INVALID_TLV_TAG
60 * If the specified tag value is invalid or inappropriate in the context
61 * in which the value is being written.
62 * @retval #CHIP_ERROR_BUFFER_TOO_SMALL
63 * If writing the value would exceed the limit on the maximum number of
64 * bytes specified when the writer was initialized.
65 * @retval #CHIP_ERROR_NO_MEMORY
66 * If an attempt to allocate an output buffer failed due to lack of
68 * @retval other Other CHIP or platform-specific errors returned by the configured
72 CHIP_ERROR generateAdditionalDataPayload(uint16_t lifetimeCounter, const char * serialNumberBuffer,
73 size_t serialNumberBufferSize, chip::System::PacketBufferHandle & bufferHandle,
74 BitFlags<uint8_t, AdditionalDataFields> additionalDataFields);
75 // Generate Device Rotating ID
77 * Generate additional data payload (i.e. TLV encoded).
79 * @param lifetimeCounter lifetime counter
80 * @param serialNumberBuffer null-terminated serial number buffer
81 * @param serialNumberBufferSize size of the serial number buffer supplied.
82 * @param rotatingDeviceIdBuffer rotating device id buffer
83 * @param rotatingDeviceIdBufferSize the current size of the supplied buffer
84 * @param rotatingDeviceIdValueOutputSize the number of chars making up the actual value of the returned rotating device id
86 * @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise.
89 CHIP_ERROR generateRotatingDeviceId(uint16_t lifetimeCounter, const char * serialNumberBuffer, size_t serialNumberBufferSize,
90 char * rotatingDeviceIdBuffer, size_t rotatingDeviceIdBufferSize,
91 size_t & rotatingDeviceIdValueOutputSize);