4
* A command interpreter for OpenIPMI
6
* Author: MontaVista Software, Inc.
7
* Corey Minyard <minyard@mvista.com>
10
* Copyright 2004 MontaVista Software Inc.
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.
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.
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.
34
#ifndef __IPMI_CMDLANG_H
35
#define __IPMI_CMDLANG_H
37
#include <OpenIPMI/selector.h>
43
/* Forward declaration */
44
typedef struct ipmi_cmd_info_s ipmi_cmd_info_t;
47
* A structure that must be passed into the command parser; it has
48
* general information about the how the parser should handle thing
49
* and generate its output.
51
typedef struct ipmi_cmdlang_s ipmi_cmdlang_t;
53
/* Output is done in name:value pairs. If you don't have a value,
55
typedef void (*cmd_out_cb)(ipmi_cmdlang_t *info,
58
typedef void (*cmd_out_b_cb)(ipmi_cmdlang_t *info,
63
/* Command-specific info. */
64
typedef void (*cmd_info_cb)(ipmi_cmdlang_t *info);
66
/* The user provides one of these when they call the command language
67
interpreter. It is used to report errors and generate output. */
70
cmd_out_cb out; /* Generate output with this. */
71
cmd_info_cb down; /* Go down a level (new indention or
73
cmd_info_cb up; /* Go up a level (leave the current
74
indention or nesting) */
75
cmd_info_cb done; /* Called when the command is done. If
76
there was an error, the err value in
77
info will be non-null. */
78
cmd_out_b_cb out_binary; /* Generate binary output with this. */
79
cmd_out_b_cb out_unicode; /* Generate unicode output with this. */
81
/* OS handler to use for the commands. Note that this may be set
82
to NULL if not required, don't depend on them except in certain
86
/* Tells if we are outputting help. */
92
int err; /* If non-zero, the errno code of the error
95
/* If non-NULL, an error occurred and this is the error info. If
96
the error string is dynamically allocated (and thus should be
97
freed), errstr_dynalloc should be set to true. */
101
/* If an error occurs, this will be set to the object name that
102
was dealing with the error. It may be an empty string if
103
no object is handling the error. This must be pre-allocated
104
and the length set properly. */
108
/* This is the location of an error. */
112
void *user_data; /* User data for anything the user wants */
115
/* Parse and handle the given command string. This always calls the
116
done function when complete. */
117
void ipmi_cmdlang_handle(ipmi_cmdlang_t *cmdlang, char *str);
119
/* If the event info is true, then the system will output object
120
information with each add or change event. */
121
void ipmi_cmdlang_set_evinfo(int evinfo);
122
int ipmi_cmdlang_get_evinfo(void);
125
* This is used to hold command information.
127
typedef struct ipmi_cmdlang_cmd_s ipmi_cmdlang_cmd_t;
129
typedef void (*ipmi_cmdlang_handler_cb)(ipmi_cmd_info_t *cmd_info);
131
/* Register a command as a subcommand of the parent, or into the main
132
command list if parent is NULL. The command will have the given
133
name and help text. When the command is executed, the handler will
134
be called with a cmd_info structure passed in. The handler_data parm
135
passed in below will be in the "handler_data" field of the cmd_info
136
structure. Note that if you are attaching subcommands to this
137
command, you should pass in a NULL handler. Returns an error value. */
138
int ipmi_cmdlang_reg_cmd(ipmi_cmdlang_cmd_t *parent,
141
ipmi_cmdlang_handler_cb handler,
143
ipmi_cmdlang_cmd_t **rv);
145
/* Register a table of commands. */
146
typedef struct ipmi_cmdlang_init_s
149
ipmi_cmdlang_cmd_t **parent;
151
ipmi_cmdlang_handler_cb handler;
153
ipmi_cmdlang_cmd_t **new_val;
154
} ipmi_cmdlang_init_t;
155
int ipmi_cmdlang_reg_table(ipmi_cmdlang_init_t *table, int len);
158
/* The following functions handle parsing various OpenIPMI objects
159
according to the naming standard. If you pass it into a command
160
registration as the handler and pass your function as the
161
handler_data, your function will be called with the specified
162
object. The specific function type is given in the individual
163
functions. The cmd_info will be passed in as the cb_data.
165
For instance, if you have a command that take an entity argument,
166
then you could write:
167
void ent_cmd_hnd(ipmi_entity_t *entity, void *cb_data)
169
ipmi_cmd_info_t *cmd_info = cb_data;
172
rv = ipmi_cmdlang_reg_cmd(parent, "ent_cmd", "The ent command",
173
ipmi_cmdlang_entity_handler, ent_cmd_hnd,
177
/* ipmi_domain_ptr_cb */
178
void ipmi_cmdlang_domain_handler(ipmi_cmd_info_t *cmd_info);
180
/* ipmi_entity_ptr_cb */
181
void ipmi_cmdlang_entity_handler(ipmi_cmd_info_t *cmd_info);
183
/* ipmi_sensor_ptr_cb */
184
void ipmi_cmdlang_sensor_handler(ipmi_cmd_info_t *cmd_info);
186
/* ipmi_control_ptr_cb */
187
void ipmi_cmdlang_control_handler(ipmi_cmd_info_t *cmd_info);
190
void ipmi_cmdlang_mc_handler(ipmi_cmd_info_t *cmd_info);
192
/* ipmi_connection_ptr_cb */
193
void ipmi_cmdlang_connection_handler(ipmi_cmd_info_t *cmd_info);
195
/* ipmi_pet_ptr_cb */
196
void ipmi_cmdlang_pet_handler(ipmi_cmd_info_t *cmd_info);
198
/* ipmi_lanparm_ptr_cb */
199
void ipmi_cmdlang_lanparm_handler(ipmi_cmd_info_t *cmd_info);
201
/* ipmi_fru_ptr_cb */
202
void ipmi_cmdlang_fru_handler(ipmi_cmd_info_t *cmd_info);
204
/* ipmi_pef_ptr_cb */
205
void ipmi_cmdlang_pef_handler(ipmi_cmd_info_t *cmd_info);
208
/* All output from the command language is in name/value pairs. The
209
value field may be NULL. */
210
void ipmi_cmdlang_out(ipmi_cmd_info_t *info,
213
void ipmi_cmdlang_out_int(ipmi_cmd_info_t *info,
216
void ipmi_cmdlang_out_double(ipmi_cmd_info_t *info,
219
void ipmi_cmdlang_out_hex(ipmi_cmd_info_t *info,
222
void ipmi_cmdlang_out_long(ipmi_cmd_info_t *info,
225
void ipmi_cmdlang_out_binary(ipmi_cmd_info_t *info,
229
void ipmi_cmdlang_out_unicode(ipmi_cmd_info_t *info,
233
void ipmi_cmdlang_out_type(ipmi_cmd_info_t *info,
235
enum ipmi_str_type_e type,
238
void ipmi_cmdlang_out_ip(ipmi_cmd_info_t *info,
240
struct in_addr *ip_addr);
241
void ipmi_cmdlang_out_mac(ipmi_cmd_info_t *info,
243
unsigned char mac_addr[6]);
244
void ipmi_cmdlang_out_bool(ipmi_cmd_info_t *info,
247
void ipmi_cmdlang_out_time(ipmi_cmd_info_t *info,
250
void ipmi_cmdlang_out_timeout(ipmi_cmd_info_t *info,
252
ipmi_timeout_t value);
254
/* Generate info for an event. */
255
void ipmi_cmdlang_event_out(ipmi_event_t *event,
256
ipmi_cmd_info_t *cmd_info);
258
/* The output from the command language is done at a nesting level.
259
When you start outputting data for a new thing, you should "down"
260
to create a new nesting level. When you are done, you should
262
void ipmi_cmdlang_down(ipmi_cmd_info_t *info);
263
void ipmi_cmdlang_up(ipmi_cmd_info_t *info);
265
/* A cmd info structure is refcounted, if you save a pointer to it you
266
must "get" it. When you are done, you must "put" it. It will be
267
destroyed (and the done routine called) after the last user puts it. */
268
void ipmi_cmdlang_cmd_info_get(ipmi_cmd_info_t *info);
269
void ipmi_cmdlang_cmd_info_put(ipmi_cmd_info_t *info);
271
/* Helper functions */
272
void ipmi_cmdlang_get_int(char *str, int *val, ipmi_cmd_info_t *info);
273
void ipmi_cmdlang_get_double(char *str, double *val, ipmi_cmd_info_t *info);
274
void ipmi_cmdlang_get_uchar(char *str, unsigned char *val,
275
ipmi_cmd_info_t *info);
276
void ipmi_cmdlang_get_user(char *str, int *val, ipmi_cmd_info_t *info);
277
void ipmi_cmdlang_get_time(char *str, ipmi_time_t *val, ipmi_cmd_info_t *info);
278
void ipmi_cmdlang_get_timeout(char *str, ipmi_timeout_t *val,
279
ipmi_cmd_info_t *info);
280
void ipmi_cmdlang_get_bool(char *str, int *val, ipmi_cmd_info_t *info);
281
void ipmi_cmdlang_get_ip(char *str, struct in_addr *val,
282
ipmi_cmd_info_t *info);
283
void ipmi_cmdlang_get_mac(char *str, unsigned char val[6],
284
ipmi_cmd_info_t *info);
285
void ipmi_cmdlang_get_color(char *str, int *val, ipmi_cmd_info_t *info);
286
void ipmi_cmdlang_get_threshold_ev(char *str,
287
enum ipmi_thresh_e *rthresh,
288
enum ipmi_event_value_dir_e *rvalue_dir,
289
enum ipmi_event_dir_e *rdir,
290
ipmi_cmd_info_t *info);
291
void ipmi_cmdlang_get_discrete_ev(char *str,
293
enum ipmi_event_dir_e *rdir,
294
ipmi_cmd_info_t *info);
295
void ipmi_cmdlang_get_threshold(char *str,
296
enum ipmi_thresh_e *rthresh,
297
ipmi_cmd_info_t *info);
299
/* Call these to initialize and setup the command interpreter. init
300
should be called after the IPMI library proper is initialized, but
302
int ipmi_cmdlang_init(os_handler_t *os_hnd);
303
void ipmi_cmdlang_cleanup(void);
306
/* Allocate a cmd info structure that can be used to generate
307
information to an event. Make sure to call the put function when
308
all the data has been output. Note that the refcounts work like
309
normal, you get it at one, when it goes to zero the structure will
311
ipmi_cmd_info_t *ipmi_cmdlang_alloc_event_info(void);
313
typedef struct ipmi_cmdlang_event_s ipmi_cmdlang_event_t;
315
/* Move to the first field. */
316
void ipmi_cmdlang_event_restart(ipmi_cmdlang_event_t *event);
318
enum ipmi_cmdlang_out_types {
324
/* Returns true if successful, false if no more fields left. */
325
int ipmi_cmdlang_event_next_field(ipmi_cmdlang_event_t *event,
327
enum ipmi_cmdlang_out_types *type,
332
/* Supplied by the user, used to report global errors (ones that don't
333
deal with a specific command invocation). The objstr is the name
334
of the object dealing with the error (like the domain name, entity
335
name, etc) or NULL if none. The location is the file and procedure
336
where the error occurred. The errstr is a descriptive string and
337
errval is an IPMI error value to be printed. */
338
void ipmi_cmdlang_global_err(char *objstr,
343
/* Supplied by the user to report events. */
344
void ipmi_cmdlang_report_event(ipmi_cmdlang_event_t *event);
346
/* In callbacks, you must use these to lock the cmd_info structure. */
347
void ipmi_cmdlang_lock(ipmi_cmd_info_t *info);
348
void ipmi_cmdlang_unlock(ipmi_cmd_info_t *info);
350
int ipmi_cmdlang_get_argc(ipmi_cmd_info_t *info);
351
char **ipmi_cmdlang_get_argv(ipmi_cmd_info_t *info);
352
int ipmi_cmdlang_get_curr_arg(ipmi_cmd_info_t *info);
353
ipmi_cmdlang_t *ipmi_cmdinfo_get_cmdlang(ipmi_cmd_info_t *info);
359
#endif /* __IPMI_CMDLANG_H */