common-fun.h 1.69 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 24
int st_com_slave_handle_announce(struct pp_instance *ppi, unsigned char *buf,
				 int len);
25

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

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

32
int st_com_master_handle_sync(struct pp_instance *ppi, unsigned char *buf,
33
			      int len);
34

35 36
int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
				 int len);
37

38 39 40 41 42 43
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);

44 45 46
int st_com_peer_handle_pres_followup(struct pp_instance *ppi,
				     unsigned char *buf, int len);

47
int __send_and_log(struct pp_instance *ppi, int msglen, int chtype);
48

49 50 51 52 53 54
/* Count successfully received PTP packets */
static inline int __recv_and_count(struct pp_instance *ppi, void *pkt, int len,
		   TimeInternal *t)
{
	int ret;
	ret = ppi->n_ops->recv(ppi, pkt, len, t);
55
	if (ret > 0)
56 57 58 59
		ppi->ptp_rx_count++;
	return ret;
}

60
#endif /* __COMMON_FUN_H */