state-initializing.c 2.01 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 7
#include <pptp/pptp.h>
#include <pptp/diag.h>
8 9 10 11 12 13 14

/*
 * Initializes network and other stuff
 */

int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
15 16 17
	struct pp_runtime_opts *rt_opts = ppi->rt_opts;

	pp_net_shutdown(ppi);
18

19 20
	if (pp_net_init(ppi) < 0)
		goto failure;
21 22

	/* Initialize default data set */
23
	DSDEF(ppi)->twoStepFlag = PP_TWO_STEP_FLAG;
24
	/* TODO initialize clockIdentity with MAC address */
25 26 27 28
	DSDEF(ppi)->clockIdentity[3] = 0xff;
	DSDEF(ppi)->clockIdentity[4] = 0xfe;
	DSDEF(ppi)->numberPorts = 1;
	pp_memcpy(&DSDEF(ppi)->clockQuality, &rt_opts->clock_quality,
29
		sizeof(ClockQuality));
30 31 32 33
	DSDEF(ppi)->priority1 = rt_opts->prio1;
	DSDEF(ppi)->priority2 = rt_opts->prio2;
	DSDEF(ppi)->domainNumber = rt_opts->domain_number;
	DSDEF(ppi)->slaveOnly = rt_opts->slave_only;
34 35 36 37 38 39
	if (rt_opts->slave_only)
		ppi->defaultDS->clockQuality.clockClass = 255;

	/* Initialize port data set */
	pp_memcpy(ppi->portDS->portIdentity.clockIdentity,
		ppi->defaultDS->clockIdentity, PP_CLOCK_IDENTITY_LENGTH);
40 41 42 43 44 45
	DSPOR(ppi)->portIdentity.portNumber = 1;
	DSPOR(ppi)->logMinDelayReqInterval = PP_DEFAULT_DELAYREQ_INTERVAL;
	DSPOR(ppi)->peerMeanPathDelay.seconds = 0;
	DSPOR(ppi)->peerMeanPathDelay.nanoseconds = 0;
	DSPOR(ppi)->logAnnounceInterval = rt_opts->announce_intvl;
	DSPOR(ppi)->announceReceiptTimeout =
46
		PP_DEFAULT_ANNOUNCE_RECEIPT_TIMEOUT;
47 48 49 50
	DSPOR(ppi)->logSyncInterval = rt_opts->sync_intvl;
	DSPOR(ppi)->delayMechanism = PP_DEFAULT_DELAY_MECHANISM;
	DSPOR(ppi)->logMinPdelayReqInterval = PP_DEFAULT_PDELAYREQ_INTERVAL;
	DSPOR(ppi)->versionNumber = PP_VERSION_PTP;
51

52
	if (pp_timer_init(ppi))
53 54
		goto failure;

55
	pp_init_clock(ppi);
56

57 58
	m1(ppi);

59
	msg_pack_header(ppi, ppi->buf_out);
60

61
	ppi->next_state = PPS_LISTENING;
62
	ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
63 64 65 66 67
	return 0;

failure:
	pp_printf("Failed to initialize network\n");
	ppi->next_state = PPS_FAULTY;
68
	ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
69 70
	return 0;
}