blob: bc5498cb785055bed29b4d57877157f409ff7248 [file] [log] [blame]
kasunath7ffd30a2022-05-10 18:11:34 -07001#pragma once
2
3#include <stdint.h>
4
5#ifdef __cplusplus
6extern "C"
7{
8#endif
9
10/**
11 * @brief If expr is non zero, return with that value.
12 */
13#ifndef RETURN_IF_IERROR
14#define RETURN_IF_IERROR(expr) \
15 do \
16 { \
17 int __status = (expr); \
18 if (__status != 0) \
19 { \
20 return __status; \
21 } \
22 } while (0)
23#endif
24
25 /**
26 * @brief RDE BEJ decoding errors.
27 */
28 enum BejError
29 {
kasunathd073aa12022-05-12 16:08:49 -070030 bejErrorNoError = 0,
31 bejErrorUnknown,
32 bejErrorInvalidSize,
33 bejErrorNotSuppoted,
34 bejErrorUnknownProperty,
35 bejErrorInvalidSchemaType,
36 bejErrorInvalidPropertyOffset,
kasunath34a096d2022-05-17 11:36:14 -070037 bejErrorNullParameter,
kasunath7ffd30a2022-05-10 18:11:34 -070038 };
39
40 /**
41 * @brief BEJ schema classes.
42 */
43 enum BejSchemaClass
44 {
kasunathd073aa12022-05-12 16:08:49 -070045 bejMajorSchemaClass = 0,
46 bejEventSchemaClass = 1,
47 bejAnnotationSchemaClass = 2,
48 bejCollectionMemberTypeSchemaClass = 3,
49 bejErrorSchemaClass = 4,
kasunath7ffd30a2022-05-10 18:11:34 -070050 };
51
52 /**
53 * @brief BEJ data types supported in BEJ version 0xF1F0F000.
54 */
55 enum BejPrincipalDataType
56 {
kasunathd073aa12022-05-12 16:08:49 -070057 bejSet = 0,
58 bejArray = 1,
59 bejNull = 2,
60 bejInteger = 3,
61 bejEnum = 4,
62 bejString = 5,
63 bejReal = 6,
64 bejBoolean = 7,
65 bejBytestring = 8,
66 bejChoice = 9,
67 bejPropertyAnnotation = 10,
68 bejPrincipalDataReserved1 = 11,
69 bejPrincipalDataReserved2 = 12,
70 bejPrincipalDataReserved3 = 13,
71 bejResourceLink = 14,
72 bejResourceLinkExpansion = 15,
kasunath7ffd30a2022-05-10 18:11:34 -070073 };
74
75 /**
76 * @brief Format BEJ tuple.
77 */
78 struct BejTupleF
79 {
80 uint8_t deferredBinding : 1;
81 uint8_t readOnlyProperty : 1;
82 uint8_t nullableProperty : 1;
83 uint8_t reserved : 1;
84 enum BejPrincipalDataType principalDataType : 4;
85 } __attribute__((__packed__));
86
87 /**
88 * @brief Sequence Number BEJ tuple.
89 */
90 struct BejTupleS
91 {
92 uint8_t schema;
93 // Dictionaries contain 16bit sequence numbers. So allocating 16bits for
94 // the sequence number here.
95 uint16_t sequenceNumber;
96 };
97
98 /**
99 * @brief Represent offsets of Format, Value Length and Value of a SFLV
100 * tuple.
101 */
102 struct BejSFLVOffset
103 {
104 uint32_t formatOffset;
105 uint32_t valueLenNnintOffset;
106 uint32_t valueOffset;
107 };
108
109 /**
110 * @brief Fields in Bej Real data type.
111 */
112 struct BejReal
113 {
114 // Number bytes in exp.
115 uint8_t expLen;
116 int64_t whole;
117 uint64_t zeroCount;
118 uint64_t fract;
119 int64_t exp;
120 };
121
122 /**
123 * @brief SFLV BEJ tuple infomation.
124 */
125 struct BejSFLV
126 {
127 struct BejTupleS tupleS;
128 struct BejTupleF format;
129 // Value portion size in bytes.
130 uint32_t valueLength;
131 // Value end-offset with respect to the begining of the encoded stream.
132 uint32_t valueEndOffset;
133 // Pointer to the value.
134 const uint8_t* value;
135 };
136
137 /**
138 * @brief bejEncoding PLDM data type header.
139 */
140 struct BejPldmBlockHeader
141 {
142 uint32_t bejVersion;
143 uint16_t reserved;
144 uint8_t schemaClass;
145 } __attribute__((__packed__));
146
147 enum RdeOperationInitType
148 {
kasunathd073aa12022-05-12 16:08:49 -0700149 rdeOpInitOperationHead = 0,
150 rdeOpInitOperationRead = 1,
151 rdeOpInitOperationCreate = 2,
152 rdeOpInitOperationDelete = 3,
153 rdeOpInitOperationUpdate = 4,
154 rdeOpInitOperationReplace = 5,
155 rdeOpInitOperationAction = 6,
kasunath7ffd30a2022-05-10 18:11:34 -0700156 };
157
158 enum RdeMultiReceiveTransferFlag
159 {
kasunathd073aa12022-05-12 16:08:49 -0700160 rdeMRecFlagStart = 0,
161 rdeMRecFlagMiddle = 1,
162 rdeMRecFlagEnd = 2,
163 rdeMRecFlagStartAndEnd = 3,
kasunath7ffd30a2022-05-10 18:11:34 -0700164 };
165
166 struct RdeOperationInitReqHeader
167 {
168 uint32_t resourceID;
169 uint16_t operationID;
170 uint8_t operationType;
171
172 // OperationFlags bits
173 uint8_t locatorValid : 1;
174 uint8_t containsRequestPayload : 1;
175 uint8_t containsCustomRequestParameters : 1;
176
177 uint8_t reserved : 5;
178 uint32_t sendDataTransferHandle;
179 uint8_t operationLocatorLength;
180 uint32_t requestPayloadLength;
181 } __attribute__((__packed__));
182
183 struct MultipartReceiveResHeader
184 {
185 uint8_t completionCode;
186 uint8_t transferFlag;
187 uint32_t nextDataTransferHandle;
188 uint32_t dataLengthBytes;
189 } __attribute__((__packed__));
190
191 /**
192 * @brief Get the unsigned integer value from provided bytes.
193 *
kasunathd073aa12022-05-12 16:08:49 -0700194 * @param[in] bytes - valid pointer to a byte stream in little-endian
195 * format.
196 * @param[in] numOfBytes - number of bytes belongs to the value. Maximum
197 * number of bytes supported is 8. If numOfBytes > 8, the result is
198 * undefined.
kasunath7ffd30a2022-05-10 18:11:34 -0700199 * @return unsigend 64bit representation of the value.
200 */
201 uint64_t rdeGetUnsignedInteger(const uint8_t* bytes, uint8_t numOfBytes);
202
203 /**
204 * @brief Get the value from nnint type.
205 *
kasunathd073aa12022-05-12 16:08:49 -0700206 * @param[in] nnint - nnint should be pointing to a valid nnint.
kasunath7ffd30a2022-05-10 18:11:34 -0700207 * @return unsigend 64bit representation of the value.
208 */
209 uint64_t rdeGetNnint(const uint8_t* nnint);
210
211 /**
212 * @brief Get the size of the complete nnint.
213 *
kasunathd073aa12022-05-12 16:08:49 -0700214 * @param[in] nnint - pointer to a valid nnint.
kasunath7ffd30a2022-05-10 18:11:34 -0700215 * @return size of the complete nnint.
216 */
217 uint8_t rdeGetNnintSize(const uint8_t* nnint);
218
219#ifdef __cplusplus
220}
221#endif