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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * FMA ETM-to-Transport API header
29  *
30  * const/type defns for transporting data between an Event Transport
31  * Module (ETM) and its associated Transport Layer within a fault domain.
32  */
33 
34 #ifndef _ETM_XPORT_API_H
35 #define	_ETM_XPORT_API_H
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #include <fm/fmd_api.h>
42 
43 typedef void* etm_xport_hdl_t;	/* transport instance handle */
44 typedef void* etm_xport_conn_t;	/* transport connection handle */
45 
46 typedef enum etm_callback_flag {
47 	ETM_CBFLAG_REINIT,	/* reinitialize connection */
48 	ETM_CBFLAG_RECV		/* receive message */
49 } etm_cb_flag_t;
50 
51 /*
52  * Connection Management
53  */
54 
55 /*
56  * Initialize/setup transport instance before any connections are opened.
57  * Return transport instance handle if successful, or NULL for failure.
58  */
59 etm_xport_hdl_t
60 etm_xport_init(fmd_hdl_t *hdl, char *endpoint_id,
61     int (*cb_func)(fmd_hdl_t *hdl, etm_xport_conn_t conn, etm_cb_flag_t flag,
62     void *arg), void *cb_func_arg);
63 
64 /*
65  * Callback function provided to etm_xport_init().
66  * This function is called by the transport layer to notify the common layer
67  * that action is required (receive a message, reinitialize a connection, etc.).
68  * Return zero for success.
69  * For any non-zero return value, the connection should be closed.
70  */
71 int
72 etm_xport_cb_func(fmd_hdl_t *hdl, etm_xport_conn_t conn, etm_cb_flag_t flag,
73     void *arg);
74 
75 /*
76  * Finish/teardown any transport infrastructure.
77  * Return zero if successful, or nonzero for failure.
78  */
79 int
80 etm_xport_fini(fmd_hdl_t *hdl, etm_xport_hdl_t tlhdl);
81 
82 /*
83  * Open a connection with the given endpoint.
84  * Return the transport connection handle if successful, or NULL for failure.
85  */
86 etm_xport_conn_t
87 etm_xport_open(fmd_hdl_t *hdl, etm_xport_hdl_t tlhdl);
88 
89 /*
90  * Close a connection.
91  * Return zero if successful, or nonzero for failure.
92  */
93 int
94 etm_xport_close(fmd_hdl_t *hdl, etm_xport_conn_t conn);
95 
96 /*
97  * Input/Output
98  */
99 
100 /*
101  * Try to read byte_cnt bytes from the connection into the given buffer.
102  * Return number of bytes successfully read, or a value < 0 for failure.
103  */
104 ssize_t
105 etm_xport_read(fmd_hdl_t *hdl, etm_xport_conn_t conn, hrtime_t timeout,
106     void *buf, size_t byte_cnt);
107 
108 /*
109  * Try to write byte_cnt bytes to the connection from the given buffer.
110  * Return number of bytes successfully written, or a value < 0 for failure.
111  */
112 ssize_t
113 etm_xport_write(fmd_hdl_t *hdl, etm_xport_conn_t conn, hrtime_t timeout,
114     void *buf, size_t byte_cnt);
115 
116 /*
117  * Filter
118  */
119 
120 #define	ETM_XPORT_FILTER_OK (1)		/* OK to send/post event */
121 #define	ETM_XPORT_FILTER_DROP (0)	/* Do not send/post event */
122 #define	ETM_XPORT_FILTER_ERROR (-1)	/* Error */
123 
124 /*
125  * Make a decision whether or not to send an event to a remote endpoint.
126  * Return ETM_XPORT_FILTER_OK, ETM_XPORT_FILTER_DROP, or ETM_XPORT_FILTER_ERROR
127  * and set errno for failure.
128  */
129 int
130 etm_xport_send_filter(fmd_hdl_t *hdl, nvlist_t *event, const char *dest);
131 
132 /*
133  * Make a decision whether or not to post an event to FMD.
134  * Return ETM_XPORT_FILTER_OK, ETM_XPORT_FILTER_DROP, or ETM_XPORT_FILTER_ERROR
135  * and set errno for failure.
136  */
137 int
138 etm_xport_post_filter(fmd_hdl_t *hdl, nvlist_t *event, const char *src);
139 
140 #ifdef __cplusplus
141 }
142 #endif
143 
144 #endif /* _ETM_XPORT_API_H */
145