common-fun.h 1.51 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
 */

9 10 11
#ifndef __COMMON_FUN_H
#define __COMMON_FUN_H

Alessandro Rubini's avatar
Alessandro Rubini committed
12
#include <ppsi/ppsi.h>
13 14 15

/* Contains all functions common to more than one state */

16
/* returns -1 in case of error, see below */
17
int st_com_execute_slave(struct pp_instance *ppi);
18

19 20 21 22
/* Each of the following "handle" functions" return 0 in case of correct
 * message, -1 in case the message contained in buf is not proper (e.g. size
 * is not the expected one
 */
23
int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
24
			     int len);
25

26
int st_com_master_handle_sync(struct pp_instance *ppi, unsigned char *buf,
27
			      int len);
28

29 30
int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
				 int len);
31

32 33 34 35 36 37
int st_com_peer_handle_preq(struct pp_instance *ppi, unsigned char *buf,
			    int len);

int st_com_peer_handle_pres(struct pp_instance *ppi, unsigned char *buf,
			    int len);

38 39 40
int st_com_peer_handle_pres_followup(struct pp_instance *ppi,
				     unsigned char *buf, int len);

41
int __send_and_log(struct pp_instance *ppi, int msglen, int chtype);
42

43 44
/* Count successfully received PTP packets */
static inline int __recv_and_count(struct pp_instance *ppi, void *pkt, int len,
45
		   struct pp_time *t)
46 47 48
{
	int ret;
	ret = ppi->n_ops->recv(ppi, pkt, len, t);
49
	if (ret > 0)
50 51 52 53
		ppi->ptp_rx_count++;
	return ret;
}

54
#endif /* __COMMON_FUN_H */