state-listening.c 977 Bytes
Newer Older
1
/*
2 3
 * Aurelio Colosimo for CERN, 2011 -- GNU LGPL v2.1 or later
 * Based on PTPd project v. 2.1.0 (see AUTHORS for details)
4
 */
5

6
#include <pptp/pptp.h>
7
#include "common-fun.h"
8 9 10

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

	if (ppi->is_new_state)
14
		st_com_restart_annrec_timer(ppi);
15

16 17
	if (st_com_check_record_update(ppi))
		goto state_updated;
18

19 20 21
	switch (ppi->msg_tmp_header.messageType) {

	case PPM_ANNOUNCE:
22
		e = st_com_master_handle_announce(ppi, pkt, plen);
23 24
		break;

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

29 30 31
	default:
		/* disreguard, nothing to do */
		break;
32
	}
33

34
	if (e == 0)
35 36 37
		e = st_com_execute_slave(ppi);

	if (e != 0)
38
		ppi->next_state = PPS_FAULTY;
39

40
state_updated:
41
	/* Leaving this state */
42
	if (ppi->next_state != ppi->state)
43
		pp_timer_stop(ppi->timers[PP_TIMER_ANN_RECEIPT]);
44

45
	ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
46

47 48
	return 0;
}