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

13 14
	if (ppi->is_new_state) {
		pp_timer_start(1 << DSPOR(ppi)->logMinPdelayReqInterval,
15
			ppi->timers[PP_TIMER_PDELAYREQ]);
16 17 18 19 20 21 22

		st_com_restart_annrec_timer(ppi);
	}

	if (st_com_check_record_update(ppi))
		goto state_updated;

23
	switch (ppi->msg_tmp_header.messageType) {
24 25

	case PPM_ANNOUNCE:
26
		e = st_com_master_handle_announce(ppi, pkt, plen);
27 28
		break;

29
	case PPM_PDELAY_REQ:
30
		e = st_com_handle_pdelay_req(ppi, pkt, plen);
31 32
		break;

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

37 38 39 40
	default:
		/* disreguard, nothing to do */
		break;

41 42
	}

43
	if (e == 0)
44 45 46
		e = st_com_execute_slave(ppi);

	if (e != 0)
47 48
		ppi->next_state = PPS_FAULTY;

49 50 51 52

state_updated:
	/* Leaving this state */
	if (ppi->next_state != ppi->state) {
53 54
		pp_timer_stop(ppi->timers[PP_TIMER_ANN_RECEIPT]);
		pp_timer_stop(ppi->timers[PP_TIMER_PDELAYREQ]);
55 56
	}

57
	ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
58

59 60
	return 0;
}