blob: bb55a37cdadd4513a1b3600d52e10f29f493520c [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 {
30 BejErrorNoError = 0,
31 BejErrorUnknown,
32 BejErrorInvalidSize,
33 BejErrorNotSuppoted,
34 BejErrorUnknownProperty,
35 BejErrorInvalidSchemaType,
36 BejErrorInvalidPropertyOffset,
37 };
38
39 /**
40 * @brief BEJ schema classes.
41 */
42 enum BejSchemaClass
43 {
44 BejMajorSchemaClass = 0,
45 BejEventSchemaClass = 1,
46 BejAnnotationSchemaClass = 2,
47 BejCollectionMemberTypeSchemaClass = 3,
48 BejErrorSchemaClass = 4,
49 };
50
51 /**
52 * @brief BEJ data types supported in BEJ version 0xF1F0F000.
53 */
54 enum BejPrincipalDataType
55 {
56 BejSet = 0,
57 BejArray = 1,
58 BejNull = 2,
59 BejInteger = 3,
60 BejEnum = 4,
61 BejString = 5,
62 BejReal = 6,
63 BejBoolean = 7,
64 BejBytestring = 8,
65 BejChoice = 9,
66 BejPropertyAnnotation = 10,
67 Reserved1 = 11,
68 Reserved2 = 12,
69 Reserved3 = 13,
70 BejResourceLink = 14,
71 BejResourceLinkExpansion = 15,
72 };
73
74 /**
75 * @brief Format BEJ tuple.
76 */
77 struct BejTupleF
78 {
79 uint8_t deferredBinding : 1;
80 uint8_t readOnlyProperty : 1;
81 uint8_t nullableProperty : 1;
82 uint8_t reserved : 1;
83 enum BejPrincipalDataType principalDataType : 4;
84 } __attribute__((__packed__));
85
86 /**
87 * @brief Sequence Number BEJ tuple.
88 */
89 struct BejTupleS
90 {
91 uint8_t schema;
92 // Dictionaries contain 16bit sequence numbers. So allocating 16bits for
93 // the sequence number here.
94 uint16_t sequenceNumber;
95 };
96
97 /**
98 * @brief Represent offsets of Format, Value Length and Value of a SFLV
99 * tuple.
100 */
101 struct BejSFLVOffset
102 {
103 uint32_t formatOffset;
104 uint32_t valueLenNnintOffset;
105 uint32_t valueOffset;
106 };
107
108 /**
109 * @brief Fields in Bej Real data type.
110 */
111 struct BejReal
112 {
113 // Number bytes in exp.
114 uint8_t expLen;
115 int64_t whole;
116 uint64_t zeroCount;
117 uint64_t fract;
118 int64_t exp;
119 };
120
121 /**
122 * @brief SFLV BEJ tuple infomation.
123 */
124 struct BejSFLV
125 {
126 struct BejTupleS tupleS;
127 struct BejTupleF format;
128 // Value portion size in bytes.
129 uint32_t valueLength;
130 // Value end-offset with respect to the begining of the encoded stream.
131 uint32_t valueEndOffset;
132 // Pointer to the value.
133 const uint8_t* value;
134 };
135
136 /**
137 * @brief bejEncoding PLDM data type header.
138 */
139 struct BejPldmBlockHeader
140 {
141 uint32_t bejVersion;
142 uint16_t reserved;
143 uint8_t schemaClass;
144 } __attribute__((__packed__));
145
146 enum RdeOperationInitType
147 {
148 RdeOpInitOperationHead = 0,
149 RdeOpInitOperationRead = 1,
150 RdeOpInitOperationCreate = 2,
151 RdeOpInitOperationDelete = 3,
152 RdeOpInitOperationUpdate = 4,
153 RdeOpInitOperationReplace = 5,
154 RdeOpInitOperationAction = 6,
155 };
156
157 enum RdeMultiReceiveTransferFlag
158 {
159 RdeMRecFlagStart = 0,
160 RdeMRecFlagMiddle = 1,
161 RdeMRecFlagEnd = 2,
162 RdeMRecFlagStartAndEnd = 3,
163 };
164
165 struct RdeOperationInitReqHeader
166 {
167 uint32_t resourceID;
168 uint16_t operationID;
169 uint8_t operationType;
170
171 // OperationFlags bits
172 uint8_t locatorValid : 1;
173 uint8_t containsRequestPayload : 1;
174 uint8_t containsCustomRequestParameters : 1;
175
176 uint8_t reserved : 5;
177 uint32_t sendDataTransferHandle;
178 uint8_t operationLocatorLength;
179 uint32_t requestPayloadLength;
180 } __attribute__((__packed__));
181
182 struct MultipartReceiveResHeader
183 {
184 uint8_t completionCode;
185 uint8_t transferFlag;
186 uint32_t nextDataTransferHandle;
187 uint32_t dataLengthBytes;
188 } __attribute__((__packed__));
189
190 /**
191 * @brief Get the unsigned integer value from provided bytes.
192 *
193 * @param bytes - valid pointer to a byte stream in little-endian format.
194 * @param numOfBytes - number of bytes belongs to the value. Maximum number
195 * of bytes supported is 8. If numOfBytes > 8, the result is undefined.
196 * @return unsigend 64bit representation of the value.
197 */
198 uint64_t rdeGetUnsignedInteger(const uint8_t* bytes, uint8_t numOfBytes);
199
200 /**
201 * @brief Get the value from nnint type.
202 *
203 * @param nnint - nnint should be pointing to a valid nnint.
204 * @return unsigend 64bit representation of the value.
205 */
206 uint64_t rdeGetNnint(const uint8_t* nnint);
207
208 /**
209 * @brief Get the size of the complete nnint.
210 *
211 * @param nnint - pointer to a valid nnint.
212 * @return size of the complete nnint.
213 */
214 uint8_t rdeGetNnintSize(const uint8_t* nnint);
215
216#ifdef __cplusplus
217}
218#endif