lwpa  0.1.0
LightWeight Platform Abstraction (lwpa)
View other versions:
lwpa_pdu

Overview

Parse or pack a generic PDU or PDU block.

#include "lwpa_pdu.h"

Modules

 lwpa_rootlayerpdu
 Parse or pack a Root Layer PDU block.
 

Data Structures

struct  LwpaPdu
 Holds state data used when parsing multiple PDUs in a PDU block. More...
 
struct  LwpaPduConstraints
 Contains specific PDU info used by the generic helper parse_pdu(). More...
 

Macros

#define pdu_length(pdu_buf)
 Get the length from the Length field of a PDU. More...
 
#define pdu_pack_normal_len(pdu_buf, length)
 Fill in the Length field of a PDU which has a length less than 4096. More...
 
#define pdu_pack_ext_len(pdu_buf, length)
 Fill in the Length field of a PDU which has a length 4096 or greater. More...
 
#define PDU_INIT
 Default LwpaPdu initializer values; must be used to intialize a struct pdu when parsing the first PDU in a block. More...
 
#define init_pdu(pduptr)
 An alternative to PDU_INIT which can be used on an existing LwpaPdu to re-initialize its values. More...
 

Typedefs

typedef struct LwpaPdu LwpaPdu
 Holds state data used when parsing multiple PDUs in a PDU block.
 
typedef struct LwpaPduConstraints LwpaPduConstraints
 Contains specific PDU info used by the generic helper parse_pdu().
 

Functions

bool parse_pdu (const uint8_t *buf, size_t buflen, const LwpaPduConstraints *constraints, LwpaPdu *pdu)
 Parse a generic PDU. More...
 

Get the inheritance and length bits in a PDU Flags & Length segment.

The first byte of each PDU contains a flags field which indicates the inheritance properties of that PDU.

For more information, see ANSI E1.17, ACN Architecture, s. 2.4.

#define l_flag_set(flags_byte)   ((bool)(flags_byte & 0x80))
 Determine whether the L flag is set in a PDU flags field. More...
 
#define v_flag_set(flags_byte)   ((bool)(flags_byte & 0x40))
 Determine whether the V flag is set in a PDU flags field. More...
 
#define h_flag_set(flags_byte)   ((bool)(flags_byte & 0x20))
 Determine whether the H flag is set in a PDU flags field. More...
 
#define d_flag_set(flags_byte)   ((bool)(flags_byte & 0x10))
 Determine whether the D flag is set in a PDU flags field. More...
 

Set the inheritance and length bits in a PDU Flags & Length segment.

The first byte of each PDU contains a flags field which indicates the inheritance properties of that PDU.

For more information, see ANSI E1.17, ACN Architecture, s. 2.4.

#define set_l_flag(flags_byte)   (flags_byte |= 0x80)
 Set the L flag in a PDU flags field. More...
 
#define set_v_flag(flags_byte)   (flags_byte |= 0x40)
 Set the V flag in a PDU flags field. More...
 
#define set_h_flag(flags_byte)   (flags_byte |= 0x20)
 Set the H flag in a PDU flags field. More...
 
#define set_d_flag(flags_byte)   (flags_byte |= 0x10)
 Set the D flag in a PDU flags field. More...
 

Macro Definition Documentation

◆ d_flag_set

#define d_flag_set (   flags_byte)    ((bool)(flags_byte & 0x10))

Determine whether the D flag is set in a PDU flags field.

Parameters
flags_byteThe first byte of the PDU.
Returns
true (the D flag is set) or false (the D flag is not set).

◆ h_flag_set

#define h_flag_set (   flags_byte)    ((bool)(flags_byte & 0x20))

Determine whether the H flag is set in a PDU flags field.

Parameters
flags_byteThe first byte of the PDU.
Returns
true (the H flag is set) or false (the H flag is not set).

◆ init_pdu

#define init_pdu (   pduptr)
Value:
do \
{ \
(pduptr)->pvector = NULL; \
(pduptr)->pheader = NULL; \
(pduptr)->pdata = NULL; \
(pduptr)->datalen = 0; \
(pduptr)->pnextpdu = NULL; \
} while (0)

An alternative to PDU_INIT which can be used on an existing LwpaPdu to re-initialize its values.

Parameters
pduptrPointer to LwpaPdu to initialize.

◆ l_flag_set

#define l_flag_set (   flags_byte)    ((bool)(flags_byte & 0x80))

Determine whether the L flag is set in a PDU flags field.

Parameters
flags_byteThe first byte of the PDU.
Returns
true (the L flag is set) or false (the L flags is not set).

◆ PDU_INIT

#define PDU_INIT
Value:
{ \
NULL, NULL, NULL, 0, NULL \
}

Default LwpaPdu initializer values; must be used to intialize a struct pdu when parsing the first PDU in a block.

◆ pdu_length

#define pdu_length (   pdu_buf)
Value:
((uint32_t)(l_flag_set(pdu_buf[0]) ? (((pdu_buf[0] & 0x0f) << 16) | (pdu_buf[1] << 8) | pdu_buf[2]) \
: (((pdu_buf[0] & 0x0f) << 8) | pdu_buf[1])))
#define l_flag_set(flags_byte)
Determine whether the L flag is set in a PDU flags field.
Definition: lwpa_pdu.h:47

Get the length from the Length field of a PDU.

Parameters
pdu_bufPointer to the start of the PDU buffer.
Returns
The length of the PDU.

◆ pdu_pack_ext_len

#define pdu_pack_ext_len (   pdu_buf,
  length 
)
Value:
do \
{ \
(pdu_buf)[0] = (((pdu_buf)[0] & 0xf0) | (((length) >> 16) & 0x0f)); \
(pdu_buf)[1] = (((length) >> 8) & 0xff); \
(pdu_buf)[2] = (length)&0xff; \
} while (0)

Fill in the Length field of a PDU which has a length 4096 or greater.

The L flag of this PDU must be set to 1.

Parameters
pdu_bufPointer to the start of the PDU buffer.
lengthLength of this PDU.

◆ pdu_pack_normal_len

#define pdu_pack_normal_len (   pdu_buf,
  length 
)
Value:
do \
{ \
(pdu_buf)[0] = (((pdu_buf)[0] & 0xf0) | (((length) >> 8) & 0x0f)); \
(pdu_buf)[1] = (length)&0xff; \
} while (0)

Fill in the Length field of a PDU which has a length less than 4096.

The L flag of this PDU must be set to 0.

Parameters
pdu_bufPointer to the start of the PDU buffer.
lengthLength of this PDU.

◆ set_d_flag

#define set_d_flag (   flags_byte)    (flags_byte |= 0x10)

Set the D flag in a PDU flags field.

Parameters
flags_byteThe first byte of the PDU.

◆ set_h_flag

#define set_h_flag (   flags_byte)    (flags_byte |= 0x20)

Set the H flag in a PDU flags field.

Parameters
flags_byteThe first byte of the PDU.

◆ set_l_flag

#define set_l_flag (   flags_byte)    (flags_byte |= 0x80)

Set the L flag in a PDU flags field.

Parameters
flags_byteThe first byte of the PDU.

◆ set_v_flag

#define set_v_flag (   flags_byte)    (flags_byte |= 0x40)

Set the V flag in a PDU flags field.

Parameters
flags_byteThe first byte of the PDU.

◆ v_flag_set

#define v_flag_set (   flags_byte)    ((bool)(flags_byte & 0x40))

Determine whether the V flag is set in a PDU flags field.

Parameters
flags_byteThe first byte of the PDU.
Returns
true (the V flag is set) or false (the V flag is not set).

Function Documentation

◆ parse_pdu()

bool parse_pdu ( const uint8_t *  buf,
size_t  buflen,
const LwpaPduConstraints constraints,
LwpaPdu pdu 
)

Parse a generic PDU.

A function to parse a generic PDU. The specific PDU info needed for parsing is contained in a struct pdu_constraints. Uses LwpaPdu to maintain state across multiple PDUs in a block.

Parameters
[in]bufByte buffer containing a PDU.
[in]buflenSize in bytes of buf.
[in]constraintsSpecific information about the PDU being parsed
[in,out]pduPDU data from the last PDU in the block. The data is used and then replaced with data from this PDU.
Returns
true (PDU was parsed successfully) or false (parse error or no more PDUs in the block).