xref: /illumos-gate/usr/src/lib/libpcp/common/libpcp.h (revision dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_LIBPCP_H
28 #define	_LIBPCP_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #define	PCPL_MAX_TRY_CNT	5
37 #define	PCP_CLEANUP_TIMEOUT	3
38 
39 #define	PCPL_DEF_MTU_SZ		100
40 
41 
42 #define	PCPL_IO_OP_READ		(1)
43 #define	PCPL_IO_OP_WRITE	(2)
44 #define	PCPL_IO_OP_PEEK		(3)
45 
46 /*
47  * sleep (seconds) for glvc call failures before
48  * retrying.
49  */
50 #define	PCPL_GLVC_SLEEP		(5)
51 
52 /*
53  * Error codes for pcp library that are
54  * returned to users applications.
55  */
56 #define	PCPL_OK			0
57 #define	PCPL_ERROR		(-1)
58 #define	PCPL_INVALID_ARGS 	(-2)
59 #define	PCPL_GLVC_ERROR		(-3)
60 #define	PCPL_XPORT_ERROR	(-4)
61 #define	PCPL_MALLOC_FAIL	(-5)
62 #define	PCPL_GLVC_TIMEOUT	(-6)
63 #define	PCPL_FRAME_ERROR	(-7)
64 #define	PCPL_CKSUM_ERROR	(-8)
65 #define	PCPL_PROT_ERROR		(-9)
66 
67 /* common defines */
68 #ifndef	MIN
69 #define	MIN(x, y) ((x) < (y) ? (x) : (y))
70 #endif
71 #ifndef	MAX
72 #define	MAX(x, y) ((x) > (y) ? (x) : (y))
73 #endif
74 #ifndef	ABS
75 #define	ABS(x)	((x) < (0) ? (-(x)) : (x))
76 #endif
77 
78 /*
79  * PCP user apps message format
80  */
81 typedef struct pcp_msg {
82 	uint8_t	msg_type;
83 	uint8_t	sub_type;
84 	uint16_t rsvd_pad;
85 	uint32_t msg_len;
86 	void *msg_data;
87 } pcp_msg_t;
88 
89 int pcp_init(char *channel_name);
90 int pcp_send_recv(int channel_fd, pcp_msg_t *req_msg, pcp_msg_t *resp_msg,
91 			uint32_t timeout);
92 int pcp_close(int channel_fd);
93 
94 #ifdef	__cplusplus
95 }
96 #endif
97 
98 #endif /* _LIBPCP_H */
99