Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / chip-zcl-zpro-codec.h
1 /**
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
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
18 #ifndef CHIP_ZCL_ZPRO_CODEC_H
19 #define CHIP_ZCL_ZPRO_CODEC_H
20
21 #include "chip-zcl-zpro-codec-api.h"
22 #include <app/util/basic-types.h>
23
24 typedef uint16_t EmberApsOption;
25
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.
28  */
29 typedef struct
30 {
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. */
42     uint8_t sequence;
43     uint8_t radius;
44 } EmberApsFrame;
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
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
55  */
56 uint16_t extractApsFrame(uint8_t * buffer, uint16_t buf_length, EmberApsFrame * outApsFrame);
57
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.
60  */
61 uint16_t extractMessage(uint8_t * buffer, uint16_t buffer_length, uint8_t ** msg);
62
63 /** @brief Prints an aps frame struct
64  */
65 void printApsFrame(EmberApsFrame * frame);
66
67 /**
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
72  * frame.
73  *
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.
78  *
79  * @return
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
83  *     EmberApsFrame, 0.
84  *   - If buffer is non-null and buf_length is large enough, the number of bytes
85  *     placed in buffer.
86  */
87 uint16_t encodeApsFrame(uint8_t * buffer, uint16_t buf_length, EmberApsFrame * apsFrame);
88
89 #ifdef __cplusplus
90 }
91 #endif
92
93 #endif // CHIP_ZCL_ZPRO_CODEC_H