blob: 78d170c0840435d5397c5f294f40e7c31bdb0a27 [file] [log] [blame]
Damian Królik8dc7e7f2020-09-30 00:29:33 +02001/*
2 * Copyright (c) 2020 Project CHIP Authors
3 * All rights reserved.
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17
Andrei Litvin1873e8c2020-10-12 10:52:26 -040018#pragma once
Damian Królik8dc7e7f2020-09-30 00:29:33 +020019
Kamil Kasperczyk04b4f072022-05-16 15:15:16 +020020#include <lib/support/Span.h>
Damian Królik8dc7e7f2020-09-30 00:29:33 +020021#include <setup_payload/SetupPayload.h>
22
Kamil Kasperczyk07c39472021-04-17 01:06:26 +020023void PrintOnboardingCodes(chip::RendezvousInformationFlags aRendezvousFlags);
Kamil Kasperczyk04b4f072022-05-16 15:15:16 +020024void PrintOnboardingCodes(const chip::PayloadContents & payload);
Kamil Kasperczyk07c39472021-04-17 01:06:26 +020025void ShareQRCodeOverNFC(chip::RendezvousInformationFlags aRendezvousFlags);
Kamil Kasperczyk04b4f072022-05-16 15:15:16 +020026
27/**
28 * Creates a null-terminated QR code from the payload created based on rendezvous flag information.
29 *
30 * The resulting size of the QR code span will be the size of data written and not including the null terminator.
31 */
32CHIP_ERROR GetQRCode(chip::MutableCharSpan & aQRCode, chip::RendezvousInformationFlags aRendezvousFlags);
33
34/**
35 * Creates a null-terminated QR code based on the provided payload.
36 *
37 * The resulting size of the QR code span will be the size of data written and not including the null terminator.
38 */
39CHIP_ERROR GetQRCode(chip::MutableCharSpan & aQRCode, const chip::PayloadContents & payload);
40
41/**
42 * Creates a null-terminated QR code url.
43 */
44CHIP_ERROR GetQRCodeUrl(char * aQRCodeUrl, size_t aUrlMaxSize, const chip::CharSpan & aQRCode);
45
46/**
47 * Creates a null-terminated manual pairing code from the payload created based on rendezvous flag information.
48 *
49 * The resulting size of the manual pairing code span will be the size of data written and not including the null terminator.
50 */
51CHIP_ERROR GetManualPairingCode(chip::MutableCharSpan & aManualPairingCode, chip::RendezvousInformationFlags aRendezvousFlags);
52
53/**
54 * Creates a null-terminated manual pairing code based on the provided payload.
55 *
56 * The resulting size of the manual pairing code span will be the size of data written and not including the null terminator.
57 */
58CHIP_ERROR GetManualPairingCode(chip::MutableCharSpan & aManualPairingCode, const chip::PayloadContents & payload);
59
60CHIP_ERROR GetPayloadContents(chip::PayloadContents & aPayload, chip::RendezvousInformationFlags aRendezvousFlags);
Kamil Kasperczyk034c37a2020-11-24 18:00:17 +010061
62/**
63 * Initialize DataModelHandler and start CHIP datamodel server, the server
64 * assumes the platform's networking has been setup already.
65 *
66 * Method verifies if every character of the QR Code is valid for the url encoding
67 * and otherwise it encodes the invalid character using available ones.
68 *
Kamil Kasperczyk07c39472021-04-17 01:06:26 +020069 * @param aQRCode address of the array storing QR Code to encode.
70 * @param aLen length of the given QR Code.
71 * @param aUrl address of the location where encoded url should be stored.
72 * @param aMaxSize maximal size of the array where encoded url should be stored.
Kamil Kasperczyk034c37a2020-11-24 18:00:17 +010073 * @return CHIP_NO_ERROR on success and other values on error.
74 */
Kamil Kasperczyk07c39472021-04-17 01:06:26 +020075CHIP_ERROR EncodeQRCodeToUrl(const char * aQRCode, size_t aLen, char * aUrl, size_t aMaxSize);