state-initializing.c 2.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * FIXME: header
 */
#include <pproto/pproto.h>
#include <dep/dep.h>

/*
 * Initializes network and other stuff
 */

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

	pp_net_shutdown(ppi);
16 17 18
	
	if (pp_net_init(ppi) < 0)
		goto failure;
19 20

	/* Initialize default data set */
21
	DSDEF(ppi)->twoStepFlag = PP_TWO_STEP_FLAG;
22
	/* TODO initialize clockIdentity with MAC address */
23 24 25 26
	DSDEF(ppi)->clockIdentity[3] = 0xff;
	DSDEF(ppi)->clockIdentity[4] = 0xfe;
	DSDEF(ppi)->numberPorts = 1;
	pp_memcpy(&DSDEF(ppi)->clockQuality, &rt_opts->clock_quality,
27
		sizeof(ClockQuality));
28 29 30 31
	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;
32 33 34 35 36 37
	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);
38 39 40 41 42 43
	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 =
44
		PP_DEFAULT_ANNOUNCE_RECEIPT_TIMEOUT;
45 46 47 48
	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;
49

50
	if (pp_timer_init(ppi))
51 52
		goto failure;

53 54 55 56 57 58 59 60 61 62 63 64
	/* TODO Check the following code coming from ptpd.
	 *
	 * Init all remaining stuff:
	 * initClock(rtOpts, ptpClock);
	 *
	 * Set myself as master (in case will not receive any announce):
	 * m1(ptpClock);
	 *
	 * Prepare a message:
	 * msgPackHeader(ptpClock->msgObuf,ptpClock);
	 */

65 66 67 68 69 70 71 72
	ppi->next_state = PPS_LISTENING;
	return 0;

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