Commit 18edcef4 authored by Jean-Claude BAU's avatar Jean-Claude BAU

Increased code readability + protect P2P reception from multiple responses

- In order to increase the code readibility, the p2p and e2e functions has
been splitted into differents files.
- Protect P2P from multiple answers coming from different hosts.
parent 8edb1dda
......@@ -254,6 +254,10 @@ struct pp_instance {
unsigned long ptp_tx_count;
unsigned long ptp_rx_count;
#if CONFIG_HAS_P2P == 1
Boolean received_dresp; /* Count the number of delay response messages received for a given delay request */
Boolean received_dresp_fup; /* Count the number of delay response follow up messages received for a given delay request */
#endif
};
......
......@@ -13,8 +13,10 @@ OBJ-y += $D/fsm-table.o \
$D/state-passive.o \
$D/state-slave.o \
$D/common-fun.o \
$D/common-fun-p2p.o \
$D/bmc.o \
$D/msg.o \
$D/msg-p2p.o \
$D/servo.o \
$D/hooks.o \
$D/open-close.o
/*
* Copyright (C) 2011 CERN (www.cern.ch)
* Author: Aurelio Colosimo
* Based on PTPd project v. 2.1.0 (see AUTHORS for details)
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#include <ppsi/ppsi.h>
#include "common-fun.h"
#include "../lib/network_types.h"
#if CONFIG_HAS_P2P
static int presp_call_servo(struct pp_instance *ppi)
{
int ret = 0;
if (is_incorrect(&ppi->t4))
return 0; /* not an error, just no data */
pp_timeout_set(ppi, PP_TO_FAULT);
if (ppi->ext_hooks->handle_presp)
ret = ppi->ext_hooks->handle_presp(ppi);
else
pp_servo_got_presp(ppi);
return ret;
}
int st_com_peer_handle_pres(struct pp_instance *ppi, void *buf,
int len)
{
MsgPDelayResp resp;
MsgHeader *hdr = &ppi->received_ptp_header;
int e = 0;
/* if not in P2P mode, just return */
if (ppi->delayMechanism != P2P)
return 0;
msg_unpack_pdelay_resp(buf, &resp);
if ((bmc_idcmp(&DSPOR(ppi)->portIdentity.clockIdentity,
&resp.requestingPortIdentity.clockIdentity) == 0) &&
((ppi->sent_seq[PPM_PDELAY_REQ]) ==
hdr->sequenceId) &&
(DSPOR(ppi)->portIdentity.portNumber ==
resp.requestingPortIdentity.portNumber) ) {
/* Check for multiple answers */
if ( ppi->received_dresp ) {
/* Response already received */
/* Clause 11.4.3.C.1 When multiple Pdelay_Resp messages are received, PTP Instance-A shall ..
* enter the FAULTY state ...
*/
if ( !DSDEF(ppi)->externalPortConfigurationEnabled ) {
ppi->next_state = PPS_FAULTY;
return 0;
} else {
/* externalPortConfiguration is enabled. We cannot change the state */
pp_diag(ppi, frames, 2, "%s: "
"Multiple PDelay Response received for the same request\n",__func__);
}
}
ppi->received_dresp=1;
ppi->t4 = resp.requestReceiptTimestamp;
pp_time_add(&ppi->t4, &hdr->cField);
/* WARNING: should be "sub" (see README-cfield::BUG) */
ppi->t6 = ppi->last_rcv_time;
if ((hdr->flagField[0] & PP_TWO_STEP_FLAG) != 0)
ppi->flags |= PPI_FLAG_WAITING_FOR_RF_UP;
else {
ppi->flags &= ~PPI_FLAG_WAITING_FOR_RF_UP;
/*
* Make sure responseOriginTimestamp is forced to 0
* for one-step responders
*/
memset(&ppi->t5, 0, sizeof(ppi->t5));
}
if (!(hdr->flagField[0] & PP_TWO_STEP_FLAG))
e = presp_call_servo(ppi);
} else {
pp_diag(ppi, frames, 2, "pp_pclock : "
"PDelay Resp doesn't match PDelay Req\n");
}
return e;
}
int st_com_peer_handle_pres_followup(struct pp_instance *ppi,
void *buf, int len)
{
MsgHeader *hdr = &ppi->received_ptp_header;
MsgPDelayRespFollowUp respFllw;
int e = 0;
/* if not in P2P mode, just return */
if (ppi->delayMechanism != P2P)
return 0;
msg_unpack_pdelay_resp_follow_up(buf, &respFllw);
if ((bmc_idcmp(&DSPOR(ppi)->portIdentity.clockIdentity,
&respFllw.requestingPortIdentity.clockIdentity) == 0) &&
((ppi->sent_seq[PPM_PDELAY_REQ]) ==
hdr->sequenceId) &&
(DSPOR(ppi)->portIdentity.portNumber ==
respFllw.requestingPortIdentity.portNumber) ) {
/* Check for multiple answers */
if ( ppi->received_dresp_fup ) {
/* Response already received */
/* Clause 11.4.3.C.1 When multiple Pdelay_Resp messages are received, PTP Instance-A shall ..
* enter the FAULTY state ...
*/
if ( !DSDEF(ppi)->externalPortConfigurationEnabled ) {
ppi->next_state = PPS_FAULTY;
return 0;
} else {
/* externalPortConfiguration is enabled. We cannot change the state */
pp_diag(ppi, frames, 2, "%s: "
"Multiple PDelay Response Follow Up received for the same request\n",__func__);
}
}
ppi->received_dresp_fup=1;
ppi->t5 = respFllw.responseOriginTimestamp;
pp_time_add(&ppi->t5, &hdr->cField);
e = presp_call_servo(ppi);
} else {
pp_diag(ppi, frames, 2, "%s: "
"PDelay Resp F-up doesn't match PDelay Req\n",
__func__);
}
return e;
}
int st_com_peer_handle_preq(struct pp_instance *ppi, void *buf,
int len)
{
int e = 0;
/* if not in P2P mode, just return */
if (ppi->delayMechanism != P2P)
return 0;
if (ppi->ext_hooks->handle_preq)
e = ppi->ext_hooks->handle_preq(ppi);
if (e)
return e;
msg_issue_pdelay_resp(ppi, &ppi->last_rcv_time);
msg_issue_pdelay_resp_followup(ppi, &ppi->last_snt_time);
return 0;
}
#endif
......@@ -64,22 +64,6 @@ void pp_prepare_pointers(struct pp_instance *ppi)
}
}
static int presp_call_servo(struct pp_instance *ppi)
{
int ret = 0;
if (is_incorrect(&ppi->t4))
return 0; /* not an error, just no data */
pp_timeout_set(ppi, PP_TO_FAULT);
if (ppi->ext_hooks->handle_presp)
ret = ppi->ext_hooks->handle_presp(ppi);
else
pp_servo_got_presp(ppi);
return ret;
}
static int is_grand_master(struct pp_instance *ppi) {
int has_slave= 0;
int has_master=0;
......@@ -129,105 +113,6 @@ int st_com_check_announce_receive_timeout(struct pp_instance *ppi)
return 0;
}
int st_com_peer_handle_pres(struct pp_instance *ppi, void *buf,
int len)
{
MsgPDelayResp resp;
MsgHeader *hdr = &ppi->received_ptp_header;
int e = 0;
/* if not in P2P mode, just return */
if (!CONFIG_HAS_P2P || ppi->delayMechanism != P2P)
return 0;
msg_unpack_pdelay_resp(buf, &resp);
if ((bmc_idcmp(&DSPOR(ppi)->portIdentity.clockIdentity,
&resp.requestingPortIdentity.clockIdentity) == 0) &&
((ppi->sent_seq[PPM_PDELAY_REQ]) ==
hdr->sequenceId) &&
(DSPOR(ppi)->portIdentity.portNumber ==
resp.requestingPortIdentity.portNumber) &&
(msg_from_current_master(ppi))) {
ppi->t4 = resp.requestReceiptTimestamp;
pp_time_add(&ppi->t4, &hdr->cField);
/* WARNING: should be "sub" (see README-cfield::BUG) */
ppi->t6 = ppi->last_rcv_time;
if ((hdr->flagField[0] & PP_TWO_STEP_FLAG) != 0)
ppi->flags |= PPI_FLAG_WAITING_FOR_RF_UP;
else {
ppi->flags &= ~PPI_FLAG_WAITING_FOR_RF_UP;
/*
* Make sure responseOriginTimestamp is forced to 0
* for one-step responders
*/
memset(&ppi->t5, 0, sizeof(ppi->t5));
}
if (!(hdr->flagField[0] & PP_TWO_STEP_FLAG))
e = presp_call_servo(ppi);
} else {
pp_diag(ppi, frames, 2, "pp_pclock : "
"PDelay Resp doesn't match PDelay Req\n");
}
return e;
}
int st_com_peer_handle_pres_followup(struct pp_instance *ppi,
void *buf, int len)
{
MsgHeader *hdr = &ppi->received_ptp_header;
MsgPDelayRespFollowUp respFllw;
int e = 0;
/* if not in P2P mode, just return */
if (!CONFIG_HAS_P2P || ppi->delayMechanism != P2P)
return 0;
msg_unpack_pdelay_resp_follow_up(buf, &respFllw);
if ((bmc_idcmp(&DSPOR(ppi)->portIdentity.clockIdentity,
&respFllw.requestingPortIdentity.clockIdentity) == 0) &&
((ppi->sent_seq[PPM_PDELAY_REQ]) ==
hdr->sequenceId) &&
(DSPOR(ppi)->portIdentity.portNumber ==
respFllw.requestingPortIdentity.portNumber) &&
(msg_from_current_master(ppi))) {
ppi->t5 = respFllw.responseOriginTimestamp;
pp_time_add(&ppi->t5, &hdr->cField);
e = presp_call_servo(ppi);
} else {
pp_diag(ppi, frames, 2, "%s: "
"PDelay Resp F-up doesn't match PDelay Req\n",
__func__);
}
return e;
}
int st_com_peer_handle_preq(struct pp_instance *ppi, void *buf,
int len)
{
int e = 0;
/* if not in P2P mode, just return */
if (!CONFIG_HAS_P2P || ppi->delayMechanism != P2P)
return 0;
if (ppi->ext_hooks->handle_preq)
e = ppi->ext_hooks->handle_preq(ppi);
if (e)
return e;
msg_issue_pdelay_resp(ppi, &ppi->last_rcv_time);
msg_issue_pdelay_resp_followup(ppi, &ppi->last_snt_time);
return 0;
}
int st_com_handle_announce(struct pp_instance *ppi, void *buf, int len)
{
/* Clause 9.2.2.2 MasterOnly PTP ports :
......
/*
* Copyright (C) 2011 CERN (www.cern.ch)
* Author: Aurelio Colosimo
* Based on PTPd project v. 2.1.0 (see AUTHORS for details)
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#include <ppsi/ppsi.h>
#if CONFIG_HAS_P2P
#include "common-fun.h"
#include "msg.h"
/* Pack PDelay Follow Up message into out buffer of ppi*/
static int msg_pack_pdelay_resp_follow_up(struct pp_instance *ppi,
MsgHeader * hdr,
struct pp_time *prec_orig_tstamp)
{
void *buf = ppi->tx_ptp;
int len;
struct pp_msgtype_info *mf = pp_msgtype_info + PPM_PDELAY_R_FUP_FMT;
len= __msg_pack_header(ppi, mf);
/* Header */
*(UInteger8 *) (buf + 4) = hdr->domainNumber; /* FIXME: why? */
/* We should copy the correction field and add our fractional part */
hdr->cField.scaled_nsecs
+= prec_orig_tstamp->scaled_nsecs & 0xffff;
normalize_pp_time(&hdr->cField);
*(Integer64 *) (buf + 8) = htonll(hdr->cField.scaled_nsecs);
*(UInteger16 *) (buf + 30) = htons(hdr->sequenceId);
/* requestReceiptTimestamp */
__pack_origin_timestamp(buf,prec_orig_tstamp);
/* requestingPortIdentity */
memcpy((buf + 44), &hdr->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 52) = htons(hdr->sourcePortIdentity.portNumber);
return len;
}
/* Unpack PDelayRespFollowUp message from in buffer of ppi to internal struct */
void msg_unpack_pdelay_resp_follow_up(void *buf,
MsgPDelayRespFollowUp * pdelay_resp_flwup)
{
__unpack_origin_timestamp(buf,&pdelay_resp_flwup->responseOriginTimestamp);
/* cField added by the caller, as it's already converted */
memcpy(&pdelay_resp_flwup->requestingPortIdentity.clockIdentity,
(buf + 44), PP_CLOCK_IDENTITY_LENGTH);
pdelay_resp_flwup->requestingPortIdentity.portNumber =
ntohs(*(UInteger16 *) (buf + 52));
}
/* pack DelayReq message into out buffer of ppi */
static int msg_pack_pdelay_req(struct pp_instance *ppi,
struct pp_time *now)
{
void *buf = ppi->tx_ptp;
struct pp_msgtype_info *mf = pp_msgtype_info + PPM_PDELAY_REQ_FMT;
int len= __msg_pack_header(ppi, mf);
/* Header */
__msg_set_seq_id(ppi,mf);
/* PDelay_req message - we may send zero instead */
__pack_origin_timestamp(buf,now);
memset((buf + 44), 0, 10);
return len;
}
/* pack PDelayResp message into OUT buffer of ppi */
static int msg_pack_pdelay_resp(struct pp_instance *ppi,
MsgHeader * hdr, struct pp_time *rcv_tstamp)
{
void *buf = ppi->tx_ptp;
UInteger8 *flags8 = buf + 6;;
struct pp_msgtype_info *mf = pp_msgtype_info + PPM_PDELAY_RESP_FMT;
int len= __msg_pack_header(ppi, mf);
/* Header */
flags8[0] = PP_TWO_STEP_FLAG; /* Table 20) */
*(UInteger16 *) (buf + 30) = htons(hdr->sequenceId);
/* cField: shdould be the fractional negated (see README-cfield) */
*(UInteger64 *)(buf + 8) =
htonll(rcv_tstamp->scaled_nsecs & 0xffff);
/* requestReceiptTimestamp */
__pack_origin_timestamp(buf,rcv_tstamp);
/* requestingPortIdentity */
memcpy((buf + 44), &hdr->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 52) = htons(hdr->sourcePortIdentity.portNumber);
return len;
}
/* Unpack PDelayReq message from in buffer of ppi to internal structure */
void msg_unpack_pdelay_req(void *buf, MsgPDelayReq * pdelay_req)
{
__unpack_origin_timestamp(buf,&pdelay_req->originTimestamp);
}
/* Unpack PDelayResp message from IN buffer of ppi to internal structure */
void msg_unpack_pdelay_resp(void *buf, MsgPDelayResp * presp)
{
__unpack_origin_timestamp(buf,&presp->requestReceiptTimestamp);
/* cfield added in the caller */
memcpy(&presp->requestingPortIdentity.clockIdentity,
(buf + 44), PP_CLOCK_IDENTITY_LENGTH);
presp->requestingPortIdentity.portNumber =
ntohs(*(UInteger16 *) (buf + 52));
}
/* Pack and send on general multicast ip address a FollowUp message */
int msg_issue_pdelay_resp_followup(struct pp_instance *ppi, struct pp_time *t)
{
int len;
len = msg_pack_pdelay_resp_follow_up(ppi, &ppi->received_ptp_header, t);
return __send_and_log(ppi, len, PP_NP_GEN,PPM_PDELAY_R_FUP_FMT);
}
/* Pack and send on event multicast ip adress a PDelayReq message */
int msg_issue_pdelay_req(struct pp_instance *ppi)
{
struct pp_time now;
int len;
mark_incorrect(&ppi->t4); /* see commit message */
ppi->t_ops->get(ppi, &now);
ppi->received_dresp=
ppi->received_dresp_fup=0;
len = msg_pack_pdelay_req(ppi, &now);
return __send_and_log(ppi, len, PP_NP_EVT,PPM_PDELAY_REQ_FMT);
}
/* Pack and send on event multicast ip adress a DelayResp message */
int msg_issue_pdelay_resp(struct pp_instance *ppi, struct pp_time *t)
{
int len;
len = msg_pack_pdelay_resp(ppi, &ppi->received_ptp_header, t);
return __send_and_log(ppi, len, PP_NP_EVT,PPM_PDELAY_RESP_FMT);
}
#endif
......@@ -8,18 +8,9 @@
#include <ppsi/ppsi.h>
#include "common-fun.h"
#include "msg.h"
static const int endianess=1; /* use to check endianess */
#define htonll(x) ((*(char *)&endianess == 1) ? \
htobe64(x) /* Little endian */ \
: \
(x)) /* Big endian */
#define ntohll(x) ((*(char *)&endianess == 1) ? \
be64toh(x) /* Little endian */ \
: \
(x)) /* Big endian */
const int endianess=1; /* use to check endianess */
/* return 1 if the frame is from the current master, else 0 */
int msg_from_current_master(struct pp_instance *ppi)
......@@ -74,14 +65,14 @@ void msg_init_header(struct pp_instance *ppi, void *buf)
}
/* set the sequence id in the buffer and update the stored one */
static void __msg_set_seq_id(struct pp_instance *ppi, struct pp_msgtype_info *mf) {
void __msg_set_seq_id(struct pp_instance *ppi, struct pp_msgtype_info *mf) {
void *buf = ppi->tx_ptp;
ppi->sent_seq[mf->msg_type]++;
*(UInteger16 *) (buf + 30) = htons(ppi->sent_seq[mf->msg_type]); /* SequenceId */
}
/* Helper used by all "msg_pack" below */
static int __msg_pack_header(struct pp_instance *ppi, struct pp_msgtype_info *msg_fmt)
int __msg_pack_header(struct pp_instance *ppi, struct pp_msgtype_info *msg_fmt)
{
void *buf = ppi->tx_ptp;
int len, log;
......@@ -150,13 +141,13 @@ void msg_unpack_signaling(void *buf, MsgSignaling *signaling)
signaling->tlv=buf + 44;
}
static void __pack_origin_timestamp(void *buf ,struct pp_time *orig_tstamp) {
void __pack_origin_timestamp(void *buf ,struct pp_time *orig_tstamp) {
*(UInteger16 *)(buf + 34) = htons(orig_tstamp->secs >> 32);
*(UInteger32 *)(buf + 36) = htonl(orig_tstamp->secs);
*(UInteger32 *)(buf + 40) = htonl(orig_tstamp->scaled_nsecs >> 16);
}
static void __unpack_origin_timestamp(void *buf ,struct pp_time *orig_tstamp) {
void __unpack_origin_timestamp(void *buf ,struct pp_time *orig_tstamp) {
orig_tstamp->secs = (((int64_t)ntohs(*(UInteger16 *) (buf + 34)))<<32) |
ntohl(*(UInteger32 *) (buf + 36));
orig_tstamp->scaled_nsecs = ((uint64_t)ntohl(*(UInteger32 *) (buf + 40)))<< 16;
......@@ -300,37 +291,6 @@ static int msg_pack_follow_up(struct pp_instance *ppi,
return len;
}
/* Pack PDelay Follow Up message into out buffer of ppi*/
static int msg_pack_pdelay_resp_follow_up(struct pp_instance *ppi,
MsgHeader * hdr,
struct pp_time *prec_orig_tstamp)
{
void *buf = ppi->tx_ptp;
int len;
struct pp_msgtype_info *mf = pp_msgtype_info + PPM_PDELAY_R_FUP_FMT;
len= __msg_pack_header(ppi, mf);
/* Header */
*(UInteger8 *) (buf + 4) = hdr->domainNumber; /* FIXME: why? */
/* We should copy the correction field and add our fractional part */
hdr->cField.scaled_nsecs
+= prec_orig_tstamp->scaled_nsecs & 0xffff;
normalize_pp_time(&hdr->cField);
*(Integer64 *) (buf + 8) = htonll(hdr->cField.scaled_nsecs);
*(UInteger16 *) (buf + 30) = htons(hdr->sequenceId);
/* requestReceiptTimestamp */
__pack_origin_timestamp(buf,prec_orig_tstamp);
/* requestingPortIdentity */
memcpy((buf + 44), &hdr->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 52) = htons(hdr->sourcePortIdentity.portNumber);
return len;
}
/* Unpack FollowUp message from in buffer of ppi to internal structure */
void msg_unpack_follow_up(void *buf, MsgFollowUp *flwup)
{
......@@ -339,19 +299,6 @@ void msg_unpack_follow_up(void *buf, MsgFollowUp *flwup)
/* cField added by the caller, from already-converted header */
}
/* Unpack PDelayRespFollowUp message from in buffer of ppi to internal struct */
void msg_unpack_pdelay_resp_follow_up(void *buf,
MsgPDelayRespFollowUp * pdelay_resp_flwup)
{
__unpack_origin_timestamp(buf,&pdelay_resp_flwup->responseOriginTimestamp);
/* cField added by the caller, as it's already converted */
memcpy(&pdelay_resp_flwup->requestingPortIdentity.clockIdentity,
(buf + 44), PP_CLOCK_IDENTITY_LENGTH);
pdelay_resp_flwup->requestingPortIdentity.portNumber =
ntohs(*(UInteger16 *) (buf + 52));
}
/* pack DelayReq message into out buffer of ppi */
static int msg_pack_delay_req(struct pp_instance *ppi,
struct pp_time *now)
......@@ -371,50 +318,6 @@ static int msg_pack_delay_req(struct pp_instance *ppi,
return len;
}
/* pack DelayReq message into out buffer of ppi */
static int msg_pack_pdelay_req(struct pp_instance *ppi,
struct pp_time *now)
{
void *buf = ppi->tx_ptp;
struct pp_msgtype_info *mf = pp_msgtype_info + PPM_PDELAY_REQ_FMT;
int len= __msg_pack_header(ppi, mf);
/* Header */
__msg_set_seq_id(ppi,mf);
/* PDelay_req message - we may send zero instead */
__pack_origin_timestamp(buf,now);
memset((buf + 44), 0, 10);
return len;
}
/* pack PDelayResp message into OUT buffer of ppi */
static int msg_pack_pdelay_resp(struct pp_instance *ppi,
MsgHeader * hdr, struct pp_time *rcv_tstamp)
{
void *buf = ppi->tx_ptp;
UInteger8 *flags8 = buf + 6;;
struct pp_msgtype_info *mf = pp_msgtype_info + PPM_PDELAY_RESP_FMT;
int len= __msg_pack_header(ppi, mf);
/* Header */
flags8[0] = PP_TWO_STEP_FLAG; /* Table 20) */
*(UInteger16 *) (buf + 30) = htons(hdr->sequenceId);
/* cField: shdould be the fractional negated (see README-cfield) */
*(UInteger64 *)(buf + 8) =
htonll(rcv_tstamp->scaled_nsecs & 0xffff);
/* requestReceiptTimestamp */
__pack_origin_timestamp(buf,rcv_tstamp);
/* requestingPortIdentity */
memcpy((buf + 44), &hdr->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 52) = htons(hdr->sourcePortIdentity.portNumber);
return len;
}
/* pack DelayResp message into OUT buffer of ppi */
static int msg_pack_delay_resp(struct pp_instance *ppi,
MsgHeader *hdr, struct pp_time *rcv_tstamp)
......@@ -447,12 +350,6 @@ void msg_unpack_delay_req(void *buf, MsgDelayReq *delay_req)
__unpack_origin_timestamp(buf,&delay_req->originTimestamp);
}
/* Unpack PDelayReq message from in buffer of ppi to internal structure */
void msg_unpack_pdelay_req(void *buf, MsgPDelayReq * pdelay_req)
{
__unpack_origin_timestamp(buf,&pdelay_req->originTimestamp);
}
/* Unpack delayResp message from IN buffer of ppi to internal structure */
void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp)
{
......@@ -465,18 +362,6 @@ void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp)
ntohs(*(UInteger16 *) (buf + 52));
}
/* Unpack PDelayResp message from IN buffer of ppi to internal structure */
void msg_unpack_pdelay_resp(void *buf, MsgPDelayResp * presp)
{
__unpack_origin_timestamp(buf,&presp->requestReceiptTimestamp);
/* cfield added in the caller */
memcpy(&presp->requestingPortIdentity.clockIdentity,
(buf + 44), PP_CLOCK_IDENTITY_LENGTH);
presp->requestingPortIdentity.portNumber =
ntohs(*(UInteger16 *) (buf + 52));
}
/* Pack and send on general multicast ip adress an Announce message */
int msg_issue_announce(struct pp_instance *ppi)
{
......@@ -502,14 +387,6 @@ int msg_issue_sync_followup(struct pp_instance *ppi)
return __send_and_log(ppi, len, PP_NP_GEN,PPM_FOLLOW_UP_FMT);
}
/* Pack and send on general multicast ip address a FollowUp message */
int msg_issue_pdelay_resp_followup(struct pp_instance *ppi, struct pp_time *t)
{
int len;
len = msg_pack_pdelay_resp_follow_up(ppi, &ppi->received_ptp_header, t);
return __send_and_log(ppi, len, PP_NP_GEN,PPM_PDELAY_R_FUP_FMT);
}
/* Pack and send on event multicast ip adress a DelayReq message */
static int msg_issue_delay_req(struct pp_instance *ppi)
......@@ -523,22 +400,12 @@ static int msg_issue_delay_req(struct pp_instance *ppi)
return __send_and_log(ppi, len, PP_NP_EVT,PPM_DELAY_REQ_FMT);
}
/* Pack and send on event multicast ip adress a PDelayReq message */
static int msg_issue_pdelay_req(struct pp_instance *ppi)
{
struct pp_time now;
int len;
mark_incorrect(&ppi->t4); /* see commit message */
ppi->t_ops->get(ppi, &now);
len = msg_pack_pdelay_req(ppi, &now);
return __send_and_log(ppi, len, PP_NP_EVT,PPM_PDELAY_REQ_FMT);
}
int msg_issue_request(struct pp_instance *ppi)
{
if (CONFIG_HAS_P2P && ppi->delayMechanism == P2P)
#if CONFIG_HAS_P2P
if (ppi->delayMechanism == P2P)
return msg_issue_pdelay_req(ppi);
#endif
return msg_issue_delay_req(ppi);
}
......@@ -551,11 +418,3 @@ int msg_issue_delay_resp(struct pp_instance *ppi, struct pp_time *t)
return __send_and_log(ppi, len, PP_NP_GEN,PPM_DELAY_RESP_FMT);
}
/* Pack and send on event multicast ip adress a DelayResp message */
int msg_issue_pdelay_resp(struct pp_instance *ppi, struct pp_time *t)
{
int len;
len = msg_pack_pdelay_resp(ppi, &ppi->received_ptp_header, t);
return __send_and_log(ppi, len, PP_NP_EVT,PPM_PDELAY_RESP_FMT);
}
/*
* Copyright (C) 2011 CERN (www.cern.ch)
* Author:Jean-Claude BAU
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#ifndef __MSG_H
#define __MSG_H
#define htonll(x) ((*(char *)&endianess == 1) ? \
htobe64(x) /* Little endian */ \
: \
(x)) /* Big endian */
#define ntohll(x) ((*(char *)&endianess == 1) ? \
be64toh(x) /* Little endian */ \
: \
(x)) /* Big endian */
extern const int endianess; /* use to check endianess */
extern int msg_unpack_header(struct pp_instance *ppi, void *buf, int len);
extern void msg_init_header(struct pp_instance *ppi, void *buf);
extern void __msg_set_seq_id(struct pp_instance *ppi,
struct pp_msgtype_info *mf);
extern int __msg_pack_header(struct pp_instance *ppi,
struct pp_msgtype_info *msg_fmt);
extern void __pack_origin_timestamp(void *buf, struct pp_time *orig_tstamp);
extern void __unpack_origin_timestamp(void *buf, struct pp_time *orig_tstamp);
extern int __msg_pack_header(struct pp_instance *ppi, struct pp_msgtype_info *msg_fmt);
extern int msg_issue_pdelay_req(struct pp_instance *ppi);
#endif /* __MSG_H */
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