Convert TLV type and length to host byte order on receive.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>master
parent
aeba3afd91
commit
f20cf6225a
36
msg.c
36
msg.c
|
@ -142,6 +142,32 @@ static void port_id_pre_send(struct PortIdentity *pid)
|
||||||
pid->portNumber = htons(pid->portNumber);
|
pid->portNumber = htons(pid->portNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int suffix_post_recv(uint8_t *ptr, int len)
|
||||||
|
{
|
||||||
|
int cnt;
|
||||||
|
struct TLV *tlv;
|
||||||
|
|
||||||
|
if (!ptr)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (cnt = 0; len > sizeof(struct TLV); cnt++) {
|
||||||
|
tlv = (struct TLV *) ptr;
|
||||||
|
tlv->type = ntohs(tlv->type);
|
||||||
|
tlv->length = ntohs(tlv->length);
|
||||||
|
if (tlv->length % 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
len -= sizeof(struct TLV);
|
||||||
|
ptr += sizeof(struct TLV);
|
||||||
|
if (tlv->length > len) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
len -= tlv->length;
|
||||||
|
ptr += tlv->length;
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
static void timestamp_post_recv(struct ptp_message *m, struct Timestamp *ts)
|
static void timestamp_post_recv(struct ptp_message *m, struct Timestamp *ts)
|
||||||
{
|
{
|
||||||
uint32_t lsb = ntohl(ts->seconds_lsb);
|
uint32_t lsb = ntohl(ts->seconds_lsb);
|
||||||
|
@ -193,6 +219,7 @@ void msg_get(struct ptp_message *m)
|
||||||
int msg_post_recv(struct ptp_message *m, int cnt)
|
int msg_post_recv(struct ptp_message *m, int cnt)
|
||||||
{
|
{
|
||||||
int pdulen, type;
|
int pdulen, type;
|
||||||
|
uint8_t *suffix = NULL;
|
||||||
|
|
||||||
if (cnt < sizeof(struct ptp_header))
|
if (cnt < sizeof(struct ptp_header))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -254,21 +281,28 @@ int msg_post_recv(struct ptp_message *m, int cnt)
|
||||||
break;
|
break;
|
||||||
case FOLLOW_UP:
|
case FOLLOW_UP:
|
||||||
timestamp_post_recv(m, &m->follow_up.preciseOriginTimestamp);
|
timestamp_post_recv(m, &m->follow_up.preciseOriginTimestamp);
|
||||||
|
suffix = m->follow_up.suffix;
|
||||||
break;
|
break;
|
||||||
case DELAY_RESP:
|
case DELAY_RESP:
|
||||||
timestamp_post_recv(m, &m->delay_resp.receiveTimestamp);
|
timestamp_post_recv(m, &m->delay_resp.receiveTimestamp);
|
||||||
|
suffix = m->delay_resp.suffix;
|
||||||
break;
|
break;
|
||||||
case PDELAY_RESP_FOLLOW_UP:
|
case PDELAY_RESP_FOLLOW_UP:
|
||||||
timestamp_post_recv(m, &m->pdelay_resp_fup.responseOriginTimestamp);
|
timestamp_post_recv(m, &m->pdelay_resp_fup.responseOriginTimestamp);
|
||||||
port_id_post_recv(&m->pdelay_resp_fup.requestingPortIdentity);
|
port_id_post_recv(&m->pdelay_resp_fup.requestingPortIdentity);
|
||||||
|
suffix = m->pdelay_resp_fup.suffix;
|
||||||
break;
|
break;
|
||||||
case ANNOUNCE:
|
case ANNOUNCE:
|
||||||
clock_gettime(CLOCK_MONOTONIC, &m->ts.host);
|
clock_gettime(CLOCK_MONOTONIC, &m->ts.host);
|
||||||
timestamp_post_recv(m, &m->announce.originTimestamp);
|
timestamp_post_recv(m, &m->announce.originTimestamp);
|
||||||
announce_post_recv(&m->announce);
|
announce_post_recv(&m->announce);
|
||||||
|
suffix = m->announce.suffix;
|
||||||
break;
|
break;
|
||||||
case SIGNALING:
|
case SIGNALING:
|
||||||
|
suffix = m->signaling.suffix;
|
||||||
|
break;
|
||||||
case MANAGEMENT:
|
case MANAGEMENT:
|
||||||
|
suffix = m->management.suffix;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,6 +311,8 @@ int msg_post_recv(struct ptp_message *m, int cnt)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m->tlv_count = suffix_post_recv(suffix, cnt - pdulen);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue