Commit e4408b7f authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Adam Wujek

general: add correctionField directly in unpack

I got wrong several times with this. Time to fix.

The correctionField is part of the timestamp, so it's better dealt
with when the timestamp is recovered.

NOTE: correctionfields in the "response" direction should be subtracted.
We always added isntead, and we keep addition for compatibility.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent ebd03f57
...@@ -214,7 +214,6 @@ int wr_servo_got_delay(struct pp_instance *ppi) ...@@ -214,7 +214,6 @@ int wr_servo_got_delay(struct pp_instance *ppi)
s->t3 = ppi->t3; s->t3 = ppi->t3;
/* s->t3.phase = 0; */ /* s->t3.phase = 0; */
s->t4 = ppi->t4; s->t4 = ppi->t4;
/* FIXME: verify that cField is already merged */
if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH) { if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH) {
s->t5 = ppi->t5; s->t5 = ppi->t5;
......
...@@ -146,7 +146,6 @@ int st_com_peer_handle_pres(struct pp_instance *ppi, unsigned char *buf, ...@@ -146,7 +146,6 @@ int st_com_peer_handle_pres(struct pp_instance *ppi, unsigned char *buf,
(ppi->flags & PPI_FLAG_FROM_CURRENT_PARENT)) { (ppi->flags & PPI_FLAG_FROM_CURRENT_PARENT)) {
ppi->t4 = resp.requestReceiptTimestamp; ppi->t4 = resp.requestReceiptTimestamp;
pp_time_add(&ppi->t4, &hdr->cField);
ppi->t6 = ppi->last_rcv_time; ppi->t6 = ppi->last_rcv_time;
if ((hdr->flagField[0] & PP_TWO_STEP_FLAG) != 0) if ((hdr->flagField[0] & PP_TWO_STEP_FLAG) != 0)
ppi->flags |= PPI_FLAG_WAITING_FOR_RF_UP; ppi->flags |= PPI_FLAG_WAITING_FOR_RF_UP;
...@@ -192,11 +191,6 @@ int st_com_peer_handle_pres_followup(struct pp_instance *ppi, ...@@ -192,11 +191,6 @@ int st_com_peer_handle_pres_followup(struct pp_instance *ppi,
(ppi->flags & PPI_FLAG_FROM_CURRENT_PARENT)) { (ppi->flags & PPI_FLAG_FROM_CURRENT_PARENT)) {
ppi->t5 = respFllw.responseOriginTimestamp; ppi->t5 = respFllw.responseOriginTimestamp;
/*
* Add correctionField of pdelay_resp_followup to
* cf of pdelay_resp (see 11.4.3 d 4)
*/
pp_time_add(&ppi->t4, &hdr->cField);
if (pp_hooks.handle_presp) if (pp_hooks.handle_presp)
e = pp_hooks.handle_presp(ppi); e = pp_hooks.handle_presp(ppi);
......
...@@ -279,7 +279,7 @@ void msg_unpack_follow_up(void *buf, MsgFollowUp *flwup) ...@@ -279,7 +279,7 @@ void msg_unpack_follow_up(void *buf, MsgFollowUp *flwup)
void msg_unpack_pdelay_resp_follow_up(void *buf, void msg_unpack_pdelay_resp_follow_up(void *buf,
MsgPDelayRespFollowUp * pdelay_resp_flwup) MsgPDelayRespFollowUp * pdelay_resp_flwup)
{ {
int64_t secs, nsecs; int64_t secs, nsecs, cf;
secs = htons(*(UInteger16 *) (buf + 34)); secs = htons(*(UInteger16 *) (buf + 34));
secs <<= 32; secs <<= 32;
...@@ -290,6 +290,14 @@ void msg_unpack_pdelay_resp_follow_up(void *buf, ...@@ -290,6 +290,14 @@ void msg_unpack_pdelay_resp_follow_up(void *buf,
pdelay_resp_flwup->responseOriginTimestamp.scaled_nsecs = pdelay_resp_flwup->responseOriginTimestamp.scaled_nsecs =
nsecs << 16; nsecs << 16;
/* add correction factor, already_scaled */
cf = ntohl(*(UInteger32 *) (buf + 8));
cf <<= 32;
cf |= ntohl(*(UInteger32 *) (buf + 12));
pdelay_resp_flwup->responseOriginTimestamp += cf;
/* FIXME: normalize? */
memcpy(&pdelay_resp_flwup->requestingPortIdentity.clockIdentity, memcpy(&pdelay_resp_flwup->requestingPortIdentity.clockIdentity,
(buf + 44), PP_CLOCK_IDENTITY_LENGTH); (buf + 44), PP_CLOCK_IDENTITY_LENGTH);
pdelay_resp_flwup->requestingPortIdentity.portNumber = pdelay_resp_flwup->requestingPortIdentity.portNumber =
...@@ -413,7 +421,7 @@ void msg_unpack_pdelay_req(void *buf, MsgPDelayReq * pdelay_req) ...@@ -413,7 +421,7 @@ void msg_unpack_pdelay_req(void *buf, MsgPDelayReq * pdelay_req)
/* Unpack delayResp message from IN buffer of ppi to internal structure */ /* Unpack delayResp message from IN buffer of ppi to internal structure */
void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp) void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp)
{ {
int64_t secs, nsecs; int64_t secs, nsecs, cf;
secs = htons(*(UInteger16 *) (buf + 34)); secs = htons(*(UInteger16 *) (buf + 34));
secs <<= 32; secs <<= 32;
...@@ -423,6 +431,13 @@ void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp) ...@@ -423,6 +431,13 @@ void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp)
resp->receiveTimestamp.secs = secs; resp->receiveTimestamp.secs = secs;
resp->receiveTimestamp.scaled_nsecs = nsecs << 16; resp->receiveTimestamp.scaled_nsecs = nsecs << 16;
/* add correction factor, already_scaled */
cf = ntohl(*(UInteger32 *) (buf + 8));
cf <<= 32;
cf |= ntohl(*(UInteger32 *) (buf + 12));
resp->receiveTimestamp.scaled_nsecs += cf;
/* FIXME: normalize? */
memcpy(&resp->requestingPortIdentity.clockIdentity, memcpy(&resp->requestingPortIdentity.clockIdentity,
(buf + 44), PP_CLOCK_IDENTITY_LENGTH); (buf + 44), PP_CLOCK_IDENTITY_LENGTH);
resp->requestingPortIdentity.portNumber = resp->requestingPortIdentity.portNumber =
...@@ -432,16 +447,23 @@ void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp) ...@@ -432,16 +447,23 @@ void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp)
/* Unpack PDelayResp message from IN buffer of ppi to internal structure */ /* Unpack PDelayResp message from IN buffer of ppi to internal structure */
void msg_unpack_pdelay_resp(void *buf, MsgPDelayResp * presp) void msg_unpack_pdelay_resp(void *buf, MsgPDelayResp * presp)
{ {
int64_t secs, nsecs; int64_t secs, nsecs, cf;
secs = htons(*(UInteger16 *) (buf + 34)); secs = ntohs(*(UInteger16 *) (buf + 34));
secs <<= 32; secs <<= 32;
secs |= htonl(*(UInteger32 *) (buf + 36)); secs |= ntohl(*(UInteger32 *) (buf + 36));
nsecs = htonl(*(UInteger32 *) (buf + 40)); nsecs = ntohl(*(UInteger32 *) (buf + 40));
presp->requestReceiptTimestamp.secs = secs; presp->requestReceiptTimestamp.secs = secs;
presp->requestReceiptTimestamp.scaled_nsecs = nsecs << 16; presp->requestReceiptTimestamp.scaled_nsecs = nsecs << 16;
/* add correction factor, already_scaled */
cf = ntohl(*(UInteger32 *) (buf + 8));
cf <<= 32;
cf |= ntohl(*(UInteger32 *) (buf + 12));
presp->requestReceiptTimestamp.scaled_nsecs += cf;
/* FIXME: normalize? */
memcpy(&presp->requestingPortIdentity.clockIdentity, memcpy(&presp->requestingPortIdentity.clockIdentity,
(buf + 44), PP_CLOCK_IDENTITY_LENGTH); (buf + 44), PP_CLOCK_IDENTITY_LENGTH);
presp->requestingPortIdentity.portNumber = presp->requestingPortIdentity.portNumber =
......
...@@ -52,8 +52,6 @@ static int slave_handle_response(struct pp_instance *ppi, unsigned char *pkt, ...@@ -52,8 +52,6 @@ static int slave_handle_response(struct pp_instance *ppi, unsigned char *pkt,
} }
ppi->t4 = resp.receiveTimestamp; ppi->t4 = resp.receiveTimestamp;
pp_time_add(&ppi->t4, &hdr->cField);
/* NOTE: older code was adding cField later, in hooks.handle_resp */
if (pp_hooks.handle_resp) if (pp_hooks.handle_resp)
e = pp_hooks.handle_resp(ppi); e = pp_hooks.handle_resp(ppi);
......
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