1 /*
2  * ipmi_pet.h
3  *
4  * MontaVista IPMI interface for setting up and handling platform event
5  * traps.
6  *
7  * Author: MontaVista Software, Inc.
8  *         Corey Minyard <minyard@mvista.com>
9  *         source@mvista.com
10  *
11  * Copyright 2004 MontaVista Software Inc.
12  *
13  *  This program is free software; you can redistribute it and/or
14  *  modify it under the terms of the GNU Lesser General Public License
15  *  as published by the Free Software Foundation; either version 2 of
16  *  the License, or (at your option) any later version.
17  *
18  *
19  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
20  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
28  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  *  You should have received a copy of the GNU Lesser General Public
31  *  License along with this program; if not, write to the Free
32  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33  */
34 
35 #ifndef OPENIPMI_PET_H
36 #define OPENIPMI_PET_H
37 
38 #include <OpenIPMI/ipmi_types.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 typedef struct ipmi_pet_s ipmi_pet_t;
45 
46 typedef void (*ipmi_pet_done_cb)(ipmi_pet_t *pet, int err, void *cb_data);
47 
48 /* Create and configure a Platform Event Trap handler for the given
49  * channel in the given domain.  Parameters are:
50  *
51  *  channel - The specific channel to configure.  There is not real
52  *      way to know all the channels and what IP addresses should
53  *      be used for each.
54  *  ip_addr - The IP address to tell the PET to send messages to, if
55  *      applicable for this domain.
56  *  mac_addr - The MAC address to tell the PET to send messages to,
57  *      if applicable for this domain.
58  *  eft_sel - the Event Filter selector to use for this PET destination.
59  *      Note that this does *not* need to be unique for different OpenIPMI
60  *      instances that are using the same channel, since the configuration
61  *      will be exactly the same for all EFT entries using the same
62  *      channel, assuming they share the same policy number.
63  *  policy_num - The policy number to use for the alert policy.  This
64  *      should be the same for all users of a domain.
65  *  apt_sel - The Alert Policy selector to use for this PET destination.
66  *      Note that as eft_sel, this needs to be unique for each different
67  *      OpenIPMI instance on the same channel, as it specifies the
68  *      destination to use.
69  *  lan_dest_sel - The LAN configuration destination selector for this PET
70  *      destination.  Unlike eft_sel and apt_sel, this *must* be unique
71  *      for each OpenIPMI instance on the same channel.
72  *
73  * Creating one of these in a domain will cause event traps to be received
74  * and handled as standard events in OpenIPMI.
75  *
76  * Note that this uses the standard SNMP trap port (162), so you
77  * cannot run SNMP software that receives traps and an IPMI PET at
78  * the same time on the same machine.
79  */
80 int ipmi_pet_create(ipmi_domain_t    *domain,
81 		    unsigned int     connection,
82 		    unsigned int     channel,
83 		    struct in_addr   ip_addr,
84 		    unsigned char    mac_addr[6],
85 		    unsigned int     eft_sel,
86 		    unsigned int     policy_num,
87 		    unsigned int     apt_sel,
88 		    unsigned int     lan_dest_sel,
89 		    ipmi_pet_done_cb done,
90 		    void             *cb_data,
91 		    ipmi_pet_t       **pet);
92 
93 /*
94  * Like the previous call, but takes an MC instead of a domain and
95  * channel.
96  */
97 int ipmi_pet_create_mc(ipmi_mc_t        *mc,
98 		       unsigned int     channel,
99 		       struct in_addr   ip_addr,
100 		       unsigned char    mac_addr[6],
101 		       unsigned int     eft_sel,
102 		       unsigned int     policy_num,
103 		       unsigned int     apt_sel,
104 		       unsigned int     lan_dest_sel,
105 		       ipmi_pet_done_cb done,
106 		       void             *cb_data,
107 		       ipmi_pet_t       **ret_pet);
108 
109 /* Destroy a PET.  Note that if you destroy all PETs, this will result
110    in the SNMP trap UDP port being closed. */
111 int ipmi_pet_destroy(ipmi_pet_t       *pet,
112 		     ipmi_pet_done_cb done,
113 		     void             *cb_data);
114 
115 /* Used to track references to a pet.  You can use this instead of
116    ipmi_pet_destroy, but use of the destroy function is
117    recommended.  This is primarily here to help reference-tracking
118    garbage collection systems like what is in Perl to be able to
119    automatically destroy pets when they are done. */
120 void ipmi_pet_ref(ipmi_pet_t *pet);
121 void ipmi_pet_deref(ipmi_pet_t *pet);
122 
123 /* Get the "name" for the PET.  Returns the length of the string
124    (minus the closing \0).  PET names are auto-assigned. */
125 #define IPMI_PET_NAME_LEN 64
126 int ipmi_pet_get_name(ipmi_pet_t *pet, char *name, int len);
127 
128 /* Iterate through all the PETs. */
129 typedef void (*ipmi_pet_ptr_cb)(ipmi_pet_t *pet, void *cb_data);
130 void ipmi_pet_iterate_pets(ipmi_domain_t   *domain,
131 			   ipmi_pet_ptr_cb handler,
132 			   void            *cb_data);
133 
134 ipmi_mcid_t ipmi_pet_get_mc_id(ipmi_pet_t *pet);
135 unsigned int ipmi_pet_get_channel(ipmi_pet_t *pet);
136 struct in_addr *ipmi_pet_get_ip_addr(ipmi_pet_t *pet, struct in_addr *ip_addr);
137 unsigned char *ipmi_pet_get_mac_addr(ipmi_pet_t    *pet,
138 				     unsigned char mac_addr[6]);
139 unsigned int ipmi_pet_get_eft_sel(ipmi_pet_t *pet);
140 unsigned int ipmi_pet_get_policy_num(ipmi_pet_t *pet);
141 unsigned int ipmi_pet_get_apt_sel(ipmi_pet_t *pet);
142 unsigned int ipmi_pet_get_lan_dest_sel(ipmi_pet_t *pet);
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif /* OPENIPMI_PET_H */
149