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