libptpmgmt  1.3
libptpmgmt library that provides the functionality of linuxptp pmc
Public Member Functions | Static Public Member Functions | List of all members
Message Class Reference

Handle PTP management message. More...

#include <msg.h>

Public Member Functions

 Message (const MsgParams &prms)
 
const MsgParamsgetParams () const
 
bool updateParams (const MsgParams &prms)
 
bool useAuth (const ConfigFile &cfg, const std::string &section="")
 
bool useAuth (const SaFile &sa, uint8_t spp, uint32_t key)
 
bool changeAuth (uint8_t spp, uint32_t key)
 
bool changeAuth (uint32_t key)
 
bool disableAuth ()
 
int usedAuthSppID () const
 
uint32_t usedAuthKeyID () const
 
const SaFilegetSa () const
 
bool haveAuth () const
 
mng_vals_e getTlvId () const
 
mng_vals_e getBuildTlvId () const
 
void setAllClocks ()
 
bool isAllClocks () const
 
bool useConfig (const ConfigFile &cfg, const std::string &section="")
 
bool isValidId (mng_vals_e id)
 
bool setAction (actionField_e actionField, mng_vals_e tlv_id, const BaseMngTlv *dataSend=nullptr)
 
void clearData ()
 
MNG_PARSE_ERROR_e build (void *buf, size_t bufSize, uint16_t sequence)
 
MNG_PARSE_ERROR_e build (Buf &buf, uint16_t sequence)
 
actionField_e getSendAction () const
 
size_t getMsgLen () const
 
ssize_t getMsgPlanedLen () const
 
MNG_PARSE_ERROR_e parse (const void *buf, ssize_t msgSize)
 
MNG_PARSE_ERROR_e parse (const Buf &buf, ssize_t msgSize)
 
actionField_e getReplyAction () const
 
bool isUnicast () const
 
uint8_t getPTPProfileSpecific () const
 
uint16_t getSequence () const
 
const PortIdentity_tgetPeer () const
 
const PortIdentity_tgetTarget () const
 
uint32_t getSdoId () const
 
uint8_t getDomainNumber () const
 
uint8_t getVersionPTP () const
 
uint8_t getMinorVersionPTP () const
 
const BaseMngTlvgetData () const
 
const BaseMngTlvgetSendData () const
 
managementErrorId_e getErrId () const
 
const std::string & getErrDisplay () const
 
const char * getErrDisplay_c () const
 
bool isLastMsgSig () const
 
bool isLastMsgSMPTE () const
 
msgType_e getType () const
 
tlvType_e getMngType () const
 
bool traversSigTlvs (const std::function< bool(const Message &msg, tlvType_e tlvType, const BaseSigTlv *tlv)> callback) const
 
bool traversSigTlvsCl (MessageSigTlvCallback &callback)
 
size_t getSigTlvsCount () const
 
const BaseSigTlvgetSigTlv (size_t position) const
 
tlvType_e getSigTlvType (size_t position) const
 
mng_vals_e getSigMngTlvType (size_t position) const
 
const BaseMngTlvgetSigMngTlv (size_t position) const
 

Static Public Member Functions

static const char * err2str_c (MNG_PARSE_ERROR_e err)
 
static const char * type2str_c (msgType_e type)
 
static const char * tlv2str_c (tlvType_e type)
 
static const char * act2str_c (actionField_e action)
 
static const char * mng2str_c (mng_vals_e id)
 
static const bool findMngID (const std::string &str, mng_vals_e &id, bool exact=true)
 
static const char * errId2str_c (managementErrorId_e err)
 
static const char * clkType2str_c (clockType_e type)
 
static const char * netProt2str_c (networkProtocol_e protocol)
 
static const char * clockAcc2str_c (clockAccuracy_e value)
 
static const char * faultRec2str_c (faultRecord_e code)
 
static const char * timeSrc2str_c (timeSource_e type)
 
static const bool findTimeSrc (const std::string &str, timeSource_e &type, bool exact=true)
 
static const char * portState2str_c (portState_e state)
 
static const bool findPortState (const std::string &str, portState_e &state, bool caseSens=true)
 
static const char * delayMech2str_c (delayMechanism_e type)
 
static const bool findDelayMech (const std::string &str, delayMechanism_e &type, bool exact=true)
 
static const char * smpteLck2str_c (SMPTEmasterLockingStatus_e state)
 
static const char * ts2str_c (linuxptpTimeStamp_e type)
 
static const char * pwr2str_c (linuxptpPowerProfileVersion_e ver)
 
static const char * us2str_c (linuxptpUnicastState_e state)
 
static bool is_LI_61 (uint8_t flags)
 
static bool is_LI_59 (uint8_t flags)
 
static bool is_UTCV (uint8_t flags)
 
static bool is_PTP (uint8_t flags)
 
static bool is_TTRA (uint8_t flags)
 
static bool is_FTRA (uint8_t flags)
 
static bool isEmpty (mng_vals_e id)
 

Detailed Description

Handle PTP management message.

Handle parse and build of a PTP management massage. Handle TLV specific dataField by calling a specific call-back per TLV id

Constructor & Destructor Documentation

◆ Message()

Message::Message ( const MsgParams prms)

Construct a new object using the user MsgParams parameters

Parameters
[in]prmsMsgParams parameters
Note
you may use the parameters from a different message object

Member Function Documentation

◆ act2str_c()

static const char* Message::act2str_c ( actionField_e  action)
static

Convert action to string

Parameters
[in]action
Returns
string with the action in a string

◆ build() [1/2]

MNG_PARSE_ERROR_e Message::build ( Buf buf,
uint16_t  sequence 
)
inline

Build a raw message for send based on last setAction call

Parameters
[in,out]bufobject with memory buffer to fill with raw PTP Message
[in]sequencemessage sequence
Returns
parse error state
Note
build before setting with setAction will create a GET raw message with NULL_PTP_MANAGEMENT management TLV
usually the user increases the sequence so it can be compared with replied message
if raw message is larger than buffer size the function return MNG_PARSE_ERROR_TOO_SMALL

◆ build() [2/2]

MNG_PARSE_ERROR_e Message::build ( void *  buf,
size_t  bufSize,
uint16_t  sequence 
)

Build a raw message for send using setAction setting

Parameters
[in,out]bufmemory buffer to fill with raw PTP Message
[in]bufSizebuffer size
[in]sequencemessage sequence
Returns
parse error state
Note
build before setting with setAction will create a GET raw message with NULL_PTP_MANAGEMENT management TLV
usually the user increases the sequence so it can be compared with replied message
if raw message is larger than buffer size the function return MNG_PARSE_ERROR_TOO_SMALL

◆ changeAuth() [1/2]

bool Message::changeAuth ( uint32_t  key)

Change the send key used in the AUTHENTICATION TLVs

Parameters
[in]keyID to use to send
Returns
true if change success

◆ changeAuth() [2/2]

bool Message::changeAuth ( uint8_t  spp,
uint32_t  key 
)

Change the spp and send key used in the AUTHENTICATION TLVs

Parameters
[in]sppID to use to send
[in]keyID to use to send
Returns
true if change success

◆ clearData()

void Message::clearData ( )

Clear data for send, prevent accidentally use, in case it is freed

◆ clkType2str_c()

static const char* Message::clkType2str_c ( clockType_e  type)
static

Convert clock type to string

Parameters
[in]typeclock type
Returns
string with the clock type

◆ clockAcc2str_c()

static const char* Message::clockAcc2str_c ( clockAccuracy_e  value)
static

Convert clock accuracy to string

Parameters
[in]valueclock accuracy
Returns
string with the clock accuracy

◆ delayMech2str_c()

static const char* Message::delayMech2str_c ( delayMechanism_e  type)
static

Convert delay mechanism to string

Parameters
[in]typedelay mechanism
Returns
string with a delay mechanism type

◆ disableAuth()

bool Message::disableAuth ( )
inline

Disable the use of AUTHENTICATION TLV

Returns
true if disabled

◆ err2str_c()

static const char* Message::err2str_c ( MNG_PARSE_ERROR_e  err)
static

Convert parse error code to string

Parameters
[in]errparse code
Returns
string with the error message

◆ errId2str_c()

static const char* Message::errId2str_c ( managementErrorId_e  err)
static

Convert management error to string

Parameters
[in]errID
Returns
string with the error message

◆ faultRec2str_c()

static const char* Message::faultRec2str_c ( faultRecord_e  code)
static

Convert fault record severity code to string

Parameters
[in]codeseverity code
Returns
string with the severity code

◆ findDelayMech()

static const bool Message::findDelayMech ( const std::string &  str,
delayMechanism_e type,
bool  exact = true 
)
static

Convert string to delay mechanism

Parameters
[in]strstring to search
[out]typedelay mechanism
[in]exactperform an exact match
Returns
true if found

◆ findMngID()

static const bool Message::findMngID ( const std::string &  str,
mng_vals_e id,
bool  exact = true 
)
static

Convert string to management id

Parameters
[in]strstring to search
[out]idparse code
[in]exactperform an exact match
Returns
true if found

◆ findPortState()

static const bool Message::findPortState ( const std::string &  str,
portState_e state,
bool  caseSens = true 
)
static

Convert string to port state

Parameters
[in]strstring to search
[out]stateport state
[in]caseSensperform case sensetive match
Returns
true if found

◆ findTimeSrc()

static const bool Message::findTimeSrc ( const std::string &  str,
timeSource_e type,
bool  exact = true 
)
static

Convert string to time source type

Parameters
[in]strstring to search
[out]typetime source
[in]exactperform an exact match
Returns
true if found

◆ getBuildTlvId()

mng_vals_e Message::getBuildTlvId ( ) const
inline

Get the current build TLV id

Returns
current TLV id

◆ getData()

const BaseMngTlv* Message::getData ( ) const
inline

Get last parsed message dataField

Returns
pointer to last parsed message dataField or null
Note
You need to cast to proper structure depends on management TLV ID, get with.
You should not try to free or change this TLV object

◆ getDomainNumber()

uint8_t Message::getDomainNumber ( ) const
inline

Get last parsed message domainNumber

Returns
parsed message domainNumber

◆ getErrDisplay()

const std::string& Message::getErrDisplay ( ) const
inline

Get management error message Relevant only when parsed message return MNG_PARSE_ERROR_MSG

Returns
error message

◆ getErrDisplay_c()

const char* Message::getErrDisplay_c ( ) const
inline

Get management error message Relevant only when parsed message return MNG_PARSE_ERROR_MSG

Returns
error message

◆ getErrId()

managementErrorId_e Message::getErrId ( ) const
inline

Get management error code ID Relevant only when parsed message return MNG_PARSE_ERROR_MSG

Returns
error code

◆ getMinorVersionPTP()

uint8_t Message::getMinorVersionPTP ( ) const
inline

Get last parsed message minor PTP version

Returns
parsed message versionPTP

◆ getMngType()

tlvType_e Message::getMngType ( ) const
inline

Get management message type

Returns
management message type
Note
return MANAGEMENT or MANAGEMENT_ERROR_STATUS

◆ getMsgLen()

size_t Message::getMsgLen ( ) const
inline

Get last build message size

Returns
message size

◆ getMsgPlanedLen()

ssize_t Message::getMsgPlanedLen ( ) const

Get planned message to build size

Returns
planned message size or negative for error
Note
the planned message size is based on the management TLV id, action and the dataSend set by the user. You can use the size to allocate proper buffer for sending. Add Authentication TLV size if used.

◆ getParams()

const MsgParams& Message::getParams ( ) const
inline

Get the current msgparams parameters

Returns
msgparams parameters

◆ getPeer()

const PortIdentity_t& Message::getPeer ( ) const
inline

Get last parsed message peer port ID

Returns
parsed message peer port ID

◆ getPTPProfileSpecific()

uint8_t Message::getPTPProfileSpecific ( ) const
inline

Get last reply PTP Profile Specific

Returns
reply management action
Note
set on parse

◆ getReplyAction()

actionField_e Message::getReplyAction ( ) const
inline

Get last reply management action

Returns
reply management action
Note
set on parse

◆ getSa()

const SaFile& Message::getSa ( ) const
inline

Get authentication security association pool

Returns
authentication parameters

◆ getSdoId()

uint32_t Message::getSdoId ( ) const
inline

Get last parsed message sdoId

Returns
parsed message sdoId
Note
upper byte is was transportSpecific

◆ getSendAction()

actionField_e Message::getSendAction ( ) const
inline

Get build management action

Returns
build management action

◆ getSendData()

const BaseMngTlv* Message::getSendData ( ) const
inline

Get send message dataField

Returns
pointer to send message dataField or null
Note
You need to cast to proper structure depends on management TLV ID.
In case you release this memory, you should call
void clearData()

◆ getSequence()

uint16_t Message::getSequence ( ) const
inline

Get last parsed message sequence number

Returns
parsed sequence number

◆ getSigMngTlv()

const BaseMngTlv* Message::getSigMngTlv ( size_t  position) const

Get a management TLV from the last signalling message TLVs by position

Parameters
[in]positionof TLV
Returns
management TLV or null
Note
return null if TLV is not management
You should not try to free this TLV object

◆ getSigMngTlvType()

mng_vals_e Message::getSigMngTlvType ( size_t  position) const

Get the management TLV ID of a management TLV from the last signalling message TLVs by position

Parameters
[in]positionof TLV
Returns
management TLV ID or NULL_PTP_MANAGEMENT
Note
return NULL_PTP_MANAGEMENT if TLV is not management

◆ getSigTlv()

const BaseSigTlv* Message::getSigTlv ( size_t  position) const

Get a TLV from the last signalling message TLVs by position

Parameters
[in]positionof TLV
Returns
TLV or null

◆ getSigTlvsCount()

size_t Message::getSigTlvsCount ( ) const

Get number of the last signalling message TLVs

Returns
number of TLVs or zero

◆ getSigTlvType()

tlvType_e Message::getSigTlvType ( size_t  position) const

Get a type of TLV from the last signalling message TLVs by position

Parameters
[in]positionof TLV
Returns
type of TLV or unknown

◆ getTarget()

const PortIdentity_t& Message::getTarget ( ) const
inline

Get last parsed message target port ID

Returns
parsed message target port ID

◆ getTlvId()

mng_vals_e Message::getTlvId ( ) const
inline

Get the current parsed TLV id

Returns
current parsed TLV id

◆ getType()

msgType_e Message::getType ( ) const
inline

Get message type

Returns
message type

◆ getVersionPTP()

uint8_t Message::getVersionPTP ( ) const
inline

Get last parsed message PTP version

Returns
parsed message versionPTP

◆ haveAuth()

bool Message::haveAuth ( ) const
inline

Get if AUTHENTICATION TLV with authentication parameters are used

Returns
true if AUTHENTICATION TLV is used

◆ is_FTRA()

static bool Message::is_FTRA ( uint8_t  flags)
inlinestatic

Check if frequency is traceable flag is enabled

Parameters
[in]flags
Returns
true if flag on

◆ is_LI_59()

static bool Message::is_LI_59 ( uint8_t  flags)
inlinestatic

Check if leap 59 seconds flag is enabled

Parameters
[in]flags
Returns
true if flag on

◆ is_LI_61()

static bool Message::is_LI_61 ( uint8_t  flags)
inlinestatic

Check if leap 61 seconds flag is enabled

Parameters
[in]flags
Returns
true if flag on

◆ is_PTP()

static bool Message::is_PTP ( uint8_t  flags)
inlinestatic

Check if is PTP instance flag is enabled

Parameters
[in]flags
Returns
true if flag on

◆ is_TTRA()

static bool Message::is_TTRA ( uint8_t  flags)
inlinestatic

Check if timescale is traceable flag is enabled

Parameters
[in]flags
Returns
true if flag on

◆ is_UTCV()

static bool Message::is_UTCV ( uint8_t  flags)
inlinestatic

Check if UTC offset is valid flag is enabled

Parameters
[in]flags
Returns
true if flag on

◆ isAllClocks()

bool Message::isAllClocks ( ) const

Query if target clock ID is using all clocks.

Returns
true if target use all clocks

◆ isEmpty()

static bool Message::isEmpty ( mng_vals_e  id)
static

Check management TLV id uses empty dataField

Parameters
[in]idmanagement TLV id
Returns
true if dataField is empty

◆ isLastMsgSig()

bool Message::isLastMsgSig ( ) const
inline

query if last message is a signalling message

Returns
true if last message is a signalling message

◆ isLastMsgSMPTE()

bool Message::isLastMsgSMPTE ( ) const

query if last message is a SMPTE message

Returns
true if last message is a SMPTE message

◆ isUnicast()

bool Message::isUnicast ( ) const
inline

Is last parsed message a unicast or not

Returns
true if parsed message is unicast

◆ isValidId()

bool Message::isValidId ( mng_vals_e  id)

Check if management TLV is valid for use

Parameters
[in]idmanagement TLV id
Returns
true if management TLV is valid
Note
function also check implement specific TLVs!

◆ mng2str_c()

static const char* Message::mng2str_c ( mng_vals_e  id)
static

Convert management id to string

Parameters
[in]idparse code
Returns
string with ID name

◆ netProt2str_c()

static const char* Message::netProt2str_c ( networkProtocol_e  protocol)
static

Convert network protocol to string

Parameters
[in]protocolnetwork protocol
Returns
string with the network protocol

◆ parse() [1/2]

MNG_PARSE_ERROR_e Message::parse ( const Buf buf,
ssize_t  msgSize 
)

Parse a received raw socket

Parameters
[in]bufobject with memory buffer containing the raw PTP Message
[in]msgSizereceived size of PTP Message
Returns
parse error state

◆ parse() [2/2]

MNG_PARSE_ERROR_e Message::parse ( const void *  buf,
ssize_t  msgSize 
)

Parse a received raw socket

Parameters
[in]bufmemory buffer containing the raw PTP Message
[in]msgSizereceived size of PTP Message
Returns
parse error state

◆ portState2str_c()

static const char* Message::portState2str_c ( portState_e  state)
static

Convert port state to string

Parameters
[in]stateport state
Returns
string with the port state

◆ pwr2str_c()

static const char* Message::pwr2str_c ( linuxptpPowerProfileVersion_e  ver)
static

Convert linuxptp power profile version to string

Parameters
[in]verversion
Returns
string with the Linux power profile version

◆ setAction()

bool Message::setAction ( actionField_e  actionField,
mng_vals_e  tlv_id,
const BaseMngTlv dataSend = nullptr 
)

Set message object management TLV id, action and data for dataField

Parameters
[in]actionFieldfor sending
[in]tlv_idmanagement TLV id
[in]dataSendpointer to TLV object
Returns
true if setting is correct
Note
the setting is valid for send only
Attention
The caller must use the proper structure with the TLV id! Mismatch will probably cause a crash to your application. The library does NOT perform any error catchig of any kind!

◆ setAllClocks()

void Message::setAllClocks ( )

Set target clock ID to use all clocks.

◆ smpteLck2str_c()

static const char* Message::smpteLck2str_c ( SMPTEmasterLockingStatus_e  state)
static

Convert SMPTE clock locking state to string

Parameters
[in]stateSMPTE clock locking state
Returns
string with the SMPTE clock locking state

◆ timeSrc2str_c()

static const char* Message::timeSrc2str_c ( timeSource_e  type)
static

Convert time source to string

Parameters
[in]typetime source
Returns
string with the time source

◆ tlv2str_c()

static const char* Message::tlv2str_c ( tlvType_e  type)
static

Convert TLV type to string

Parameters
[in]type
Returns
string with the TLV type

◆ traversSigTlvs()

bool Message::traversSigTlvs ( const std::function< bool(const Message &msg, tlvType_e tlvType, const BaseSigTlv *tlv)>  callback) const

Traverse all last signalling message TLVs

Parameters
[in]callbackfunction to call with each TLV
Returns
true if any of the calling to call-back return true
Note
stop if any of the calling to call-back return true

◆ traversSigTlvsCl()

bool Message::traversSigTlvsCl ( MessageSigTlvCallback callback)

Traverse all last signalling message TLVs

Parameters
[in]callbackobject with callback to be called with each TLV
Returns
true if any of the calling to call-back return true
Note
stop if any of the calling to call-back return true
Available for PHP, Perl, Python and Ruby use

◆ ts2str_c()

static const char* Message::ts2str_c ( linuxptpTimeStamp_e  type)
static

Convert linuxptp time stamp type to string

Parameters
[in]typetime stamp type
Returns
string with the Linux time stamp type

◆ type2str_c()

static const char* Message::type2str_c ( msgType_e  type)
static

Convert message type to string

Parameters
[in]type
Returns
string with the TLV type

◆ updateParams()

bool Message::updateParams ( const MsgParams prms)

Set and use a user MsgParams parameters

Parameters
[in]prmsMsgParams parameters
Returns
true if parameters are valid and updated

◆ us2str_c()

static const char* Message::us2str_c ( linuxptpUnicastState_e  state)
static

Convert linuxptp master unicasy state to string

Parameters
[in]state
Returns
string with the master state in the unicast master table

◆ useAuth() [1/2]

bool Message::useAuth ( const ConfigFile cfg,
const std::string &  section = "" 
)

Use the AUTHENTICATION TLV on send and receive read parameters from configuration file.

Parameters
[in]cfgreference to configuration file object
[in]sectionin configuration file
Returns
true if find valid authentication parameters and hmac library

◆ useAuth() [2/2]

bool Message::useAuth ( const SaFile sa,
uint8_t  spp,
uint32_t  key 
)

Use the AUTHENTICATION TLV on send and receive, read SA file.

Parameters
[in]sareference to SA file object
[in]sppID to use to send
[in]keyID to use to send
Returns
true if find valid authentication parameters and hmac library

◆ useConfig()

bool Message::useConfig ( const ConfigFile cfg,
const std::string &  section = "" 
)

Fetch MsgParams parameters from configuration file

Parameters
[in]cfgreference to configuration file object
[in]sectionin configuration file
Returns
true on success
Note
calling without section will fetch value from "global" section

◆ usedAuthKeyID()

uint32_t Message::usedAuthKeyID ( ) const
inline

Get used AUTHENTICATION TLV key ID used for send

Returns
key ID or 0

◆ usedAuthSppID()

int Message::usedAuthSppID ( ) const
inline

Get used AUTHENTICATION TLV Spp ID used for send

Returns
Spp ID or -1

The documentation for this class was generated from the following file: