Commit b5b16b95 authored by Alessandro Rubini's avatar Alessandro Rubini

fsm.c: bugfix on frame error

fsm.c corrently decodes the received frame, and error management is
built in (even if code in msg.c still needs to be audited to be more
careful about rogue frames).  However, when a received frame is in
error, fsm.c cannot return to the caller because it doesn't know the
current delay. Thus, zero the frame and call the current status, so
we have back a recalculated ppi->next_delay.

Meanwhile, mask with pp_verbose_frames the diagnostic message for
received frames -- and be more careful with accessing it's data.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 32995f14
......@@ -20,17 +20,28 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
struct pp_state_table_item *ip;
int state, err = 0;
if (plen && plen < PP_HEADER_LENGTH)
err = -1;
if (plen >= PP_HEADER_LENGTH) {
PP_VPRINTF("RECV %02d %d.%09d %s\n", plen,
(int)ppi->last_rcv_time.seconds,
(int)ppi->last_rcv_time.nanoseconds,
pp_msg_names[packet[0] & 0x0f]);
err = msg_unpack_header(ppi, packet);
if (plen && pp_verbose_frames) {
PP_VPRINTF("RECV %02d bytes at %d.%09d (type %x)\n", plen,
(int)ppi->last_rcv_time.seconds,
(int)ppi->last_rcv_time.nanoseconds,
packet[0] & 0xf);
}
/*
* Since all ptp frames have the same header, parse it now.
* In case of error continue without a frame, so the current
* ptp state can update ppi->next_delay and return a proper value
*/
if (plen) {
if (plen >= PP_HEADER_LENGTH)
err = msg_unpack_header(ppi, packet);
else
err = 1;
if (err) {
plen = 0;
packet = NULL;
}
}
if (err)
return ppi->next_delay;
state = ppi->state;
......
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