state-faulty.c 1.48 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

baujc's avatar
baujc committed
11 12
#define TIMEOUT_FAULTY_STATE_MS (60*1000) /* define the time to stay on faulty state before to go to initializing state */

13
/*
14 15
 * Fault troubleshooting. Now only comes back to
 * PTP_INITIALIZING state after a grace period.
16 17
 */

18
int pp_faulty(struct pp_instance *ppi, void *buf, int len)
19
{
baujc's avatar
baujc committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

	/* If the clockClass is < 128 and externalPortConfigurationEnabled is active,
	 * states SALVE and UNCALIBRATED are not allowed. We must stay in FAULTY state.
	 */
	if (is_externalPortConfigurationEnabled(DSDEF(ppi))) {
		Enumeration8 desiredState=ppi->externalPortConfigurationPortDS.desiredState;

		if ( DSDEF(ppi)->clockQuality.clockClass<128  &&
				(desiredState == PPS_SLAVE || desiredState == PPS_UNCALIBRATED)
				) {
			/*
			 * We set the next delay to an arbitrary value (1s) as we should stay forever
			 * in this state.
			 */
			ppi->next_delay = 1000; /* 1s */
			return 0;
		}
37
	}
baujc's avatar
baujc committed
38 39 40 41 42 43 44 45 46 47 48 49 50
	if ( ppi->is_new_state) {
		pp_timeout_set(ppi,PP_TO_IN_STATE, TIMEOUT_FAULTY_STATE_MS);
	} else {
		/* Check if we can exit from FAULTY state */
		if (pp_timeout(ppi, PP_TO_IN_STATE)) {
			pp_timeout_disable(ppi,PP_TO_IN_STATE);
			ppi->next_state = PPS_INITIALIZING;
			return 0;
		}
	}

	/* We stay on FAULTY state */
	ppi->next_delay = pp_next_delay_1(ppi, PP_TO_IN_STATE);
51 52
	return 0;
}