state-listening.c 890 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 25 26 27
		break;

	default:
		/* disreguard, nothing to do */
		break;
28
	}
29

30 31 32 33
	if (e == 0)
		st_com_execute_slave(ppi);
	else
		ppi->next_state = PPS_FAULTY;
34

35
state_updated:
36
	/* Leaving this state */
37
	if (ppi->next_state != ppi->state)
38
		pp_timer_stop(ppi->timers[PP_TIMER_ANN_RECEIPT]);
39

40
	ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
41

42 43
	return 0;
}