state-listening.c 1.42 KB
Newer Older
1
/*
2 3
 * Copyright (C) 2011 CERN (www.cern.ch)
 * Author: Aurelio Colosimo
4
 * Based on PTPd project v. 2.1.0 (see AUTHORS for details)
5 6
 *
 * Released according to the GNU LGPL, version 2.1 or any later version.
7
 */
8

Alessandro Rubini's avatar
Alessandro Rubini committed
9
#include <ppsi/ppsi.h>
10
#include "common-fun.h"
11 12 13

int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
14
	int e = 0; /* error var, to check errors in msg handling */
15

16
	pp_timeout_set(ppi, PP_TO_FAULT); /* no fault as long as we listen */
17 18 19
	if (pp_hooks.listening)
		e = pp_hooks.listening(ppi, pkt, plen);
	if (e)
20
		goto out;
21

22
	/* when the clock is using peer-delay, listening must send it too */
23
	if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH)
24
		e  = pp_lib_may_issue_request(ppi);
25

26
	switch (ppi->received_ptp_header.messageType) {
27 28

	case PPM_ANNOUNCE:
29
		e = pp_lib_handle_announce(ppi, pkt, plen);
30 31
		break;

32
	case PPM_SYNC:
33
		e = st_com_master_handle_sync(ppi, pkt, plen);
34 35
		break;

36
	case PPM_PDELAY_REQ:
37 38
		if (CONFIG_HAS_P2P)
			st_com_peer_handle_preq(ppi, pkt, plen);
39 40 41
		break;

	case PPM_PDELAY_RESP:
42 43
		if (CONFIG_HAS_P2P)
			e = st_com_peer_handle_pres(ppi, pkt, plen);
44 45
		break;

46
	case PPM_PDELAY_R_FUP:
47 48
		if (CONFIG_HAS_P2P)
			e = st_com_peer_handle_pres_followup(ppi, pkt, plen);
49 50
		break;

51
	default:
52
		/* disregard, nothing to do */
53
		break;
54
	}
55

56
out:
57
	if (e == 0)
58
		e = st_com_execute_slave(ppi);
59 60

	if (e != 0)
61
		ppi->next_state = PPS_FAULTY;
62

63
	ppi->next_delay = pp_next_delay_1(ppi, PP_TO_ANN_RECEIPT);
64

65 66
	return 0;
}