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 | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | /** |
| 40 | * @brief BEJ schema classes. |
| 41 | */ |
| 42 | enum BejSchemaClass |
| 43 | { |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame^] | 44 | bejMajorSchemaClass = 0, |
| 45 | bejEventSchemaClass = 1, |
| 46 | bejAnnotationSchemaClass = 2, |
| 47 | bejCollectionMemberTypeSchemaClass = 3, |
| 48 | bejErrorSchemaClass = 4, |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | /** |
| 52 | * @brief BEJ data types supported in BEJ version 0xF1F0F000. |
| 53 | */ |
| 54 | enum BejPrincipalDataType |
| 55 | { |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame^] | 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 | bejPrincipalDataReserved1 = 11, |
| 68 | bejPrincipalDataReserved2 = 12, |
| 69 | bejPrincipalDataReserved3 = 13, |
| 70 | bejResourceLink = 14, |
| 71 | bejResourceLinkExpansion = 15, |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 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 | { |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame^] | 148 | rdeOpInitOperationHead = 0, |
| 149 | rdeOpInitOperationRead = 1, |
| 150 | rdeOpInitOperationCreate = 2, |
| 151 | rdeOpInitOperationDelete = 3, |
| 152 | rdeOpInitOperationUpdate = 4, |
| 153 | rdeOpInitOperationReplace = 5, |
| 154 | rdeOpInitOperationAction = 6, |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | enum RdeMultiReceiveTransferFlag |
| 158 | { |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame^] | 159 | rdeMRecFlagStart = 0, |
| 160 | rdeMRecFlagMiddle = 1, |
| 161 | rdeMRecFlagEnd = 2, |
| 162 | rdeMRecFlagStartAndEnd = 3, |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 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 | * |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame^] | 193 | * @param[in] bytes - valid pointer to a byte stream in little-endian |
| 194 | * format. |
| 195 | * @param[in] numOfBytes - number of bytes belongs to the value. Maximum |
| 196 | * number of bytes supported is 8. If numOfBytes > 8, the result is |
| 197 | * undefined. |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 198 | * @return unsigend 64bit representation of the value. |
| 199 | */ |
| 200 | uint64_t rdeGetUnsignedInteger(const uint8_t* bytes, uint8_t numOfBytes); |
| 201 | |
| 202 | /** |
| 203 | * @brief Get the value from nnint type. |
| 204 | * |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame^] | 205 | * @param[in] nnint - nnint should be pointing to a valid nnint. |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 206 | * @return unsigend 64bit representation of the value. |
| 207 | */ |
| 208 | uint64_t rdeGetNnint(const uint8_t* nnint); |
| 209 | |
| 210 | /** |
| 211 | * @brief Get the size of the complete nnint. |
| 212 | * |
kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame^] | 213 | * @param[in] nnint - pointer to a valid nnint. |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 214 | * @return size of the complete nnint. |
| 215 | */ |
| 216 | uint8_t rdeGetNnintSize(const uint8_t* nnint); |
| 217 | |
| 218 | #ifdef __cplusplus |
| 219 | } |
| 220 | #endif |