kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | |
| 5 | #ifdef __cplusplus |
| 6 | extern "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 | { |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame] | 30 | bejErrorNoError = 0, |
| 31 | bejErrorUnknown, |
| 32 | bejErrorInvalidSize, |
| 33 | bejErrorNotSuppoted, |
| 34 | bejErrorUnknownProperty, |
| 35 | bejErrorInvalidSchemaType, |
| 36 | bejErrorInvalidPropertyOffset, |
kasunath | 34a096d | 2022-05-17 11:36:14 -0700 | [diff] [blame] | 37 | bejErrorNullParameter, |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * @brief BEJ schema classes. |
| 42 | */ |
| 43 | enum BejSchemaClass |
| 44 | { |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame] | 45 | bejMajorSchemaClass = 0, |
| 46 | bejEventSchemaClass = 1, |
| 47 | bejAnnotationSchemaClass = 2, |
| 48 | bejCollectionMemberTypeSchemaClass = 3, |
| 49 | bejErrorSchemaClass = 4, |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | /** |
| 53 | * @brief BEJ data types supported in BEJ version 0xF1F0F000. |
| 54 | */ |
| 55 | enum BejPrincipalDataType |
| 56 | { |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame] | 57 | 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, |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 73 | }; |
| 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 | { |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame] | 149 | rdeOpInitOperationHead = 0, |
| 150 | rdeOpInitOperationRead = 1, |
| 151 | rdeOpInitOperationCreate = 2, |
| 152 | rdeOpInitOperationDelete = 3, |
| 153 | rdeOpInitOperationUpdate = 4, |
| 154 | rdeOpInitOperationReplace = 5, |
| 155 | rdeOpInitOperationAction = 6, |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | enum RdeMultiReceiveTransferFlag |
| 159 | { |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame] | 160 | rdeMRecFlagStart = 0, |
| 161 | rdeMRecFlagMiddle = 1, |
| 162 | rdeMRecFlagEnd = 2, |
| 163 | rdeMRecFlagStartAndEnd = 3, |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 164 | }; |
| 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 | * |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame] | 194 | * @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. |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 199 | * @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 | * |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame] | 206 | * @param[in] nnint - nnint should be pointing to a valid nnint. |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 207 | * @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 | * |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame] | 214 | * @param[in] nnint - pointer to a valid nnint. |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 215 | * @return size of the complete nnint. |
| 216 | */ |
| 217 | uint8_t rdeGetNnintSize(const uint8_t* nnint); |
| 218 | |
| 219 | #ifdef __cplusplus |
| 220 | } |
| 221 | #endif |