xref: /illumos-gate/usr/src/lib/libpcp/common/libpcp.h (revision 201ceb75ab95f9bf1f42ea1dc9ab363b43ba47cf)
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 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #define	PCPL_MAX_TRY_CNT	5
35 #define	PCP_CLEANUP_TIMEOUT	3
36 
37 #define	PCPL_DEF_MTU_SZ		100
38 
39 
40 #define	PCPL_IO_OP_READ		(1)
41 #define	PCPL_IO_OP_WRITE	(2)
42 #define	PCPL_IO_OP_PEEK		(3)
43 
44 /*
45  * sleep (seconds) for glvc call failures before
46  * retrying.
47  */
48 #define	PCPL_GLVC_SLEEP		(5)
49 
50 /*
51  * Error codes for pcp library that are
52  * returned to users applications.
53  */
54 #define	PCPL_OK			0
55 #define	PCPL_ERROR		(-1)
56 #define	PCPL_INVALID_ARGS 	(-2)
57 #define	PCPL_GLVC_ERROR		(-3)
58 #define	PCPL_XPORT_ERROR	(-4)
59 #define	PCPL_MALLOC_FAIL	(-5)
60 #define	PCPL_GLVC_TIMEOUT	(-6)
61 #define	PCPL_FRAME_ERROR	(-7)
62 #define	PCPL_CKSUM_ERROR	(-8)
63 #define	PCPL_PROT_ERROR		(-9)
64 
65 /* common defines */
66 #ifndef	MIN
67 #define	MIN(x, y) ((x) < (y) ? (x) : (y))
68 #endif
69 #ifndef	MAX
70 #define	MAX(x, y) ((x) > (y) ? (x) : (y))
71 #endif
72 #ifndef	ABS
73 #define	ABS(x)	((x) < (0) ? (-(x)) : (x))
74 #endif
75 
76 /*
77  * PCP user apps message format
78  */
79 typedef struct pcp_msg {
80 	uint8_t	msg_type;
81 	uint8_t	sub_type;
82 	uint16_t rsvd_pad;
83 	uint32_t msg_len;
84 	void *msg_data;
85 } pcp_msg_t;
86 
87 int pcp_init(char *channel_name);
88 int pcp_send_recv(int channel_fd, pcp_msg_t *req_msg, pcp_msg_t *resp_msg,
89 			uint32_t timeout);
90 int pcp_close(int channel_fd);
91 
92 #ifdef	__cplusplus
93 }
94 #endif
95 
96 #endif /* _LIBPCP_H */
97