blob: f377507e18a50edd29a652d11903ee1b091c54f1 [file] [log] [blame]
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
/**
* @brief If expr is non zero, return with that value.
*/
#ifndef RETURN_IF_IERROR
#define RETURN_IF_IERROR(expr) \
do \
{ \
int __status = (expr); \
if (__status != 0) \
{ \
return __status; \
} \
} while (0)
#endif
/**
* @brief RDE BEJ decoding errors.
*/
enum BejError
{
bejErrorNoError = 0,
bejErrorUnknown,
bejErrorInvalidSize,
bejErrorNotSuppoted,
bejErrorUnknownProperty,
bejErrorInvalidSchemaType,
bejErrorInvalidPropertyOffset,
};
/**
* @brief BEJ schema classes.
*/
enum BejSchemaClass
{
bejMajorSchemaClass = 0,
bejEventSchemaClass = 1,
bejAnnotationSchemaClass = 2,
bejCollectionMemberTypeSchemaClass = 3,
bejErrorSchemaClass = 4,
};
/**
* @brief BEJ data types supported in BEJ version 0xF1F0F000.
*/
enum BejPrincipalDataType
{
bejSet = 0,
bejArray = 1,
bejNull = 2,
bejInteger = 3,
bejEnum = 4,
bejString = 5,
bejReal = 6,
bejBoolean = 7,
bejBytestring = 8,
bejChoice = 9,
bejPropertyAnnotation = 10,
bejPrincipalDataReserved1 = 11,
bejPrincipalDataReserved2 = 12,
bejPrincipalDataReserved3 = 13,
bejResourceLink = 14,
bejResourceLinkExpansion = 15,
};
/**
* @brief Format BEJ tuple.
*/
struct BejTupleF
{
uint8_t deferredBinding : 1;
uint8_t readOnlyProperty : 1;
uint8_t nullableProperty : 1;
uint8_t reserved : 1;
enum BejPrincipalDataType principalDataType : 4;
} __attribute__((__packed__));
/**
* @brief Sequence Number BEJ tuple.
*/
struct BejTupleS
{
uint8_t schema;
// Dictionaries contain 16bit sequence numbers. So allocating 16bits for
// the sequence number here.
uint16_t sequenceNumber;
};
/**
* @brief Represent offsets of Format, Value Length and Value of a SFLV
* tuple.
*/
struct BejSFLVOffset
{
uint32_t formatOffset;
uint32_t valueLenNnintOffset;
uint32_t valueOffset;
};
/**
* @brief Fields in Bej Real data type.
*/
struct BejReal
{
// Number bytes in exp.
uint8_t expLen;
int64_t whole;
uint64_t zeroCount;
uint64_t fract;
int64_t exp;
};
/**
* @brief SFLV BEJ tuple infomation.
*/
struct BejSFLV
{
struct BejTupleS tupleS;
struct BejTupleF format;
// Value portion size in bytes.
uint32_t valueLength;
// Value end-offset with respect to the begining of the encoded stream.
uint32_t valueEndOffset;
// Pointer to the value.
const uint8_t* value;
};
/**
* @brief bejEncoding PLDM data type header.
*/
struct BejPldmBlockHeader
{
uint32_t bejVersion;
uint16_t reserved;
uint8_t schemaClass;
} __attribute__((__packed__));
enum RdeOperationInitType
{
rdeOpInitOperationHead = 0,
rdeOpInitOperationRead = 1,
rdeOpInitOperationCreate = 2,
rdeOpInitOperationDelete = 3,
rdeOpInitOperationUpdate = 4,
rdeOpInitOperationReplace = 5,
rdeOpInitOperationAction = 6,
};
enum RdeMultiReceiveTransferFlag
{
rdeMRecFlagStart = 0,
rdeMRecFlagMiddle = 1,
rdeMRecFlagEnd = 2,
rdeMRecFlagStartAndEnd = 3,
};
struct RdeOperationInitReqHeader
{
uint32_t resourceID;
uint16_t operationID;
uint8_t operationType;
// OperationFlags bits
uint8_t locatorValid : 1;
uint8_t containsRequestPayload : 1;
uint8_t containsCustomRequestParameters : 1;
uint8_t reserved : 5;
uint32_t sendDataTransferHandle;
uint8_t operationLocatorLength;
uint32_t requestPayloadLength;
} __attribute__((__packed__));
struct MultipartReceiveResHeader
{
uint8_t completionCode;
uint8_t transferFlag;
uint32_t nextDataTransferHandle;
uint32_t dataLengthBytes;
} __attribute__((__packed__));
/**
* @brief Get the unsigned integer value from provided bytes.
*
* @param[in] bytes - valid pointer to a byte stream in little-endian
* format.
* @param[in] numOfBytes - number of bytes belongs to the value. Maximum
* number of bytes supported is 8. If numOfBytes > 8, the result is
* undefined.
* @return unsigend 64bit representation of the value.
*/
uint64_t rdeGetUnsignedInteger(const uint8_t* bytes, uint8_t numOfBytes);
/**
* @brief Get the value from nnint type.
*
* @param[in] nnint - nnint should be pointing to a valid nnint.
* @return unsigend 64bit representation of the value.
*/
uint64_t rdeGetNnint(const uint8_t* nnint);
/**
* @brief Get the size of the complete nnint.
*
* @param[in] nnint - pointer to a valid nnint.
* @return size of the complete nnint.
*/
uint8_t rdeGetNnintSize(const uint8_t* nnint);
#ifdef __cplusplus
}
#endif