Commit 6eb65f72 authored by Cesar Prados's avatar Cesar Prados Committed by Alessandro Rubini

pdelay/msg: PDelay in the Master Clock

In PDelay mechanism, the Master has to reply to PDelay_Req from pclocks
with PDelay_respond and PDelay_follow_up. Add pack/issue functions
for this messages
Signed-off-by: Cesar Prados's avatarC.Prados <c.prados@gsi.de>

[WARNING: this commit was changed by Alessandro, adding a missing
"pdelay_req_hdr" field in pp_instance, and exporting msg_copy_header
that had been turned to static -- this must be fixed]
parent cc3e8ce2
......@@ -174,6 +174,8 @@ struct pp_instance {
UInteger16 sent_seq[__PP_NR_MESSAGES_TYPES]; /* last sent this type */
MsgHeader received_ptp_header;
MsgHeader pdelay_req_hdr;
char *iface_name; /* for direct actions on hardware */
char *port_name; /* for diagnostics, mainly */
int port_idx;
......
......@@ -392,17 +392,26 @@ extern void msg_unpack_announce(void *buf, MsgAnnounce *ann);
extern void msg_unpack_follow_up(void *buf, MsgFollowUp *flwup);
extern void msg_unpack_delay_req(void *buf, MsgDelayReq *delay_req);
extern void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp);
/* pdelay */
extern void msg_pack_pdelay_resp_follow_up(struct pp_instance *ppi,
MsgHeader * hdr,
Timestamp * prec_orig_tstamp);
extern void msg_pack_pdelay_resp(struct pp_instance *ppi, MsgHeader * hdr,
Timestamp * rcv_tstamp);
/* each of them returns 0 if ok, -1 in case of error in send, 1 if stamp err */
#define PP_SEND_OK 0
#define PP_SEND_ERROR -1
#define PP_SEND_NO_STAMP 1
extern void *msg_copy_header(MsgHeader *dest, MsgHeader *src); /* REMOVE ME!! */
extern int msg_issue_announce(struct pp_instance *ppi);
extern int msg_issue_sync_followup(struct pp_instance *ppi);
extern int msg_issue_delay_req(struct pp_instance *ppi);
extern int msg_issue_delay_resp(struct pp_instance *ppi, TimeInternal *time);
extern int msg_issue_pdelay_resp_followup(struct pp_instance *ppi,
TimeInternal * time);
extern int msg_issue_pdelay_resp(struct pp_instance *ppi, TimeInternal * time);
/* Functions for timestamp handling (internal to protocol format conversion*/
/* FIXME: add prefix in function name? */
......
......@@ -15,7 +15,7 @@
#define ARCH_IS_WRS 0
#endif
static void *msg_copy_header(MsgHeader *dest, MsgHeader *src)
void *msg_copy_header(MsgHeader *dest, MsgHeader *src)
{
return memcpy(dest, src, sizeof(MsgHeader));
}
......
......@@ -217,6 +217,40 @@ static void msg_pack_follow_up(struct pp_instance *ppi, Timestamp *prec_orig_tst
htonl(prec_orig_tstamp->nanosecondsField);
}
/* Pack PDelay Follow Up message into out buffer of ppi*/
void msg_pack_pdelay_resp_follow_up(struct pp_instance *ppi,
MsgHeader * hdr,
Timestamp * prec_orig_tstamp)
{
void *buf;
buf = ppi->tx_ptp;
/* header */
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
/* RAZ messageType */
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x0A;
*(UInteger16 *) (buf + 2) = htons(PP_PDELAY_RESP_LENGTH);
*(UInteger8 *) (buf + 4) = hdr->domainNumber;
/* copy the correction field, 11.4.3 c.3) */
*(Integer32 *) (buf + 8) = htonl(hdr->correctionfield.msb);
*(Integer32 *) (buf + 12) = htonl(hdr->correctionfield.lsb);
*(UInteger16 *) (buf + 30) = htons(hdr->sequenceId);
*(UInteger8 *) (buf + 32) = 0x05; /* controlField */
/* requestReceiptTimestamp */
*(UInteger16 *) (buf + 34) = htons(prec_orig_tstamp->secondsField.msb);
*(UInteger32 *) (buf + 36) = htonl(prec_orig_tstamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) = htonl(prec_orig_tstamp->nanosecondsField);
/* requestingPortIdentity */
memcpy((buf + 44), &hdr->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 52) = htons(hdr->sourcePortIdentity.portNumber);
}
/* Unpack FollowUp message from in buffer of ppi to msgtmp.follow */
void msg_unpack_follow_up(void *buf, MsgFollowUp *flwup)
{
......@@ -258,6 +292,37 @@ static void msg_pack_delay_req(struct pp_instance *ppi, Timestamp *orig_tstamp)
*(UInteger32 *) (buf + 40) = htonl(orig_tstamp->nanosecondsField);
}
/* pack PDelayResp message into OUT buffer of ppi */
void msg_pack_pdelay_resp(struct pp_instance *ppi,
MsgHeader * hdr, Timestamp * rcv_tstamp)
{
void *buf;
buf = ppi->tx_ptp;
/* header */
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
/* RAZ messageType */
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x03;
*(UInteger16 *) (buf + 2) = htons(PP_PDELAY_RESP_LENGTH);
*(UInteger8 *) (buf + 4) = hdr->domainNumber;
/* set 0 the correction field, 11.4.3 c.3) */
memset((buf + 8), 0, 8);
*(UInteger16 *) (buf + 30) = htons(hdr->sequenceId);
*(UInteger8 *) (buf + 32) = 0x05; /* controlField */
/* requestReceiptTimestamp */
*(UInteger16 *) (buf + 34) = htons(rcv_tstamp->secondsField.msb);
*(UInteger32 *) (buf + 36) = htonl(rcv_tstamp->secondsField.lsb);
*(UInteger32 *) (buf + 40) = htonl(rcv_tstamp->nanosecondsField);
/* requestingPortIdentity */
memcpy((buf + 44), &hdr->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 52) = htons(hdr->sourcePortIdentity.portNumber);
}
/* pack DelayResp message into OUT buffer of ppi */
static void msg_pack_delay_resp(struct pp_instance *ppi,
MsgHeader *hdr, Timestamp *rcv_tstamp)
......@@ -372,6 +437,19 @@ int msg_issue_sync_followup(struct pp_instance *ppi)
PP_NP_GEN);
}
/* Pack and send on general multicast ip address a FollowUp message */
int msg_issue_pdelay_resp_followup(struct pp_instance *ppi, TimeInternal * time)
{
Timestamp prec_orig_tstamp;
from_TimeInternal(time, &prec_orig_tstamp);
msg_pack_pdelay_resp_follow_up(ppi, &ppi->pdelay_req_hdr,
&prec_orig_tstamp);
return __send_and_log(ppi, PP_PDELAY_RESP_FOLLOW_UP_LENGTH,
PPM_PDELAY_RESP_FOLLOW_UP, PP_NP_GEN);
}
/* Pack and send on event multicast ip adress a DelayReq message */
int msg_issue_delay_req(struct pp_instance *ppi)
{
......@@ -397,3 +475,15 @@ int msg_issue_delay_resp(struct pp_instance *ppi, TimeInternal *time)
return __send_and_log(ppi, PP_DELAY_RESP_LENGTH, PPM_DELAY_RESP,
PP_NP_GEN);
}
/* Pack and send on event multicast ip adress a DelayResp message */
int msg_issue_pdelay_resp(struct pp_instance *ppi, TimeInternal * time)
{
Timestamp rcv_tstamp;
from_TimeInternal(time, &rcv_tstamp);
msg_pack_pdelay_resp(ppi, &ppi->pdelay_req_hdr, &rcv_tstamp);
return __send_and_log(ppi, PP_PDELAY_RESP_LENGTH, PPM_PDELAY_RESP,
PP_NP_EVT);
}
......@@ -126,12 +126,12 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
msg_issue_delay_resp(ppi, &ppi->last_rcv_time);
break;
/*
* We are not supporting pdelay (not configured to, see
* 9.5.13.1, p 106), so all the code about pdelay is removed
* as a whole by one commit in our history. It can be recoverd
* and fixed if needed
*/
case PPM_PDELAY_REQ:
msg_copy_header(&ppi->pdelay_req_hdr,
&ppi->received_ptp_header);
msg_issue_pdelay_resp(ppi, &ppi->last_rcv_time);
msg_issue_pdelay_resp_followup(ppi, &ppi->last_snt_time);
break;
default:
/* disregard, nothing to do */
......
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