1 /*
2  * ipmi_solparm.h
3  *
4  * Routines for configuring IPMI SoL data.
5  *
6  * Author: MontaVista Software, Inc.
7  *         Corey Minyard <minyard@mvista.com>
8  *         source@mvista.com
9  *
10  * Copyright 2006 MontaVista Software Inc.
11  *
12  *  This program is free software; you can redistribute it and/or
13  *  modify it under the terms of the GNU Lesser General Public License
14  *  as published by the Free Software Foundation; either version 2 of
15  *  the License, or (at your option) any later version.
16  *
17  *
18  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  *  You should have received a copy of the GNU Lesser General Public
30  *  License along with this program; if not, write to the Free
31  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32  */
33 
34 #ifndef OPENIPMI_SOLPARM_H
35 #define OPENIPMI_SOLPARM_H
36 
37 #include <OpenIPMI/ipmi_types.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /* The abstract type for solparm. */
44 typedef struct ipmi_solparm_s ipmi_solparm_t;
45 
46 
47 /* Generic callback used to tell when a SOLPARM operation is done. */
48 typedef void (*ipmi_solparm_done_cb)(ipmi_solparm_t *solparm,
49 				     int            err,
50 				     void           *cb_data);
51 
52 /* Generic callback for iterating. */
53 typedef void (*ipmi_solparm_ptr_cb)(ipmi_solparm_t *solparm,
54 				    void           *cb_data);
55 
56 /* Allocate a SOLPARM. */
57 int ipmi_solparm_alloc(ipmi_mc_t      *mc,
58 		       unsigned int   channel,
59 		       ipmi_solparm_t **new_solparm);
60 
61 /* Destroy a SOLPARM. */
62 int ipmi_solparm_destroy(ipmi_solparm_t       *solparm,
63 			 ipmi_solparm_done_cb handler,
64 			 void                 *cb_data);
65 
66 /* Used to track references to a solparm.  You can use this instead of
67    ipmi_solparm_destroy, but use of the destroy function is
68    recommended.  This is primarily here to help reference-tracking
69    garbage collection systems like what is in Perl to be able to
70    automatically destroy solparms when they are done. */
71 void ipmi_solparm_ref(ipmi_solparm_t *solparm);
72 void ipmi_solparm_deref(ipmi_solparm_t *solparm);
73 
74 void ipmi_solparm_iterate_solparms(ipmi_domain_t       *domain,
75 				   ipmi_solparm_ptr_cb handler,
76 				   void                *cb_data);
77 
78 ipmi_mcid_t ipmi_solparm_get_mc_id(ipmi_solparm_t *solparm);
79 unsigned int ipmi_solparm_get_channel(ipmi_solparm_t *solparm);
80 
81 #define IPMI_SOLPARM_NAME_LEN 64
82 int ipmi_solparm_get_name(ipmi_solparm_t *solparm, char *name, int length);
83 
84 
85 
86 /* Fetch a parameter value from the SOLPARM.  The "set" and "block"
87    parameters are the set selector and block selectors.  If those are
88    not relevant for the given parm, then set them to zero.  Note that
89    on the return data, the first byte (byte 0) is the revision number,
90    the data starts in the second byte. */
91 typedef void (*ipmi_solparm_get_cb)(ipmi_solparm_t    *solparm,
92 				    int               err,
93 				    unsigned char     *data,
94 				    unsigned int      data_len,
95 				    void              *cb_data);
96 int ipmi_solparm_get_parm(ipmi_solparm_t      *solparm,
97 			  unsigned int        parm,
98 			  unsigned int        set,
99 			  unsigned int        block,
100 			  ipmi_solparm_get_cb done,
101 			  void                *cb_data);
102 
103 /* Set the parameter value in the SOLPARM to the given data. */
104 int ipmi_solparm_set_parm(ipmi_solparm_t       *solparm,
105 			  unsigned int         parm,
106 			  unsigned char        *data,
107 			  unsigned int         data_len,
108 			  ipmi_solparm_done_cb done,
109 			  void                 *cb_data);
110 
111 /* The various SoL config parms. */
112 #define IPMI_SOLPARM_SET_IN_PROGRESS		0
113 #define IPMI_SOLPARM_ENABLE			1
114 #define IPMI_SOLPARM_AUTHENTICATION		2
115 #define IPMI_SOLPARM_CHAR_SETTINGS		3
116 #define IPMI_SOLPARM_RETRY			4
117 #define IPMI_SOLPARM_NONVOLATILE_BITRATE	5
118 #define IPMI_SOLPARM_VOLATILE_BITRATE		6
119 #define IPMI_SOLPARM_PAYLOAD_CHANNEL		7
120 #define IPMI_SOLPARM_PAYLOAD_PORT_NUMBER	8
121 
122 /* A full SoL configuration.  Note that you cannot allocate one of
123    these, you can only fetch them, modify them, set them, and free
124    them. */
125 typedef struct ipmi_sol_config_s ipmi_sol_config_t;
126 
127 /* Get the full SOL configuration and lock the SOL.  Note that if the
128    SOL is locked by another, you will get an EAGAIN error in the
129    callback.  You can retry the operation, or if you are sure that it
130    is free, you can call ipmi_sol_clear_lock() before retrying.  Note
131    that the config in the callback *must* be freed by you. */
132 typedef void (*ipmi_sol_get_config_cb)(ipmi_solparm_t    *solparm,
133 				       int               err,
134 				       ipmi_sol_config_t *config,
135 				       void              *cb_data);
136 int ipmi_sol_get_config(ipmi_solparm_t         *solparm,
137 			ipmi_sol_get_config_cb done,
138 			void                   *cb_data);
139 
140 /* Set the full SOL configuration.  The config *MUST* be locked and
141    the solparm must match the SOL that it was fetched with.  Note that
142    a copy is made of the configuration, so you are free to do whatever
143    you like with it after this.  Note that this unlocks the config, so
144    it cannot be used for future set operations. */
145 int ipmi_sol_set_config(ipmi_solparm_t       *solparm,
146 			ipmi_sol_config_t    *config,
147 			ipmi_solparm_done_cb done,
148 			void                 *cb_data);
149 
150 /* Clear the lock on a SOL.  If the SOL config is non-NULL, then it's
151    lock is also cleared. */
152 int ipmi_sol_clear_lock(ipmi_solparm_t       *solparm,
153 			ipmi_sol_config_t    *solc,
154 			ipmi_solparm_done_cb done,
155 			void                 *cb_data);
156 
157 /* Free a SOL config. */
158 void ipmi_sol_free_config(ipmi_sol_config_t *config);
159 
160 /*
161  * Boatloads of data from the SOL config.  Note that all IP addresses,
162  * ports, etc. are in network order.
163  */
164 
165 /* This interface lets you fetch and set the data values by parm
166    num. Note that the parm nums *DO NOT* correspond to the
167    IPMI_SOLPARM_xxx values above. */
168 
169 enum ipmi_solconf_val_type_e { IPMI_SOLCONFIG_INT, IPMI_SOLCONFIG_BOOL,
170 			       IPMI_SOLCONFIG_DATA,
171 			       IPMI_SOLCONFIG_IP, IPMI_SOLCONFIG_MAC };
172 /* When getting the value, the valtype will be set to int or data.  If
173    it is int or bool, the value is returned in ival and the dval is
174    not used.  If it is data, ip, or mac, the data will be returned in
175    an allocated array in dval and the length set in dval_len.  The
176    data must be freed with ipmi_solconfig_data_free().  The is used
177    for some data items (the priv level for authentication type, the
178    destination for alerts and destination addresses); for other items
179    it is ignored.  The index should point to the value to fetch
180    (starting at zero), it will be updated to the next value or -1 if
181    no more are left.  The index will be unchanged if the parm does not
182    support an index.
183 
184    The string name is returned in the name field, if it is not NULL.
185 
186    Note that when fetching a value, if the passed in pointer is NULL
187    the data will not be filled in (except for index, which must always
188    be present).  That lets you get the value type without getting the
189    data, for instance. */
190 int ipmi_solconfig_get_val(ipmi_sol_config_t *solc,
191 			   unsigned int      parm,
192 			   const char        **name,
193 			   int               *index,
194 			   enum ipmi_solconf_val_type_e *valtype,
195 			   unsigned int      *ival,
196 			   unsigned char     **dval,
197 			   unsigned int      *dval_len);
198   /* Set a value in the sol config.  You must know ahead of time the
199      actual value type and set the proper one. */
200 int ipmi_solconfig_set_val(ipmi_sol_config_t *solc,
201 			   unsigned int      parm,
202 			   int               index,
203 			   unsigned int      ival,
204 			   unsigned char     *dval,
205 			   unsigned int      dval_len);
206 /* If the value is an integer, this can be used to determine if it is
207    an enumeration and what the values are.  If the parm is not an
208    enumeration, this will return ENOSYS for the parm.  Otherwise, if
209    you pass in zero, you will get either the first enumeration value,
210    or EINVAL if zero is not a valid enumeration, but there are others.
211    If this returns EINVAL or 0, nval will be set to the next valid
212    enumeration value, or -1 if val is the last or past the last
213    enumeration value.  If this returns 0, val will be set to the
214    string value for the enumeration. */
215 int ipmi_solconfig_enum_val(unsigned int parm, int val, int *nval,
216 			    const char **sval);
217 /* Sometimes array indexes may be enumerations.  This allows the user
218    to detect if a specific parm's array index is an enumeration, and
219    to get the enumeration values.  */
220 int ipmi_solconfig_enum_idx(unsigned int parm, int idx, const char **sval);
221 /* Free data from ipmi_solconfig_get_val(). */
222 void ipmi_solconfig_data_free(void *data);
223 /* Convert a string to a solconfig parm number.  Returns -1 if the
224    string is invalid. */
225 unsigned int ipmi_solconfig_str_to_parm(char *name);
226 /* Convert the parm to a string name. */
227 const char *ipmi_solconfig_parm_to_str(unsigned int parm);
228 /* Get the type of a specific parm. */
229 int ipmi_solconfig_parm_to_type(unsigned int                 parm,
230 				enum ipmi_solconf_val_type_e *valtype);
231 
232 
233 /* Settings for getting at individual parameters directly. */
234 
235 unsigned int
236 ipmi_solconfig_get_enable(ipmi_sol_config_t *solc);
237 int
238 ipmi_solconfig_set_enable(ipmi_sol_config_t *solc,
239 			  unsigned int      val);
240 
241 unsigned int
242 ipmi_solconfig_get_force_payload_encryption(ipmi_sol_config_t *solc);
243 int
244 ipmi_solconfig_set_force_payload_encryption(ipmi_sol_config_t *solc,
245 					    unsigned int      val);
246 
247 unsigned int
248 ipmi_solconfig_get_force_payload_authentication(ipmi_sol_config_t *solc);
249 int
250 ipmi_solconfig_set_force_payload_authentication(ipmi_sol_config_t *solc,
251 						unsigned int      val);
252 
253 unsigned int
254 ipmi_solconfig_get_privilege_level(ipmi_sol_config_t *solc);
255 int
256 ipmi_solconfig_set_privilege_level(ipmi_sol_config_t *solc,
257 				   unsigned int      val);
258 
259 unsigned int
260 ipmi_solconfig_get_char_accumulation_interval(ipmi_sol_config_t *solc);
261 int
262 ipmi_solconfig_set_char_accumulation_interval(ipmi_sol_config_t *solc,
263 					      unsigned int      val);
264 
265 unsigned int
266 ipmi_solconfig_get_char_send_threshold(ipmi_sol_config_t *solc);
267 int
268 ipmi_solconfig_set_char_send_threshold(ipmi_sol_config_t *solc,
269 				       unsigned int      val);
270 
271 unsigned int
272 ipmi_solconfig_get_retry_count(ipmi_sol_config_t *solc);
273 int
274 ipmi_solconfig_set_retry_count(ipmi_sol_config_t *solc,
275 			       unsigned int      val);
276 
277 unsigned int
278 ipmi_solconfig_get_retry_interval(ipmi_sol_config_t *solc);
279 int
280 ipmi_solconfig_set_retry_interval(ipmi_sol_config_t *solc,
281 				  unsigned int      val);
282 
283 unsigned int
284 ipmi_solconfig_get_non_volatile_bitrate(ipmi_sol_config_t *solc);
285 int
286 ipmi_solconfig_set_non_volatile_bitrate(ipmi_sol_config_t *solc,
287 					unsigned int      val);
288 
289 unsigned int
290 ipmi_solconfig_get_volatile_bitrate(ipmi_sol_config_t *solc);
291 int
292 ipmi_solconfig_set_volatile_bitrate(ipmi_sol_config_t *solc,
293 				   unsigned int      val);
294 
295 int
296 ipmi_solconfig_get_port_number(ipmi_sol_config_t *solc,
297 			       unsigned int      *data);
298 int
299 ipmi_solconfig_set_port_number(ipmi_sol_config_t *solc,
300 			       unsigned int      val);
301 
302 int
303 ipmi_solconfig_get_payload_channel(ipmi_sol_config_t *solc,
304 				   unsigned int      *data);
305 
306 #ifdef __cplusplus
307 }
308 #endif
309 
310 #endif /* OPENIPMI_SOLPARM_H */
311