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.
18 #ifndef CHIP_ZCL_ZPRO_CODEC_H
19 #define CHIP_ZCL_ZPRO_CODEC_H
21 #include "chip-zcl-zpro-codec-api.h"
22 #include <app/util/basic-types.h>
24 typedef uint16_t EmberApsOption;
26 /** @brief An in-memory representation of a ZigBee APS frame
27 * of an incoming or outgoing message. Copy pasted here so that we can compile this unit of code independently.
31 /** The cluster ID for this message. */
32 chip::ClusterId clusterId;
33 /** The source endpoint. */
34 chip::EndpointId sourceEndpoint;
35 /** The destination endpoint. */
36 chip::EndpointId destinationEndpoint;
37 /** A bitmask of options from the enumeration above. */
38 EmberApsOption options;
39 /** The group ID for this message, if it is multicast mode. */
40 chip::GroupId groupId;
41 /** The sequence number. */
50 /** @brief Extracts an aps frame from buffer into outApsFrame
51 * @param buffer Buffer to read from
52 * @param buf_length Length of buffer
53 * @param outApsFrame Pointer to EmberApsFrame struct to read into
54 * @return returns the number of bytes that were consumed to read out the EmberApsFrame. 0 means an error was encountered
56 uint16_t extractApsFrame(uint8_t * buffer, uint16_t buf_length, EmberApsFrame * outApsFrame);
58 /** @brief Populates msg with address of the zcl message within buffer.
59 * @return Returns the length of msg buffer. Returns 0 on error e.g. if buffer is too short.
61 uint16_t extractMessage(uint8_t * buffer, uint16_t buffer_length, uint8_t ** msg);
63 /** @brief Prints an aps frame struct
65 void printApsFrame(EmberApsFrame * frame);
68 * @brief Encode an APS frame into the given buffer. Returns the number of
69 * bytes of buffer used by the encoding or 0 if the given buffer is not big
70 * enough. If buffer is null, no encoding will happen; the function will
71 * instead return the number of bytes that would be needed to encode the APS
74 * @param[in] buffer The buffer to write to. If null, the call is in "count the
75 * bytes" mode, and no writing will happen.
76 * @parem[in] buf_length The size of the buffer. Ignored if buffer is null.
77 * @param[in] apsFrame The frame to encode.
80 * - If buffer is null, the number of bytes needed to encode. If this number
81 * does not fit in a uint16_t, 0 will be returned.
82 * - If buffer is non-null but buf_length is not enough to hold the
84 * - If buffer is non-null and buf_length is large enough, the number of bytes
87 uint16_t encodeApsFrame(uint8_t * buffer, uint16_t buf_length, EmberApsFrame * apsFrame);
93 #endif // CHIP_ZCL_ZPRO_CODEC_H