state-passive.c 1.28 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_passive(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
14
	int e = 0; /* error var, to check errors in msg handling */
15

16
	/* when the clock is using peer-delay, listening must send it too */
17
	if (CONFIG_HAS_P2P && ppi->mech == PP_P2P_MECH)
18
		e  = pp_lib_may_issue_request(ppi);
19

20
	switch (ppi->received_ptp_header.messageType) {
21 22

	case PPM_ANNOUNCE:
23
		e = pp_lib_handle_announce(ppi, pkt, plen);
24 25
		break;

26
	case PPM_SYNC:
27
		e = st_com_master_handle_sync(ppi, pkt, plen);
28 29
		break;

30
	case PPM_PDELAY_REQ:
31 32
		if (CONFIG_HAS_P2P)
			st_com_peer_handle_preq(ppi, pkt, plen);
33 34 35
		break;

	case PPM_PDELAY_RESP:
36 37
		if (CONFIG_HAS_P2P)
			e = st_com_peer_handle_pres(ppi, pkt, plen);
38 39
		break;

40
	case PPM_PDELAY_R_FUP:
41 42
		if (CONFIG_HAS_P2P)
			e = st_com_peer_handle_pres_followup(ppi, pkt, plen);
43 44
		break;

45 46 47 48
	default:
		/* disreguard, nothing to do */
		break;

49 50
	}

51
	if (e == 0)
52
		e = st_com_execute_slave(ppi);
53

54 55 56
	if (e != 0) {
		/* ignore: a lost frame is not the end of the world */
	}
57

58
	ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
59

60 61
	return 0;
}