Commit 74da3f32 authored by Aurelio Colosimo's avatar Aurelio Colosimo

integration of msg.c src file, containing function for message handling

parent 86c25f77
......@@ -27,6 +27,11 @@ int pp_memcmp(void *s1, const void *s2, int count)
return memcmp(s1, s2, count);
}
void *pp_memset(void *s, int c, int count)
{
return memset(s, c, count);
}
void pp_get_stamp(uint32_t *sptr)
{
*sptr = htonl(time(NULL));
......
......@@ -31,6 +31,7 @@ int main(int argc, char **argv)
if (!ppi)
exit(__LINE__);
ppi->sent_seq_id = calloc(16, sizeof(*ppi->sent_seq_id));
ppi->defaultDS = calloc(1, sizeof(*ppi->defaultDS));
ppi->currentDS = calloc(1, sizeof(*ppi->currentDS));
ppi->parentDS = calloc(1, sizeof(*ppi->parentDS));
......@@ -38,7 +39,8 @@ int main(int argc, char **argv)
ppi->timePropertiesDS = calloc(1, sizeof(*ppi->timePropertiesDS));
if ((!ppi->defaultDS) || (!ppi->currentDS) || (!ppi->parentDS)
|| (!ppi->portDS) || (!ppi->timePropertiesDS))
|| (!ppi->portDS) || (!ppi->timePropertiesDS) || (!ppi->sent_seq_id)
)
exit(__LINE__);
if (posix_open_ch(ppi, ifname)) {
......
......@@ -15,5 +15,6 @@ extern void pp_puts(const char *s);
extern int pp_strnlen(const char *s, int maxlen);
extern void *pp_memcpy(void *d, const void *s, int count);
extern int pp_memcmp(void *s1, const void *s2, int count);
extern void *pp_memset(void *s, int c, int count);
#endif /* __PTP_DEP_H__ */
......@@ -42,4 +42,15 @@
#define PP_TWO_STEP_FLAG 2
#define PP_VERSION_PTP 2
#define PP_HEADER_LENGTH 34
#define PP_ANNOUNCE_LENGTH 64
#define PP_SYNC_LENGTH 44
#define PP_FOLLOW_UP_LENGTH 44
#define PP_PDELAY_REQ_LENGTH 54
#define PP_DELAY_REQ_LENGTH 44
#define PP_DELAY_RESP_LENGTH 54
#define PP_PDELAY_RESP_LENGTH 54
#define PP_PDELAY_RESP_FOLLOW_UP_LENGTH 54
#define PP_MANAGEMENT_LENGTH 48
#endif /* __PTP_CONSTANTS_H__ */
......@@ -108,13 +108,13 @@ struct pp_instance {
DSTimeProperties *timePropertiesDS;
struct pp_timer *timers[PP_TIMER_ARRAY_SIZE];
/* FIXME: check the variables below. Now inherited from ptpd src*/
/* FIXME: check the variables from now on. Now inherited from ptpd src*/
UInteger16 number_foreign_records;
Integer16 max_foreign_records;
Integer16 foreign_record_i;
Integer16 foreign_record_best;
Boolean record_update;
MsgHeader msg_tmp_header;
union {
MsgSync sync;
MsgFollowUp follow;
......@@ -127,6 +127,11 @@ struct pp_instance {
MsgAnnounce announce;
MsgSignaling signaling;
} msg_tmp;
UInteger16 *sent_seq_id; /* sequence id of the last message sent of the
* same type
*/
MsgHeader msg_tmp_header;
MsgHeader pdelay_req_hdr;
};
......@@ -150,8 +155,11 @@ extern int pp_net_init(struct pp_instance *ppi);
extern int pp_net_shutdown(struct pp_instance *ppi);
extern int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len);
extern int pp_send_packet(struct pp_instance *ppi, void *pkt, int len);
extern UInteger32 pp_htonl(UInteger32 hostlong);
extern UInteger16 pp_htons(UInteger16 hostlong);
/* Timers */
extern int pp_timer_init(struct pp_instance *ppi); /* initializes timer common
structure */
extern int pp_timer_start(struct pp_timer *tm);
......
......@@ -18,6 +18,7 @@ OBJ-libstd := $D/state-table-default.o \
$D/state-uncalibrated.o \
$D/state-slave.o \
$D/bmc.o \
$D/msg.o \
$D/open-close.o
$(TARGET).o: $(LIBSTD)
......
/**
* @file msg.c
* @author George Neville-Neil <gnn@neville-neil.com>
* @date Tue Jul 20 16:17:05 2010
*
* @brief Functions to pack and unpack messages.
*
* See spec annex d
/*
* FIXME header
*/
#include "../ptpd.h"
#include <pproto/pproto.h>
#include <dep/dep.h>
/*Unpack Header from IN buffer to msgTmpHeader field */
void
msgUnpackHeader(void *buf, MsgHeader * header)
/* Unpack header from in buffer to msg_tmp_header field */
void msg_unpack_header(void *buf, MsgHeader *hdr)
{
header->transportSpecific = (*(Nibble *) (buf + 0)) >> 4;
header->messageType = (*(Enumeration4 *) (buf + 0)) & 0x0F;
header->versionPTP = (*(UInteger4 *) (buf + 1)) & 0x0F;
/* force reserved bit to zero if not */
header->messageLength = flip16(*(UInteger16 *) (buf + 2));
header->domainNumber = (*(UInteger8 *) (buf + 4));
memcpy(header->flagField, (buf + 6), FLAG_FIELD_LENGTH);
memcpy(&header->correctionfield.msb, (buf + 8), 4);
memcpy(&header->correctionfield.lsb, (buf + 12), 4);
header->correctionfield.msb = flip32(header->correctionfield.msb);
header->correctionfield.lsb = flip32(header->correctionfield.lsb);
memcpy(header->sourcePortIdentity.clockIdentity, (buf + 20),
CLOCK_IDENTITY_LENGTH);
header->sourcePortIdentity.portNumber =
flip16(*(UInteger16 *) (buf + 28));
header->sequenceId = flip16(*(UInteger16 *) (buf + 30));
header->controlField = (*(UInteger8 *) (buf + 32));
header->logMessageInterval = (*(Integer8 *) (buf + 33));
hdr->transportSpecific = (*(Nibble *) (buf + 0)) >> 4;
hdr->messageType = (*(Enumeration4 *) (buf + 0)) & 0x0F;
hdr->versionPTP = (*(UInteger4 *) (buf + 1)) & 0x0F;
/* force reserved bit to zero if not */
hdr->messageLength = pp_htons(*(UInteger16 *) (buf + 2));
hdr->domainNumber = (*(UInteger8 *) (buf + 4));
/* pp_memcpy(hdr->flagField, (buf + 6), FIXME:FLAG_FIELD_LENGTH); */
pp_memcpy(&hdr->correctionfield.msb, (buf + 8), 4);
pp_memcpy(&hdr->correctionfield.lsb, (buf + 12), 4);
hdr->correctionfield.msb = pp_htonl(hdr->correctionfield.msb);
hdr->correctionfield.lsb = pp_htonl(hdr->correctionfield.lsb);
pp_memcpy(hdr->sourcePortIdentity.clockIdentity, (buf + 20),
PP_CLOCK_IDENTITY_LENGTH);
hdr->sourcePortIdentity.portNumber =
pp_htons(*(UInteger16 *) (buf + 28));
hdr->sequenceId = pp_htons(*(UInteger16 *) (buf + 30));
hdr->controlField = (*(UInteger8 *) (buf + 32));
hdr->logMessageInterval = (*(Integer8 *) (buf + 33));
/* FIXME: diag
#ifdef PTPD_DBG
msgHeader_display(header);
#endif /* PTPD_DBG */
#endif
*/
}
/*Pack header message into OUT buffer of ptpClock*/
void
msgPackHeader(void *buf, PtpClock * ptpClock)
/* Pack header message into out buffer of ppi */
void msg_pack_header(void *buf, struct pp_instance *ppi)
{
Nibble transport = 0x80;
/* (spec annex D) */
*(UInteger8 *) (buf + 0) = transport;
*(UInteger4 *) (buf + 1) = ptpClock->versionNumber;
*(UInteger8 *) (buf + 4) = ptpClock->domainNumber;
*(UInteger4 *) (buf + 1) = DSPOR(ppi)->versionNumber;
*(UInteger8 *) (buf + 4) = DSDEF(ppi)->domainNumber;
if (ptpClock->twoStepFlag)
*(UInteger8 *) (buf + 6) = TWO_STEP_FLAG;
if (DSDEF(ppi)->twoStepFlag)
*(UInteger8 *) (buf + 6) = PP_TWO_STEP_FLAG;
memset((buf + 8), 0, 8);
memcpy((buf + 20), ptpClock->portIdentity.clockIdentity,
CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 28) = flip16(ptpClock->portIdentity.portNumber);
pp_memset((buf + 8), 0, 8);
pp_memcpy((buf + 20), DSPOR(ppi)->portIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 28) =
pp_htons(DSPOR(ppi)->portIdentity.portNumber);
*(UInteger8 *) (buf + 33) = 0x7F;
/* Default value(spec Table 24) */
}
/*Pack SYNC message into OUT buffer of ptpClock*/
void
msgPackSync(void *buf, Timestamp * originTimestamp, PtpClock * ptpClock)
/* Pack Sync message into out buffer of ppi */
void msg_pack_sync(void *buf, Timestamp * orig_tstamp, struct pp_instance *ppi)
{
/* changes in header */
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
/* RAZ messageType */
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x00;
/* Table 19 */
*(UInteger16 *) (buf + 2) = flip16(SYNC_LENGTH);
*(UInteger16 *) (buf + 30) = flip16(ptpClock->sentSyncSequenceId);
*(UInteger16 *) (buf + 2) = pp_htons(PP_SYNC_LENGTH);
*(UInteger16 *) (buf + 30) = pp_htons(ppi->sent_seq_id[PPM_SYNC]);
*(UInteger8 *) (buf + 32) = 0x00;
/* Table 23 */
*(Integer8 *) (buf + 33) = ptpClock->logSyncInterval;
memset((buf + 8), 0, 8);
*(Integer8 *) (buf + 33) = DSPOR(ppi)->logSyncInterval;
pp_memset((buf + 8), 0, 8);
/* Sync message */
*(UInteger16 *) (buf + 34) = flip16(originTimestamp->secondsField.msb);
*(UInteger32 *) (buf + 36) = flip32(originTimestamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) = flip32(originTimestamp->nanosecondsField);
*(UInteger16 *) (buf + 34) = pp_htons(orig_tstamp->secondsField.msb);
*(UInteger32 *) (buf + 36) = pp_htonl(orig_tstamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) = pp_htonl(orig_tstamp->nanosecondsField);
}
/*Unpack Sync message from IN buffer */
void
msgUnpackSync(void *buf, MsgSync * sync)
/* Unpack Sync message from in buffer */
void msg_unpack_sync(void *buf, MsgSync *sync)
{
sync->originTimestamp.secondsField.msb =
flip16(*(UInteger16 *) (buf + 34));
pp_htons(*(UInteger16 *) (buf + 34));
sync->originTimestamp.secondsField.lsb =
flip32(*(UInteger32 *) (buf + 36));
pp_htonl(*(UInteger32 *) (buf + 36));
sync->originTimestamp.nanosecondsField =
flip32(*(UInteger32 *) (buf + 40));
pp_htonl(*(UInteger32 *) (buf + 40));
/* FIXME: diag
#ifdef PTPD_DBG
msgSync_display(sync);
#endif /* PTPD_DBG */
#endif
*/
}
/*Pack Announce message into OUT buffer of ptpClock*/
void
msgPackAnnounce(void *buf, PtpClock * ptpClock)
/* Pack Announce message into out buffer of ppi */
void msg_pack_announce(void *buf, struct pp_instance *ppi)
{
/* changes in header */
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
/* RAZ messageType */
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x0B;
/* Table 19 */
*(UInteger16 *) (buf + 2) = flip16(ANNOUNCE_LENGTH);
*(UInteger16 *) (buf + 30) = flip16(ptpClock->sentAnnounceSequenceId);
*(UInteger16 *) (buf + 2) = pp_htons(PP_ANNOUNCE_LENGTH);
*(UInteger16 *) (buf + 30) = pp_htons(ppi->sent_seq_id[PPM_ANNOUNCE]);
*(UInteger8 *) (buf + 32) = 0x05;
/* Table 23 */
*(Integer8 *) (buf + 33) = ptpClock->logAnnounceInterval;
*(Integer8 *) (buf + 33) = DSPOR(ppi)->logAnnounceInterval;
/* Announce message */
memset((buf + 34), 0, 10);
*(Integer16 *) (buf + 44) = flip16(ptpClock->currentUtcOffset);
*(UInteger8 *) (buf + 47) = ptpClock->grandmasterPriority1;
*(UInteger8 *) (buf + 48) = ptpClock->clockQuality.clockClass;
*(Enumeration8 *) (buf + 49) = ptpClock->clockQuality.clockAccuracy;
pp_memset((buf + 34), 0, 10);
*(Integer16 *) (buf + 44) = pp_htons(DSPRO(ppi)->currentUtcOffset);
*(UInteger8 *) (buf + 47) = DSPAR(ppi)->grandmasterPriority1;
*(UInteger8 *) (buf + 48) = DSDEF(ppi)->clockQuality.clockClass;
*(Enumeration8 *) (buf + 49) = DSDEF(ppi)->clockQuality.clockAccuracy;
*(UInteger16 *) (buf + 50) =
flip16(ptpClock->clockQuality.offsetScaledLogVariance);
*(UInteger8 *) (buf + 52) = ptpClock->grandmasterPriority2;
memcpy((buf + 53), ptpClock->grandmasterIdentity, CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 61) = flip16(ptpClock->stepsRemoved);
*(Enumeration8 *) (buf + 63) = ptpClock->timeSource;
pp_htons(DSDEF(ppi)->clockQuality.offsetScaledLogVariance);
*(UInteger8 *) (buf + 52) = DSPAR(ppi)->grandmasterPriority2;
pp_memcpy((buf + 53), DSPAR(ppi)->grandmasterIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 61) = pp_htons(DSCUR(ppi)->stepsRemoved);
*(Enumeration8 *) (buf + 63) = DSPRO(ppi)->timeSource;
}
/*Unpack Announce message from IN buffer of ptpClock to msgtmp.Announce*/
void
msgUnpackAnnounce(void *buf, MsgAnnounce * announce)
/* Unpack Announce message from in buffer of ppi to msgtmp. Announce */
void msg_unpack_announce(void *buf, MsgAnnounce *ann)
{
announce->originTimestamp.secondsField.msb =
flip16(*(UInteger16 *) (buf + 34));
announce->originTimestamp.secondsField.lsb =
flip32(*(UInteger32 *) (buf + 36));
announce->originTimestamp.nanosecondsField =
flip32(*(UInteger32 *) (buf + 40));
announce->currentUtcOffset = flip16(*(UInteger16 *) (buf + 44));
announce->grandmasterPriority1 = *(UInteger8 *) (buf + 47);
announce->grandmasterClockQuality.clockClass =
ann->originTimestamp.secondsField.msb =
pp_htons(*(UInteger16 *) (buf + 34));
ann->originTimestamp.secondsField.lsb =
pp_htonl(*(UInteger32 *) (buf + 36));
ann->originTimestamp.nanosecondsField =
pp_htonl(*(UInteger32 *) (buf + 40));
ann->currentUtcOffset = pp_htons(*(UInteger16 *) (buf + 44));
ann->grandmasterPriority1 = *(UInteger8 *) (buf + 47);
ann->grandmasterClockQuality.clockClass =
*(UInteger8 *) (buf + 48);
announce->grandmasterClockQuality.clockAccuracy =
ann->grandmasterClockQuality.clockAccuracy =
*(Enumeration8 *) (buf + 49);
announce->grandmasterClockQuality.offsetScaledLogVariance =
flip16(*(UInteger16 *) (buf + 50));
announce->grandmasterPriority2 = *(UInteger8 *) (buf + 52);
memcpy(announce->grandmasterIdentity, (buf + 53),
CLOCK_IDENTITY_LENGTH);
announce->stepsRemoved = flip16(*(UInteger16 *) (buf + 61));
announce->timeSource = *(Enumeration8 *) (buf + 63);
ann->grandmasterClockQuality.offsetScaledLogVariance =
pp_htons(*(UInteger16 *) (buf + 50));
ann->grandmasterPriority2 = *(UInteger8 *) (buf + 52);
pp_memcpy(ann->grandmasterIdentity, (buf + 53),
PP_CLOCK_IDENTITY_LENGTH);
ann->stepsRemoved = pp_htons(*(UInteger16 *) (buf + 61));
ann->timeSource = *(Enumeration8 *) (buf + 63);
/* FIXME: diag
#ifdef PTPD_DBG
msgAnnounce_display(announce);
#endif /* PTPD_DBG */
#endif
*/
}
/*pack Follow_up message into OUT buffer of ptpClock*/
void
msgPackFollowUp(void *buf, Timestamp * preciseOriginTimestamp, PtpClock * ptpClock)
/* Pack Follow Up message into out buffer of ppi*/
void msg_pack_follow_up(void *buf, Timestamp *prec_orig_tstamp,
struct pp_instance *ppi)
{
/* changes in header */
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
/* RAZ messageType */
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x08;
/* Table 19 */
*(UInteger16 *) (buf + 2) = flip16(FOLLOW_UP_LENGTH);
*(UInteger16 *) (buf + 30) = flip16(ptpClock->sentSyncSequenceId - 1);
*(UInteger16 *) (buf + 2) = pp_htons(PP_FOLLOW_UP_LENGTH);
*(UInteger16 *) (buf + 30) = pp_htons(ppi->sent_seq_id[PPM_SYNC] - 1);
/* sentSyncSequenceId has already been incremented in "issueSync" */
*(UInteger8 *) (buf + 32) = 0x02;
/* Table 23 */
*(Integer8 *) (buf + 33) = ptpClock->logSyncInterval;
*(Integer8 *) (buf + 33) = DSPOR(ppi)->logSyncInterval;
/* Follow_up message */
/* Follow Up message */
*(UInteger16 *) (buf + 34) =
flip16(preciseOriginTimestamp->secondsField.msb);
pp_htons(prec_orig_tstamp->secondsField.msb);
*(UInteger32 *) (buf + 36) =
flip32(preciseOriginTimestamp->secondsField.lsb);
pp_htonl(prec_orig_tstamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) =
flip32(preciseOriginTimestamp->nanosecondsField);
pp_htonl(prec_orig_tstamp->nanosecondsField);
}
/*Unpack Follow_up message from IN buffer of ptpClock to msgtmp.follow*/
void
msgUnpackFollowUp(void *buf, MsgFollowUp * follow)
/* Unpack FollowUp message from in buffer of ppi to msgtmp.follow */
void msg_unpack_follow_up(void *buf, MsgFollowUp *flwup)
{
follow->preciseOriginTimestamp.secondsField.msb =
flip16(*(UInteger16 *) (buf + 34));
follow->preciseOriginTimestamp.secondsField.lsb =
flip32(*(UInteger32 *) (buf + 36));
follow->preciseOriginTimestamp.nanosecondsField =
flip32(*(UInteger32 *) (buf + 40));
flwup->preciseOriginTimestamp.secondsField.msb =
pp_htons(*(UInteger16 *) (buf + 34));
flwup->preciseOriginTimestamp.secondsField.lsb =
pp_htonl(*(UInteger32 *) (buf + 36));
flwup->preciseOriginTimestamp.nanosecondsField =
pp_htonl(*(UInteger32 *) (buf + 40));
/* FIXME: diag
#ifdef PTPD_DBG
msgFollowUp_display(follow);
#endif /* PTPD_DBG */
#endif
*/
}
/*pack PdelayReq message into OUT buffer of ptpClock*/
void
msgPackPDelayReq(void *buf, Timestamp * originTimestamp, PtpClock * ptpClock)
/* pack PdelayReq message into out buffer of ppi */
void msg_pack_pdelay_req(void *buf, Timestamp *orig_tstamp,
struct pp_instance *ppi)
{
/* changes in header */
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
/* RAZ messageType */
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x02;
/* Table 19 */
*(UInteger16 *) (buf + 2) = flip16(PDELAY_REQ_LENGTH);
*(UInteger16 *) (buf + 30) = flip16(ptpClock->sentPDelayReqSequenceId);
*(UInteger16 *) (buf + 2) = pp_htons(PP_PDELAY_REQ_LENGTH);
*(UInteger16 *) (buf + 30) = pp_htons(ppi->sent_seq_id[PPM_PDELAY_REQ]);
*(UInteger8 *) (buf + 32) = 0x05;
/* Table 23 */
*(Integer8 *) (buf + 33) = 0x7F;
/* Table 24 */
memset((buf + 8), 0, 8);
pp_memset((buf + 8), 0, 8);
/* Pdelay_req message */
*(UInteger16 *) (buf + 34) = flip16(originTimestamp->secondsField.msb);
*(UInteger32 *) (buf + 36) = flip32(originTimestamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) = flip32(originTimestamp->nanosecondsField);
*(UInteger16 *) (buf + 34) = pp_htons(orig_tstamp->secondsField.msb);
*(UInteger32 *) (buf + 36) = pp_htonl(orig_tstamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) = pp_htonl(orig_tstamp->nanosecondsField);
memset((buf + 44), 0, 10);
pp_memset((buf + 44), 0, 10);
/* RAZ reserved octets */
}
/*pack delayReq message into OUT buffer of ptpClock*/
void
msgPackDelayReq(void *buf, Timestamp * originTimestamp, PtpClock * ptpClock)
/*pack DelayReq message into out buffer of ppi*/
void msg_pack_delay_req(void *buf, Timestamp *orig_tstamp,
struct pp_instance *ppi)
{
/* changes in header */
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
/* RAZ messageType */
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x01;
/* Table 19 */
*(UInteger16 *) (buf + 2) = flip16(DELAY_REQ_LENGTH);
*(UInteger16 *) (buf + 30) = flip16(ptpClock->sentDelayReqSequenceId);
*(UInteger16 *) (buf + 2) = pp_htons(PP_DELAY_REQ_LENGTH);
*(UInteger16 *) (buf + 30) = pp_htons(ppi->sent_seq_id[PPM_DELAY_REQ]);
*(UInteger8 *) (buf + 32) = 0x01;
/* Table 23 */
*(Integer8 *) (buf + 33) = 0x7F;
/* Table 24 */
memset((buf + 8), 0, 8);
pp_memset((buf + 8), 0, 8);
/* Pdelay_req message */
*(UInteger16 *) (buf + 34) = flip16(originTimestamp->secondsField.msb);
*(UInteger32 *) (buf + 36) = flip32(originTimestamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) = flip32(originTimestamp->nanosecondsField);
*(UInteger16 *) (buf + 34) = pp_htons(orig_tstamp->secondsField.msb);
*(UInteger32 *) (buf + 36) = pp_htonl(orig_tstamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) = pp_htonl(orig_tstamp->nanosecondsField);
}
/*pack delayResp message into OUT buffer of ptpClock*/
void
msgPackDelayResp(void *buf, MsgHeader * header, Timestamp * receiveTimestamp, PtpClock * ptpClock)
/*pack delayResp message into OUT buffer of ppi*/
void msg_pack_delay_resp(void *buf, MsgHeader *hdr, Timestamp *rcv_tstamp,
struct pp_instance *ppi)
{
/* changes in header */
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
/* RAZ messageType */
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x09;
/* Table 19 */
*(UInteger16 *) (buf + 2) = flip16(DELAY_RESP_LENGTH);
*(UInteger8 *) (buf + 4) = header->domainNumber;
memset((buf + 8), 0, 8);
*(UInteger16 *) (buf + 2) = pp_htons(PP_DELAY_RESP_LENGTH);
*(UInteger8 *) (buf + 4) = hdr->domainNumber;
pp_memset((buf + 8), 0, 8);
/* Copy correctionField of PdelayReqMessage */
*(Integer32 *) (buf + 8) = flip32(header->correctionfield.msb);
*(Integer32 *) (buf + 12) = flip32(header->correctionfield.lsb);
*(Integer32 *) (buf + 8) = pp_htonl(hdr->correctionfield.msb);
*(Integer32 *) (buf + 12) = pp_htonl(hdr->correctionfield.lsb);
*(UInteger16 *) (buf + 30) = flip16(header->sequenceId);
*(UInteger16 *) (buf + 30) = pp_htons(hdr->sequenceId);
*(UInteger8 *) (buf + 32) = 0x03;
/* Table 23 */
*(Integer8 *) (buf + 33) = ptpClock->logMinDelayReqInterval;
*(Integer8 *) (buf + 33) = DSPOR(ppi)->logMinDelayReqInterval;
/* Table 24 */
/* Pdelay_resp message */
*(UInteger16 *) (buf + 34) =
flip16(receiveTimestamp->secondsField.msb);
*(UInteger32 *) (buf + 36) = flip32(receiveTimestamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) = flip32(receiveTimestamp->nanosecondsField);
memcpy((buf + 44), header->sourcePortIdentity.clockIdentity,
CLOCK_IDENTITY_LENGTH);
pp_htons(rcv_tstamp->secondsField.msb);
*(UInteger32 *) (buf + 36) = pp_htonl(rcv_tstamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) = pp_htonl(rcv_tstamp->nanosecondsField);
pp_memcpy((buf + 44), hdr->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 52) =
flip16(header->sourcePortIdentity.portNumber);
pp_htons(hdr->sourcePortIdentity.portNumber);
}
/*pack PdelayResp message into OUT buffer of ptpClock*/
void
msgPackPDelayResp(void *buf, MsgHeader * header, Timestamp * requestReceiptTimestamp, PtpClock * ptpClock)
/* Pack PdelayResp message into out buffer of ppi */
void msg_pack_pdelay_resp(void *buf, MsgHeader *hdr,
Timestamp *req_rec_tstamp, struct pp_instance *ppi)
{
/* changes in header */
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
/* RAZ messageType */
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x03;
/* Table 19 */
*(UInteger16 *) (buf + 2) = flip16(PDELAY_RESP_LENGTH);
*(UInteger8 *) (buf + 4) = header->domainNumber;
memset((buf + 8), 0, 8);
*(UInteger16 *) (buf + 2) = pp_htons(PP_PDELAY_RESP_LENGTH);
*(UInteger8 *) (buf + 4) = hdr->domainNumber;
pp_memset((buf + 8), 0, 8);
*(UInteger16 *) (buf + 30) = flip16(header->sequenceId);
*(UInteger16 *) (buf + 30) = pp_htons(hdr->sequenceId);
*(UInteger8 *) (buf + 32) = 0x05;
/* Table 23 */
......@@ -313,137 +325,141 @@ msgPackPDelayResp(void *buf, MsgHeader * header, Timestamp * requestReceiptTimes
/* Table 24 */
/* Pdelay_resp message */
*(UInteger16 *) (buf + 34) = flip16(requestReceiptTimestamp->secondsField.msb);
*(UInteger32 *) (buf + 36) = flip32(requestReceiptTimestamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) = flip32(requestReceiptTimestamp->nanosecondsField);
memcpy((buf + 44), header->sourcePortIdentity.clockIdentity, CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 52) = flip16(header->sourcePortIdentity.portNumber);
*(UInteger16 *) (buf + 34) = pp_htons(req_rec_tstamp->secondsField.msb);
*(UInteger32 *) (buf + 36) = pp_htonl(req_rec_tstamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) = pp_htonl(req_rec_tstamp->nanosecondsField);
pp_memcpy((buf + 44), hdr->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 52) =
pp_htons(hdr->sourcePortIdentity.portNumber);
}
/*Unpack delayReq message from IN buffer of ptpClock to msgtmp.req*/
void
msgUnpackDelayReq(void *buf, MsgDelayReq * delayreq)
/* Unpack delayReq message from in buffer of ppi to msgtmp.req */
void msg_unpack_delay_req(void *buf, MsgDelayReq *delay_req)
{
delayreq->originTimestamp.secondsField.msb =
flip16(*(UInteger16 *) (buf + 34));
delayreq->originTimestamp.secondsField.lsb =
flip32(*(UInteger32 *) (buf + 36));
delayreq->originTimestamp.nanosecondsField =
flip32(*(UInteger32 *) (buf + 40));
delay_req->originTimestamp.secondsField.msb =
pp_htons(*(UInteger16 *) (buf + 34));
delay_req->originTimestamp.secondsField.lsb =
pp_htonl(*(UInteger32 *) (buf + 36));
delay_req->originTimestamp.nanosecondsField =
pp_htonl(*(UInteger32 *) (buf + 40));
/* FIXME: diag
#ifdef PTPD_DBG
msgDelayReq_display(delayreq);
#endif /* PTPD_DBG */
#endif
*/
}
/*Unpack PdelayReq message from IN buffer of ptpClock to msgtmp.req*/
void
msgUnpackPDelayReq(void *buf, MsgPDelayReq * pdelayreq)
{
pdelayreq->originTimestamp.secondsField.msb =
flip16(*(UInteger16 *) (buf + 34));
pdelayreq->originTimestamp.secondsField.lsb =
flip32(*(UInteger32 *) (buf + 36));
pdelayreq->originTimestamp.nanosecondsField =
flip32(*(UInteger32 *) (buf + 40));
/* Unpack PdelayReq message from IN buffer of ppi to msgtmp.req */
void msg_unpack_pdelay_req(void *buf, MsgPDelayReq *pdelay_req)
{
pdelay_req->originTimestamp.secondsField.msb =
pp_htons(*(UInteger16 *) (buf + 34));
pdelay_req->originTimestamp.secondsField.lsb =
pp_htonl(*(UInteger32 *) (buf + 36));
pdelay_req->originTimestamp.nanosecondsField =
pp_htonl(*(UInteger32 *) (buf + 40));
/* FIXME: diag
#ifdef PTPD_DBG
msgPDelayReq_display(pdelayreq);
#endif /* PTPD_DBG */
#endif
*/
}
/*Unpack delayResp message from IN buffer of ptpClock to msgtmp.presp*/
void
msgUnpackDelayResp(void *buf, MsgDelayResp * resp)
/* Unpack delayResp message from IN buffer of ppi to msgtmp.presp */
void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp)
{
resp->receiveTimestamp.secondsField.msb =
flip16(*(UInteger16 *) (buf + 34));
pp_htons(*(UInteger16 *) (buf + 34));
resp->receiveTimestamp.secondsField.lsb =
flip32(*(UInteger32 *) (buf + 36));
pp_htonl(*(UInteger32 *) (buf + 36));
resp->receiveTimestamp.nanosecondsField =
flip32(*(UInteger32 *) (buf + 40));
memcpy(resp->requestingPortIdentity.clockIdentity,
(buf + 44), CLOCK_IDENTITY_LENGTH);
pp_htonl(*(UInteger32 *) (buf + 40));
pp_memcpy(resp->requestingPortIdentity.clockIdentity,
(buf + 44), PP_CLOCK_IDENTITY_LENGTH);
resp->requestingPortIdentity.portNumber =
flip16(*(UInteger16 *) (buf + 52));
pp_htons(*(UInteger16 *) (buf + 52));
/* FIXME: diag
#ifdef PTPD_DBG
msgDelayResp_display(resp);
#endif /* PTPD_DBG */
#endif
*/
}
/*Unpack PdelayResp message from IN buffer of ptpClock to msgtmp.presp*/
void
msgUnpackPDelayResp(void *buf, MsgPDelayResp * presp)
/* Unpack PdelayResp message from IN buffer of ppi to msgtmp.presp */
void msg_unpack_pdelay_resp(void *buf, MsgPDelayResp *presp)
{
presp->requestReceiptTimestamp.secondsField.msb =
flip16(*(UInteger16 *) (buf + 34));
presp->requestReceiptTimestamp.secondsField.lsb =
flip32(*(UInteger32 *) (buf + 36));
presp->requestReceiptTimestamp.nanosecondsField =
flip32(*(UInteger32 *) (buf + 40));
memcpy(presp->requestingPortIdentity.clockIdentity,
(buf + 44), CLOCK_IDENTITY_LENGTH);
presp->requestingPortIdentity.portNumber =
flip16(*(UInteger16 *) (buf + 52));
presp->requestReceiptTimestamp.secondsField.msb =
pp_htons(*(UInteger16 *) (buf + 34));
presp->requestReceiptTimestamp.secondsField.lsb =
pp_htonl(*(UInteger32 *) (buf + 36));
presp->requestReceiptTimestamp.nanosecondsField =
pp_htonl(*(UInteger32 *) (buf + 40));
pp_memcpy(presp->requestingPortIdentity.clockIdentity,
(buf + 44), PP_CLOCK_IDENTITY_LENGTH);
presp->requestingPortIdentity.portNumber =
pp_htons(*(UInteger16 *) (buf + 52));
/* FIXME: diag
#ifdef PTPD_DBG
msgPDelayResp_display(presp);
#endif /* PTPD_DBG */
#endif
*/
}
/*pack PdelayRespfollowup message into OUT buffer of ptpClock*/
void
msgPackPDelayRespFollowUp(void *buf, MsgHeader * header, Timestamp * responseOriginTimestamp, PtpClock * ptpClock)
/* Pack PdelayRespFollowUp message into out buffer of ppi */
void msg_pack_pdelay_resp_followup(void *buf, MsgHeader *hdr,
Timestamp *resp_orig_tstamp, struct pp_instance* ppi)
{
/* changes in header */
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
/* RAZ messageType */
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x0A;
/* Table 19 */
*(UInteger16 *) (buf + 2) = flip16(PDELAY_RESP_FOLLOW_UP_LENGTH);
*(UInteger16 *) (buf + 30) = flip16(ptpClock->PdelayReqHeader.sequenceId);
*(UInteger16 *) (buf + 2) = pp_htons(PP_PDELAY_RESP_FOLLOW_UP_LENGTH);
*(UInteger16 *) (buf + 30) = pp_htons(ppi->pdelay_req_hdr.sequenceId);
*(UInteger8 *) (buf + 32) = 0x05;
/* Table 23 */
*(Integer8 *) (buf + 33) = 0x7F;
/* Table 24 */
/* Copy correctionField of PdelayReqMessage */
*(Integer32 *) (buf + 8) = flip32(header->correctionfield.msb);
*(Integer32 *) (buf + 12) = flip32(header->correctionfield.lsb);
*(Integer32 *) (buf + 8) = pp_htonl(hdr->correctionfield.msb);
*(Integer32 *) (buf + 12) = pp_htonl(hdr->correctionfield.lsb);
/* Pdelay_resp_follow_up message */
*(UInteger16 *) (buf + 34) =
flip16(responseOriginTimestamp->secondsField.msb);
*(UInteger32 *) (buf + 36) =
flip32(responseOriginTimestamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) =
flip32(responseOriginTimestamp->nanosecondsField);
memcpy((buf + 44), header->sourcePortIdentity.clockIdentity,
CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 52) =
flip16(header->sourcePortIdentity.portNumber);
*(UInteger16 *) (buf + 34) =
pp_htons(resp_orig_tstamp->secondsField.msb);
*(UInteger32 *) (buf + 36) =
pp_htonl(resp_orig_tstamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) =
pp_htonl(resp_orig_tstamp->nanosecondsField);
pp_memcpy((buf + 44), hdr->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 52) =
pp_htons(hdr->sourcePortIdentity.portNumber);
}
/*Unpack PdelayResp message from IN buffer of ptpClock to msgtmp.presp*/
void
msgUnpackPDelayRespFollowUp(void *buf, MsgPDelayRespFollowUp * prespfollow)
/* Unpack PdelayResp message from in buffer of ppi to msgtmp.presp */
void msg_unpack_pdelay_resp_followup(void *buf,
MsgPDelayRespFollowUp *presp_follow)
{
prespfollow->responseOriginTimestamp.secondsField.msb =
flip16(*(UInteger16 *) (buf + 34));
prespfollow->responseOriginTimestamp.secondsField.lsb =
flip32(*(UInteger32 *) (buf + 36));
prespfollow->responseOriginTimestamp.nanosecondsField =
flip32(*(UInteger32 *) (buf + 40));
memcpy(prespfollow->requestingPortIdentity.clockIdentity,
(buf + 44), CLOCK_IDENTITY_LENGTH);
prespfollow->requestingPortIdentity.portNumber =
flip16(*(UInteger16 *) (buf + 52));
presp_follow->responseOriginTimestamp.secondsField.msb =
pp_htons(*(UInteger16 *) (buf + 34));
presp_follow->responseOriginTimestamp.secondsField.lsb =
pp_htonl(*(UInteger32 *) (buf + 36));
presp_follow->responseOriginTimestamp.nanosecondsField =
pp_htonl(*(UInteger32 *) (buf + 40));
pp_memcpy(presp_follow->requestingPortIdentity.clockIdentity,
(buf + 44), PP_CLOCK_IDENTITY_LENGTH);
presp_follow->requestingPortIdentity.portNumber =
pp_htons(*(UInteger16 *) (buf + 52));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment