3 * Copyright (c) 2020 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 describes a QRCode Setup Payload generator based on the
23 * The encoding of the binary data to a base41 string is as follows:
24 * - Every 2 bytes (16 bits) of binary source data are encoded to 3
25 * characters of the Base-41 alphabet.
26 * - If an odd number of bytes are to be encoded, the remaining
27 * single byte is encoded to 2 characters of the Base-41 alphabet.
30 #include "SetupPayload.h"
38 class QRCodeSetupPayloadGenerator
41 SetupPayload mPayload;
44 QRCodeSetupPayloadGenerator(const SetupPayload & setupPayload) : mPayload(setupPayload) {}
47 * This function is called to encode the binary data of a payload to a
48 * base41 string using CHIP TLV encoding scheme.
50 * @param[out] base41Representation
51 * The string to copy the base41 to.
53 * @retval #CHIP_NO_ERROR if the method succeeded.
54 * @retval #CHIP_ERROR_INVALID_ARGUMENT if the payload is invalid.
55 * @retval other Other CHIP or platform-specific error codes indicating
56 * that an error occurred preventing the function from
57 * producing the requested string.
59 CHIP_ERROR payloadBase41Representation(std::string & base41Representation);
62 * This function is called to encode the binary data of a payload to a
63 * base41 string. Callers must pass a buffer of at least
64 * chip::kTotalPayloadDataInBytes or more if there is any serialNumber or
65 * any other optional data. The buffer should be big enough to hold the
66 * TLV encoded value of the payload. If not an error will be throw.
68 * @param[out] base41Representation
69 * The string to copy the base41 to.
70 * @param[in] tlvDataStart
71 * A pointer to an uint8_t buffer into which the TLV
73 * @param[in] tlvDataStartSize
74 * The maximum number of bytes that should be written to
77 * @retval #CHIP_NO_ERROR if the method succeeded.
78 * @retval #CHIP_ERROR_INVALID_ARGUMENT if the payload is invalid.
79 * @retval other Other CHIP or platform-specific error codes indicating
80 * that an error occurred preventing the function from
81 * producing the requested string.
83 CHIP_ERROR payloadBase41Representation(std::string & base41Representation, uint8_t * tlvDataStart, uint32_t tlvDataStartSize);
86 CHIP_ERROR generateTLVFromOptionalData(SetupPayload & outPayload, uint8_t * tlvDataStart, uint32_t maxLen,
87 size_t & tlvDataLengthInBytes);