state-passive.c 1.18 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
	TimeInternal time; /* TODO: handle it, see handle(...) in protocol.c */
12
	int e = 0; /* error var, to check errors in msg handling */
13

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

		st_com_restart_annrec_timer(ppi);
	}

	if (st_com_check_record_update(ppi))
		goto state_updated;

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

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

30
	case PPM_PDELAY_REQ:
31
		e = st_com_handle_pdelay_req(ppi, pkt, plen, &time);
32 33 34 35 36 37
		break;

	default:
		/* disreguard, nothing to do */
		break;

38 39
	}

40 41 42 43 44
	if (e == 0)
		st_com_execute_slave(ppi);
	else
		ppi->next_state = PPS_FAULTY;

45 46 47 48

state_updated:
	/* Leaving this state */
	if (ppi->next_state != ppi->state) {
49 50
		pp_timer_stop(ppi->timers[PP_TIMER_ANN_RECEIPT]);
		pp_timer_stop(ppi->timers[PP_TIMER_PDELAYREQ]);
51 52
	}

53
	ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
54

55 56
	return 0;
}