1 /*
2  * OpenIPMI.i
3  *
4  * A SWIG interface file for OpenIPMI
5  *
6  * Author: MontaVista Software, Inc.
7  *         Corey Minyard <minyard@mvista.com>
8  *         source@mvista.com
9  *
10  * Copyright 2004 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 %module OpenIPMI
35 
36 %{
37 
38 #include <config.h>
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 
42 #ifdef HAVE_GETADDRINFO
43 #include <netdb.h>
44 #endif
45 
46 #include <OpenIPMI/ipmiif.h>
47 #include <OpenIPMI/ipmi_auth.h>
48 #include <OpenIPMI/ipmi_mc.h>
49 #include <OpenIPMI/ipmi_fru.h>
50 #include <OpenIPMI/ipmi_msgbits.h>
51 #include <OpenIPMI/ipmi_conn.h>
52 #include <OpenIPMI/ipmi_posix.h>
53 #include <OpenIPMI/ipmi_debug.h>
54 #include <OpenIPMI/ipmi_user.h>
55 #include <OpenIPMI/ipmi_lanparm.h>
56 #include <OpenIPMI/ipmi_pef.h>
57 #include <OpenIPMI/ipmi_pet.h>
58 #include <OpenIPMI/ipmi_sol.h>
59 #include <OpenIPMI/ipmi_solparm.h>
60 #include <OpenIPMI/ipmi_err.h>
61 #include <OpenIPMI/ipmi_cmdlang.h>
62 
63 #include <signal.h>
64 
65 /* For ipmi_debug_malloc_cleanup() */
66 #include <OpenIPMI/internal/ipmi_malloc.h>
67 
68 #include "OpenIPMI.h"
69 
70 typedef struct intarray
71 {
72     int *val;
73     int len;
74 } intarray;
75 
76 typedef struct charbuf
77 {
78     char *val;
79     int len;
80 } charbuf;
81 
82 os_handler_t *swig_os_hnd;
83 
84 static int
next_parm(char * s,int * start,int * next)85 next_parm(char *s, int *start, int *next)
86 {
87     while (s[*start] && isspace(s[*start]))
88 	(*start)++;
89     if (!s[*start])
90 	return EINVAL;
91 
92     *next = *start;
93     while (s[*next] && !isspace(s[*next]))
94 	(*next)++;
95     return 0;
96 }
97 
98 static int
next_colon_parm(char * s,int * start,int * next)99 next_colon_parm(char *s, int *start, int *next)
100 {
101     while (s[*start] && (s[*start] == ':'))
102 	(*start)++;
103     if (!s[*start])
104 	return EINVAL;
105 
106     *next = *start;
107     while (s[*next] && (s[*next] != ':'))
108 	(*next)++;
109     return 0;
110 }
111 
112 static int
num_parm(char * s,int len,int * rval)113 num_parm(char *s, int len, int *rval)
114 {
115     char numstr[10];
116     char *end;
117     int  val;
118 
119     if (len > 9)
120 	return EINVAL;
121     memcpy(numstr, s, len);
122     numstr[len] = '\0';
123     val = strtoul(numstr, &end, 0);
124     if (*end != '\0')
125 	return EINVAL;
126     *rval = val;
127     return 0;
128 }
129 
130 static int
parse_ipmi_addr(char * addr,int lun,ipmi_addr_t * i,unsigned int * addr_len)131 parse_ipmi_addr(char *addr, int lun, ipmi_addr_t *i, unsigned int *addr_len)
132 {
133     int start, next;
134     int rv;
135     int num;
136     int len;
137 
138     start = 0;
139     rv = next_parm(addr, &start, &next);
140     if (rv)
141 	return rv;
142     len = next - start;
143 
144     if (strncmp(addr+start, "smi", len) == 0) {
145 	ipmi_system_interface_addr_t *si = (void *) i;
146 
147 	si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
148 	si->lun = lun;
149 	start = next;
150 	rv = next_parm(addr, &start, &next);
151 	if (rv)
152 	    return rv;
153 	len = next - start;
154 	rv = num_parm(addr+start, len, &num);
155 	if (rv)
156 	    return rv;
157 	si->channel = num;
158 	*addr_len = sizeof(*si);
159     } else if (strncmp(addr+start, "ipmb", len) == 0) {
160 	ipmi_ipmb_addr_t *ipmb = (void *) i;
161 
162 	ipmb->addr_type = IPMI_IPMB_ADDR_TYPE;
163 	ipmb->lun = lun;
164 
165 	start = next;
166 	rv = next_parm(addr, &start, &next);
167 	if (rv)
168 	    return rv;
169 	len = next - start;
170 	rv = num_parm(addr+start, len, &num);
171 	if (rv)
172 	    return rv;
173 	ipmb->channel = num;
174 
175 	start = next;
176 	rv = next_parm(addr, &start, &next);
177 	if (rv)
178 	    return rv;
179 	len = next - start;
180 	rv = num_parm(addr+start, len, &num);
181 	if (rv)
182 	    return rv;
183 	ipmb->slave_addr = num;
184 
185 	*addr_len = sizeof(*ipmb);
186     } else {
187 	return EINVAL;
188     }
189 
190     return 0;
191 }
192 
193 static void
make_ipmi_addr(char * out,int max_len,ipmi_addr_t * addr,int addr_len,int * lun)194 make_ipmi_addr(char *out, int max_len, ipmi_addr_t *addr, int addr_len,
195 	       int *lun)
196 {
197     if (addr->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) {
198 	ipmi_system_interface_addr_t *si = (void *) addr;
199 	snprintf(out, max_len, "smi %d", si->channel);
200 	*lun = si->lun;
201     } else if (addr->addr_type == IPMI_IPMB_ADDR_TYPE) {
202 	ipmi_ipmb_addr_t *ipmb = (void *) addr;
203 	snprintf(out, max_len, "ipmb %d %d", ipmb->channel, ipmb->slave_addr);
204 	*lun = ipmb->lun;
205     } else {
206 	strncpy(out, "unknown", max_len);
207 	*lun = 0;
208     }
209 }
210 
211 static int
parse_ipmi_data(intarray data,unsigned char * odata,unsigned int max_len,unsigned int * rlen)212 parse_ipmi_data(intarray data, unsigned char *odata,
213 		unsigned int max_len,
214 		unsigned int *rlen)
215 {
216     int i;
217     if (data.len > max_len)
218 	return E2BIG;
219     for (i=0; i<data.len; i++)
220 	odata[i] = data.val[i];
221     *rlen = data.len;
222     return 0;
223 }
224 
225 static unsigned char *
parse_raw_str_data(char * str,unsigned int * length)226 parse_raw_str_data(char *str, unsigned int *length)
227 {
228     char *s = str;
229     int  inspace = 1;
230     int  count = 0;
231     int  i;
232     unsigned char *rv;
233     char *endstr;
234 
235     while (*s) {
236 	if (inspace && !isspace(*s)) {
237 	    inspace = 0;
238 	    count++;
239 	} else if (!inspace && isspace(*s)) {
240 	    inspace = 1;
241 	}
242 	s++;
243     }
244 
245     if (count == 0) {
246 	*length = 0;
247 	return malloc(1);
248     }
249 
250     rv = malloc(count);
251     if (!rv)
252 	return NULL;
253 
254     s = str;
255     i = 0;
256     while ((*s) && (i < count)) {
257 	rv[i] = strtoul(s, &endstr, 0);
258 	if (*endstr && (!isspace(*endstr)))
259 	    goto out_err;
260 	i++;
261 	s = endstr;
262     }
263 
264     *length = count;
265     return rv;
266 
267  out_err:
268     free(rv);
269     return NULL;
270 }
271 
272 static int
parse_ip_addr(char * str,struct in_addr * addr)273 parse_ip_addr(char *str, struct in_addr *addr)
274 {
275 #ifdef HAVE_GETADDRINFO
276     struct addrinfo    hints, *res0, *s;
277     struct sockaddr_in *paddr;
278     int                rv;
279 
280     memset(&hints, 0, sizeof(hints));
281     hints.ai_family = PF_UNSPEC;
282     hints.ai_socktype = SOCK_DGRAM;
283     rv = getaddrinfo(str, "100", &hints, &res0);
284     if (rv) {
285 	return EINVAL;
286     }
287     /* Only get the first ipv4 */
288     s = res0;
289     while (s) {
290 	if (s->ai_family == PF_INET)
291 	    break;
292 	s = s->ai_next;
293     }
294     if (!s) {
295 	freeaddrinfo(res0);
296 	return EINVAL;
297     }
298     paddr = (struct sockaddr_in *) s->ai_addr;
299     *addr = paddr->sin_addr;
300     freeaddrinfo(res0);
301     return 0;
302 #else
303 /* System does not support getaddrinfo, just for IPv4*/
304     struct hostent *ent;
305     ent = gethostbyname(str);
306     if (!ent)
307 	return EINVAL;
308     memcpy(&addr->s_addr, ent->h_addr_list[0], 4);
309     return 0;
310 #endif
311 }
312 
313 static int
parse_mac_addr(char * str,unsigned char * addr)314 parse_mac_addr(char *str, unsigned char *addr)
315 {
316     char *s;
317     int  i;
318     char *endstr;
319 
320     s = str;
321     while (isspace(*s))
322 	s++;
323     if (! isxdigit(*s))
324 	return EINVAL;
325     for (i=0; i<5; i++) {
326 	addr[i] = strtoul(s, &endstr, 16);
327 	if (*endstr != ':')
328 	    return EINVAL;
329 	s = endstr+1;
330     }
331     addr[i] = strtoul(s, &endstr, 16);
332     if (*endstr != '\0')
333 	return EINVAL;
334     return 0;
335 }
336 %}
337 
338 %{
339 /* For output returning an array of constant strings */
340 typedef struct strconstarray
341 {
342     const char **val;
343     int len;
344 } strconstarray;
345 
346 /* For input only */
347 typedef struct argarray
348 {
349     char **val;
350     int len;
351 } argarray;
352 
353 /* For input only */
354 typedef struct iargarray
355 {
356     ipmi_args_t **val;
357     int         len;
358 } iargarray;
359 %}
360 typedef struct strconstarray
361 {
362     char **val;
363     int len;
364 } strconstarray;
365 typedef struct argarray
366 {
367     char **val;
368     int len;
369 } argarray;
370 typedef struct iargarray
371 {
372     ipmi_args_t **val;
373     int        len;
374 } iargarray;
375 
376 %include "OpenIPMI_lang.i"
377 
378 %nodefault;
379 
380 %{
381 swig_cb_val *swig_log_handler;
382 
383 void
openipmi_swig_vlog(os_handler_t * os_handler,const char * format,enum ipmi_log_type_e log_type,va_list ap)384 openipmi_swig_vlog(os_handler_t *os_handler, const char *format,
385 		   enum ipmi_log_type_e log_type, va_list ap)
386 {
387     char *pfx = "";
388     static char log[1024];
389     static int curr = 0;
390     swig_cb_val *handler = swig_log_handler;
391 
392     if (! handler)
393 	return;
394 
395     switch(log_type)
396     {
397     case IPMI_LOG_INFO:
398 	pfx = "INFO";
399 	break;
400 
401     case IPMI_LOG_WARNING:
402 	pfx = "WARN";
403 	break;
404 
405     case IPMI_LOG_SEVERE:
406 	pfx = "SEVR";
407 	break;
408 
409     case IPMI_LOG_FATAL:
410 	pfx = "FATL";
411 	break;
412 
413     case IPMI_LOG_ERR_INFO:
414 	pfx = "EINF";
415 	break;
416 
417     case IPMI_LOG_DEBUG:
418 	pfx = "DEBG";
419 	break;
420 
421     case IPMI_LOG_DEBUG_START:
422     case IPMI_LOG_DEBUG_CONT:
423 	if (curr < sizeof(log))
424 	    curr += vsnprintf(log+curr, sizeof(log)-curr, format, ap);
425 	return;
426 
427     case IPMI_LOG_DEBUG_END:
428 	if (curr < sizeof(log))
429 	    vsnprintf(log+curr, sizeof(log)-curr, format, ap);
430 	pfx = "DEBG";
431 	curr = 0;
432 	goto plog;
433     }
434 
435     vsnprintf(log, sizeof(log), format, ap);
436 
437  plog:
438     swig_call_cb(handler, "log", "%s%s", pfx, log);
439 }
440 
441 static void
handle_domain_cb(ipmi_domain_t * domain,void * cb_data)442 handle_domain_cb(ipmi_domain_t *domain, void *cb_data)
443 {
444     swig_cb_val *cb = cb_data;
445     swig_ref    domain_ref;
446 
447     domain_ref = swig_make_ref(domain, ipmi_domain_t);
448     swig_call_cb(cb, "domain_cb", "%p", &domain_ref);
449     swig_free_ref_check(domain_ref, ipmi_domain_t);
450 }
451 
452 static void
domain_connect_change_handler(ipmi_domain_t * domain,int err,unsigned int conn_num,unsigned int port_num,int still_connected,void * cb_data)453 domain_connect_change_handler(ipmi_domain_t *domain,
454 			      int           err,
455 			      unsigned int  conn_num,
456 			      unsigned int  port_num,
457 			      int           still_connected,
458 			      void          *cb_data)
459 {
460     swig_cb_val *cb = cb_data;
461     swig_ref    domain_ref;
462 
463     domain_ref = swig_make_ref(domain, ipmi_domain_t);
464     swig_call_cb(cb, "conn_change_cb", "%p%d%d%d%d",
465 		 &domain_ref, err, conn_num, port_num, still_connected);
466     swig_free_ref_check(domain_ref, ipmi_domain_t);
467 }
468 
469 static void
domain_connect_change_handler_cl(ipmi_domain_con_cb handler,void * handler_data,void * cb_data)470 domain_connect_change_handler_cl(ipmi_domain_con_cb handler,
471 				 void               *handler_data,
472 				 void               *cb_data)
473 {
474     if (handler != domain_connect_change_handler)
475 	return;
476     swig_cb_val *handler_val = handler_data;
477     deref_swig_cb_val(handler_val);
478 }
479 
480 static void
domain_iterate_connections_handler(ipmi_domain_t * domain,int conn,void * cb_data)481 domain_iterate_connections_handler(ipmi_domain_t *domain, int conn,
482 				   void *cb_data)
483 {
484     swig_cb_val *cb = cb_data;
485     swig_ref    domain_ref;
486 
487     domain_ref = swig_make_ref(domain, ipmi_domain_t);
488     swig_call_cb(cb, "domain_iter_connection_cb", "%p%d", &domain_ref, conn);
489     swig_free_ref_check(domain_ref, ipmi_domain_t);
490 }
491 
492 static void
domain_event_handler(ipmi_domain_t * domain,ipmi_event_t * event,void * cb_data)493 domain_event_handler(ipmi_domain_t *domain, ipmi_event_t *event, void *cb_data)
494 {
495     swig_cb_val *cb = cb_data;
496     swig_ref    domain_ref;
497     swig_ref    event_ref;
498 
499     domain_ref = swig_make_ref(domain, ipmi_domain_t);
500     event_ref = swig_make_ref_destruct(ipmi_event_dup(event), ipmi_event_t);
501     swig_call_cb(cb, "event_cb", "%p%p", &domain_ref, &event_ref);
502     swig_free_ref_check(domain_ref, ipmi_domain_t);
503     swig_free_ref(event_ref);
504 }
505 
506 static void
domain_event_handler_cl(ipmi_event_handler_cb handler,void * handler_data,void * cb_data)507 domain_event_handler_cl(ipmi_event_handler_cb handler,
508 			void                  *handler_data,
509 			void                  *cb_data)
510 {
511     if (handler != domain_event_handler)
512 	return;
513     swig_cb_val *handler_val = handler_data;
514     deref_swig_cb_val(handler_val);
515 }
516 
517 static void
domain_mc_updated_handler(enum ipmi_update_e op,ipmi_domain_t * domain,ipmi_mc_t * mc,void * cb_data)518 domain_mc_updated_handler(enum ipmi_update_e op, ipmi_domain_t *domain,
519 			  ipmi_mc_t *mc, void *cb_data)
520 {
521     swig_cb_val *cb = cb_data;
522     swig_ref    domain_ref;
523     swig_ref    mc_ref;
524 
525     domain_ref = swig_make_ref(domain, ipmi_domain_t);
526     mc_ref = swig_make_ref(mc, ipmi_mc_t);
527     swig_call_cb(cb, "mc_update_cb", "%s%p%p",
528 		 ipmi_update_e_string(op), &domain_ref, &mc_ref);
529     swig_free_ref_check(domain_ref, ipmi_domain_t);
530     swig_free_ref_check(mc_ref, ipmi_mc_t);
531 }
532 
533 static void
domain_mc_updated_handler_cl(ipmi_domain_mc_upd_cb handler,void * handler_data,void * cb_data)534 domain_mc_updated_handler_cl(ipmi_domain_mc_upd_cb handler,
535 			     void                  *handler_data,
536 			     void                  *cb_data)
537 {
538     if (handler != domain_mc_updated_handler)
539 	return;
540     swig_cb_val *handler_val = handler_data;
541     deref_swig_cb_val(handler_val);
542 }
543 
544 static void
domain_entity_update_handler(enum ipmi_update_e op,ipmi_domain_t * domain,ipmi_entity_t * entity,void * cb_data)545 domain_entity_update_handler(enum ipmi_update_e op, ipmi_domain_t *domain,
546 			      ipmi_entity_t *entity, void *cb_data)
547 {
548     swig_cb_val *cb = cb_data;
549     swig_ref    domain_ref;
550     swig_ref    entity_ref;
551 
552     domain_ref = swig_make_ref(domain, ipmi_domain_t);
553     entity_ref = swig_make_ref(entity, ipmi_entity_t);
554     swig_call_cb(cb, "entity_update_cb", "%s%p%p",
555 		 ipmi_update_e_string(op), &domain_ref, &entity_ref);
556     swig_free_ref_check(domain_ref, ipmi_domain_t);
557     swig_free_ref_check(entity_ref, ipmi_entity_t);
558 }
559 
560 static void
domain_entity_update_handler_cl(ipmi_domain_entity_cb handler,void * handler_data,void * cb_data)561 domain_entity_update_handler_cl(ipmi_domain_entity_cb handler,
562 				void                  *handler_data,
563 				void                  *cb_data)
564 {
565     if (handler != domain_entity_update_handler)
566 	return;
567     swig_cb_val *handler_val = handler_data;
568     deref_swig_cb_val(handler_val);
569 }
570 
571 static void
domain_fully_up(ipmi_domain_t * domain,void * cb_data)572 domain_fully_up(ipmi_domain_t *domain, void *cb_data)
573 {
574     swig_cb_val *cb = cb_data;
575     swig_ref    domain_ref;
576 
577     domain_ref = swig_make_ref(domain, ipmi_domain_t);
578     swig_call_cb(cb, "domain_up_cb", "%p", &domain_ref);
579     swig_free_ref_check(domain_ref, ipmi_domain_t);
580     /* One-time call, get rid of the CB. */
581     deref_swig_cb_val(cb);
582 }
583 
584 static void
parse_args_iter_help_hnd(const char * name,const char * help,void * cb_data)585 parse_args_iter_help_hnd(const char *name, const char *help, void *cb_data)
586 {
587     swig_cb_val *cb = cb_data;
588 
589     swig_call_cb(cb, "parse_args_iter_help_cb", "%s%s", name, help);
590 }
591 
592 static void
domain_close_done(void * cb_data)593 domain_close_done(void *cb_data)
594 {
595     swig_cb_val *cb = cb_data;
596 
597     swig_call_cb(cb, "domain_close_done_cb", " ");
598     /* One-time call, get rid of the CB. */
599     deref_swig_cb_val(cb);
600 }
601 
602 static void
domain_iterate_entities_handler(ipmi_entity_t * entity,void * cb_data)603 domain_iterate_entities_handler(ipmi_entity_t *entity, void *cb_data)
604 {
605     swig_cb_val *cb = cb_data;
606     swig_ref    domain_ref;
607     swig_ref    entity_ref;
608 
609     domain_ref = swig_make_ref(ipmi_entity_get_domain(entity), ipmi_domain_t);
610     entity_ref = swig_make_ref(entity, ipmi_entity_t);
611     swig_call_cb(cb, "domain_iter_entity_cb", "%p%p",
612 		 &domain_ref, &entity_ref);
613     swig_free_ref_check(domain_ref, ipmi_domain_t);
614     swig_free_ref_check(entity_ref, ipmi_entity_t);
615 }
616 
617 static void
ipmb_mc_scan_handler(ipmi_domain_t * domain,int err,void * cb_data)618 ipmb_mc_scan_handler(ipmi_domain_t *domain, int err, void *cb_data)
619 {
620     swig_cb_val *cb = cb_data;
621     swig_ref    domain_ref;
622 
623     domain_ref = swig_make_ref(domain, ipmi_domain_t);
624     swig_call_cb(cb, "domain_ipmb_mc_scan_cb", "%p%d", &domain_ref, err);
625     swig_free_ref_check(domain_ref, ipmi_domain_t);
626     /* One-time call, get rid of the CB. */
627     deref_swig_cb_val(cb);
628 }
629 
630 static void
domain_reread_sels_handler(ipmi_domain_t * domain,int err,void * cb_data)631 domain_reread_sels_handler(ipmi_domain_t *domain, int err, void *cb_data)
632 {
633     swig_cb_val *cb = cb_data;
634     swig_ref    domain_ref;
635 
636     domain_ref = swig_make_ref(domain, ipmi_domain_t);
637     swig_call_cb(cb, "domain_reread_sels_cb", "%p%d", &domain_ref, err);
638     swig_free_ref_check(domain_ref, ipmi_domain_t);
639 }
640 
641 static int
domain_msg_cb(ipmi_domain_t * domain,ipmi_msgi_t * rspi)642 domain_msg_cb(ipmi_domain_t *domain, ipmi_msgi_t *rspi)
643 {
644     swig_cb_val   *cb = rspi->data1;
645     swig_ref      domain_ref;
646     ipmi_msg_t    *msg = &rspi->msg;
647     ipmi_addr_t   *addr = &rspi->addr;
648     int           addr_len = rspi->addr_len;
649     char          addr_str[50];
650     int           lun;
651 
652     make_ipmi_addr(addr_str, sizeof(addr_str), addr, addr_len, &lun);
653     domain_ref = swig_make_ref(domain, ipmi_domain_t);
654     swig_call_cb(cb, "domain_addr_cmd_cb", "%p%s%d%d%d%*s", &domain_ref,
655 		 addr_str, lun, msg->netfn, msg->cmd,
656 		 msg->data_len, msg->data);
657     swig_free_ref_check(domain_ref, ipmi_domain_t);
658     /* One-time call, get rid of the CB. */
659     deref_swig_cb_val(cb);
660 
661     return IPMI_MSG_ITEM_NOT_USED;
662 }
663 
664 static void
domain_iterate_mcs_handler(ipmi_domain_t * domain,ipmi_mc_t * mc,void * cb_data)665 domain_iterate_mcs_handler(ipmi_domain_t *domain, ipmi_mc_t *mc, void *cb_data)
666 {
667     swig_cb_val *cb = cb_data;
668     swig_ref    domain_ref;
669     swig_ref    mc_ref;
670 
671     domain_ref = swig_make_ref(domain, ipmi_domain_t);
672     mc_ref = swig_make_ref(mc, ipmi_mc_t);
673     swig_call_cb(cb, "domain_iter_mc_cb", "%p%p", &domain_ref, &mc_ref);
674     swig_free_ref_check(domain_ref, ipmi_domain_t);
675     swig_free_ref_check(mc_ref, ipmi_mc_t);
676 }
677 
678 static void
fru_written_done(ipmi_domain_t * domain,ipmi_fru_t * fru,int err,void * cb_data)679 fru_written_done(ipmi_domain_t *domain, ipmi_fru_t *fru,
680 		 int err, void *cb_data)
681 {
682     swig_cb_val *cb = cb_data;
683     swig_ref    domain_ref;
684     swig_ref    fru_ref;
685 
686     domain_ref = swig_make_ref(domain, ipmi_domain_t);
687     fru_ref = swig_make_ref_destruct(fru, ipmi_fru_t);
688     /* The FRU is already referenced because of the callback, no need
689        to mess with refcounts. */
690     swig_call_cb(cb, "fru_written", "%p%p%d", &domain_ref, &fru_ref, err);
691     swig_free_ref_check(domain_ref, ipmi_domain_t);
692     swig_free_ref(fru_ref);
693     /* One-time call, get rid of the CB. */
694     deref_swig_cb_val(cb);
695 }
696 
697 static void
fru_fetched(ipmi_domain_t * domain,ipmi_fru_t * fru,int err,void * cb_data)698 fru_fetched(ipmi_domain_t *domain, ipmi_fru_t *fru, int err, void *cb_data)
699 {
700     swig_cb_val *cb = cb_data;
701     swig_ref    domain_ref;
702     swig_ref    fru_ref;
703 
704     domain_ref = swig_make_ref(domain, ipmi_domain_t);
705     fru_ref = swig_make_ref_destruct(fru, ipmi_fru_t);
706     /* The FRU is already referenced because of the callback, no need
707        to mess with refcounts. */
708     swig_call_cb(cb, "fru_fetched", "%p%p%d", &domain_ref, &fru_ref, err);
709     swig_free_ref_check(domain_ref, ipmi_domain_t);
710     swig_free_ref(fru_ref);
711     /* One-time call, get rid of the CB. */
712     deref_swig_cb_val(cb);
713 }
714 
715 static void
handle_entity_cb(ipmi_entity_t * entity,void * cb_data)716 handle_entity_cb(ipmi_entity_t *entity, void *cb_data)
717 {
718     swig_cb_val *cb = cb_data;
719     swig_ref    entity_ref;
720 
721     entity_ref = swig_make_ref(entity, ipmi_entity_t);
722     swig_call_cb(cb, "entity_cb", "%p", &entity_ref);
723     swig_free_ref_check(entity_ref, ipmi_entity_t);
724 }
725 
726 static void
entity_iterate_entities_handler(ipmi_entity_t * ent1,ipmi_entity_t * ent2,void * cb_data)727 entity_iterate_entities_handler(ipmi_entity_t *ent1,
728 				ipmi_entity_t *ent2,
729 				void          *cb_data)
730 {
731     swig_cb_val *cb = cb_data;
732     swig_ref    ent1_ref;
733     swig_ref    ent2_ref;
734 
735     ent1_ref = swig_make_ref(ent1, ipmi_entity_t);
736     ent2_ref = swig_make_ref(ent2, ipmi_entity_t);
737     swig_call_cb(cb, "entity_iter_entities_cb", "%p%p", &ent1_ref, &ent2_ref);
738     swig_free_ref_check(ent2_ref, ipmi_entity_t);
739     swig_free_ref_check(ent1_ref, ipmi_entity_t);
740 }
741 
742 static void
entity_iterate_sensors_handler(ipmi_entity_t * entity,ipmi_sensor_t * sensor,void * cb_data)743 entity_iterate_sensors_handler(ipmi_entity_t *entity,
744 			       ipmi_sensor_t *sensor,
745 			       void          *cb_data)
746 {
747     swig_cb_val *cb = cb_data;
748     swig_ref    entity_ref;
749     swig_ref    sensor_ref;
750 
751     entity_ref = swig_make_ref(entity, ipmi_entity_t);
752     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
753     swig_call_cb(cb, "entity_iter_sensors_cb", "%p%p",
754 		 &entity_ref, &sensor_ref);
755     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
756     swig_free_ref_check(entity_ref, ipmi_entity_t);
757 }
758 
759 static void
entity_iterate_controls_handler(ipmi_entity_t * entity,ipmi_control_t * control,void * cb_data)760 entity_iterate_controls_handler(ipmi_entity_t  *entity,
761 				ipmi_control_t *control,
762 				void           *cb_data)
763 {
764     swig_cb_val *cb = cb_data;
765     swig_ref    entity_ref;
766     swig_ref    control_ref;
767 
768     entity_ref = swig_make_ref(entity, ipmi_entity_t);
769     control_ref = swig_make_ref(control, ipmi_control_t);
770     swig_call_cb(cb, "entity_iter_controls_cb", "%p%p",
771 		 &entity_ref, &control_ref);
772     swig_free_ref_check(control_ref, ipmi_control_t);
773     swig_free_ref_check(entity_ref, ipmi_entity_t);
774 }
775 
776 static int
entity_presence_handler(ipmi_entity_t * entity,int present,void * cb_data,ipmi_event_t * event)777 entity_presence_handler(ipmi_entity_t *entity,
778 			int           present,
779 			void          *cb_data,
780 			ipmi_event_t  *event)
781 {
782     swig_cb_val *cb = cb_data;
783     swig_ref    entity_ref;
784     swig_ref    event_ref;
785     int         rv = IPMI_EVENT_NOT_HANDLED;
786 
787     entity_ref = swig_make_ref(entity, ipmi_entity_t);
788     event_ref = swig_make_ref_destruct(ipmi_event_dup(event), ipmi_event_t);
789     swig_call_cb_rv('I', &rv, cb, "entity_presence_cb", "%p%d%p",
790 		    &entity_ref, present, &event_ref);
791     swig_free_ref_check(entity_ref, ipmi_entity_t);
792     swig_free_ref(event_ref);
793     return rv;
794 }
795 
796 static void
entity_presence_handler_cl(ipmi_entity_presence_change_cb handler,void * handler_data,void * cb_data)797 entity_presence_handler_cl(ipmi_entity_presence_change_cb handler,
798 			   void                           *handler_data,
799 			   void                           *cb_data)
800 {
801     if (handler != entity_presence_handler)
802 	return;
803     swig_cb_val *handler_val = handler_data;
804     deref_swig_cb_val(handler_val);
805 }
806 
807 static void
entity_sensor_update_handler(enum ipmi_update_e op,ipmi_entity_t * entity,ipmi_sensor_t * sensor,void * cb_data)808 entity_sensor_update_handler(enum ipmi_update_e op,
809 			     ipmi_entity_t      *entity,
810 			     ipmi_sensor_t      *sensor,
811 			     void               *cb_data)
812 {
813     swig_cb_val *cb = cb_data;
814     swig_ref    entity_ref;
815     swig_ref    sensor_ref;
816 
817     entity_ref = swig_make_ref(entity, ipmi_entity_t);
818     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
819     swig_call_cb(cb, "entity_sensor_update_cb", "%s%p%p",
820 		 ipmi_update_e_string(op), &entity_ref, &sensor_ref);
821     swig_free_ref_check(entity_ref, ipmi_entity_t);
822     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
823 }
824 
825 static void
entity_sensor_update_handler_cl(ipmi_entity_sensor_cb handler,void * handler_data,void * cb_data)826 entity_sensor_update_handler_cl(ipmi_entity_sensor_cb handler,
827 				 void                  *handler_data,
828 				 void                  *cb_data)
829 {
830     if (handler != entity_sensor_update_handler)
831 	return;
832     swig_cb_val *handler_val = handler_data;
833     deref_swig_cb_val(handler_val);
834 }
835 
836 static void
entity_control_update_handler(enum ipmi_update_e op,ipmi_entity_t * entity,ipmi_control_t * control,void * cb_data)837 entity_control_update_handler(enum ipmi_update_e op,
838 			      ipmi_entity_t      *entity,
839 			      ipmi_control_t     *control,
840 			      void               *cb_data)
841 {
842     swig_cb_val *cb = cb_data;
843     swig_ref    entity_ref;
844     swig_ref    control_ref;
845 
846     entity_ref = swig_make_ref(entity, ipmi_entity_t);
847     control_ref = swig_make_ref(control, ipmi_control_t);
848     swig_call_cb(cb, "entity_control_update_cb", "%s%p%p",
849 		 ipmi_update_e_string(op), &entity_ref, &control_ref);
850     swig_free_ref_check(entity_ref, ipmi_entity_t);
851     swig_free_ref_check(control_ref, ipmi_control_t);
852 }
853 
854 static void
entity_control_update_handler_cl(ipmi_entity_control_cb handler,void * handler_data,void * cb_data)855 entity_control_update_handler_cl(ipmi_entity_control_cb handler,
856 				 void                  *handler_data,
857 				 void                  *cb_data)
858 {
859     if (handler != entity_control_update_handler)
860 	return;
861     swig_cb_val *handler_val = handler_data;
862     deref_swig_cb_val(handler_val);
863 }
864 
865 static void
entity_fru_update_handler(enum ipmi_update_e op,ipmi_entity_t * entity,void * cb_data)866 entity_fru_update_handler(enum ipmi_update_e op,
867 			  ipmi_entity_t      *entity,
868 			  void               *cb_data)
869 {
870     swig_cb_val *cb = cb_data;
871     swig_ref    entity_ref;
872     swig_ref    fru_ref;
873     ipmi_fru_t  *fru;
874 
875     entity_ref = swig_make_ref(entity, ipmi_entity_t);
876     fru = ipmi_entity_get_fru(entity);
877     if (fru)
878 	ipmi_fru_ref(fru);
879     fru_ref = swig_make_ref_destruct(fru, ipmi_fru_t);
880     swig_call_cb(cb, "entity_fru_update_cb", "%s%p%p",
881 		 ipmi_update_e_string(op), &entity_ref, &fru_ref);
882     swig_free_ref_check(entity_ref, ipmi_entity_t);
883     swig_free_ref(fru_ref);
884 }
885 
886 static void
entity_fru_update_werr_handler(enum ipmi_update_werr_e op,int err,ipmi_entity_t * entity,void * cb_data)887 entity_fru_update_werr_handler(enum ipmi_update_werr_e op,
888 			       int                     err,
889 			       ipmi_entity_t           *entity,
890 			       void                    *cb_data)
891 {
892     swig_cb_val *cb = cb_data;
893     swig_ref    entity_ref;
894     swig_ref    fru_ref;
895     ipmi_fru_t  *fru;
896 
897     entity_ref = swig_make_ref(entity, ipmi_entity_t);
898     fru = ipmi_entity_get_fru(entity);
899     if (fru)
900 	ipmi_fru_ref(fru);
901     fru_ref = swig_make_ref_destruct(fru, ipmi_fru_t);
902     swig_call_cb(cb, "entity_fru_update_werr_cb", "%s%d%p%p",
903 		 ipmi_update_werr_e_string(op), err, &entity_ref, &fru_ref);
904     swig_free_ref_check(entity_ref, ipmi_entity_t);
905     swig_free_ref(fru_ref);
906 }
907 
908 static void
entity_fru_update_handler_cl(ipmi_entity_fru_cb handler,void * handler_data,void * cb_data)909 entity_fru_update_handler_cl(ipmi_entity_fru_cb handler,
910 			     void               *handler_data,
911 			     void               *cb_data)
912 {
913     if (handler != entity_fru_update_handler)
914 	return;
915     swig_cb_val *handler_val = handler_data;
916     deref_swig_cb_val(handler_val);
917 }
918 
919 static void
entity_fru_update_werr_handler_cl(ipmi_entity_fru_werr_cb handler,void * handler_data,void * cb_data)920 entity_fru_update_werr_handler_cl(ipmi_entity_fru_werr_cb handler,
921 				  void                    *handler_data,
922 				  void                    *cb_data)
923 {
924     if (handler != entity_fru_update_werr_handler)
925 	return;
926     swig_cb_val *handler_val = handler_data;
927     deref_swig_cb_val(handler_val);
928 }
929 
930 static int
entity_hot_swap_handler(ipmi_entity_t * entity,enum ipmi_hot_swap_states last_state,enum ipmi_hot_swap_states curr_state,void * cb_data,ipmi_event_t * event)931 entity_hot_swap_handler(ipmi_entity_t             *entity,
932 			enum ipmi_hot_swap_states last_state,
933 			enum ipmi_hot_swap_states curr_state,
934 			void                      *cb_data,
935 			ipmi_event_t              *event)
936 {
937     swig_cb_val *cb = cb_data;
938     swig_ref    entity_ref;
939     swig_ref    event_ref;
940     int         rv = IPMI_EVENT_NOT_HANDLED;
941 
942     entity_ref = swig_make_ref(entity, ipmi_entity_t);
943     event_ref = swig_make_ref_destruct(ipmi_event_dup(event), ipmi_event_t);
944     swig_call_cb_rv('I', &rv,
945 		    cb, "entity_hot_swap_update_cb", "%p%s%s%p", &entity_ref,
946 		    ipmi_hot_swap_state_name(last_state),
947 		    ipmi_hot_swap_state_name(curr_state),
948 		    &event_ref);
949     swig_free_ref_check(entity_ref, ipmi_entity_t);
950     swig_free_ref(event_ref);
951     return rv;
952 }
953 
954 static void
entity_hot_swap_handler_cl(ipmi_entity_hot_swap_cb handler,void * handler_data,void * cb_data)955 entity_hot_swap_handler_cl(ipmi_entity_hot_swap_cb handler,
956 			   void                    *handler_data,
957 			   void                    *cb_data)
958 {
959     if (handler != entity_hot_swap_handler)
960 	return;
961     swig_cb_val *handler_val = handler_data;
962     deref_swig_cb_val(handler_val);
963 }
964 
965 static void
entity_get_hot_swap_handler(ipmi_entity_t * entity,int err,enum ipmi_hot_swap_states state,void * cb_data)966 entity_get_hot_swap_handler(ipmi_entity_t             *entity,
967 			    int                       err,
968 			    enum ipmi_hot_swap_states state,
969 			    void                      *cb_data)
970 {
971     swig_cb_val *cb = cb_data;
972     swig_ref    entity_ref;
973 
974     entity_ref = swig_make_ref(entity, ipmi_entity_t);
975     swig_call_cb(cb, "entity_hot_swap_cb", "%p%d%s", &entity_ref,
976 		 err, ipmi_hot_swap_state_name(state));
977     swig_free_ref_check(entity_ref, ipmi_entity_t);
978     /* One-time call, get rid of the CB. */
979     deref_swig_cb_val(cb);
980 }
981 
982 static void
entity_get_hot_swap_time_handler(ipmi_entity_t * entity,int err,ipmi_timeout_t time,void * cb_data)983 entity_get_hot_swap_time_handler(ipmi_entity_t  *entity,
984 				 int            err,
985 				 ipmi_timeout_t time,
986 				 void           *cb_data)
987 {
988     swig_cb_val *cb = cb_data;
989     swig_ref    entity_ref;
990 
991     entity_ref = swig_make_ref(entity, ipmi_entity_t);
992     swig_call_cb(cb, "entity_hot_swap_get_time_cb", "%p%d%f", &entity_ref,
993 		 err, ((double) time) / 1000000000.0);
994     swig_free_ref_check(entity_ref, ipmi_entity_t);
995     /* One-time call, get rid of the CB. */
996     deref_swig_cb_val(cb);
997 }
998 
999 static void
entity_set_hot_swap_time_handler(ipmi_entity_t * entity,int err,void * cb_data)1000 entity_set_hot_swap_time_handler(ipmi_entity_t  *entity,
1001 				 int            err,
1002 				 void           *cb_data)
1003 {
1004     swig_cb_val *cb = cb_data;
1005     swig_ref    entity_ref;
1006 
1007     entity_ref = swig_make_ref(entity, ipmi_entity_t);
1008     swig_call_cb(cb, "entity_hot_swap_set_time_cb", "%p%d", &entity_ref, err);
1009     swig_free_ref_check(entity_ref, ipmi_entity_t);
1010     /* One-time call, get rid of the CB. */
1011     deref_swig_cb_val(cb);
1012 }
1013 
1014 static void
entity_activate_handler(ipmi_entity_t * entity,int err,void * cb_data)1015 entity_activate_handler(ipmi_entity_t  *entity,
1016 			int            err,
1017 			void           *cb_data)
1018 {
1019     swig_cb_val *cb = cb_data;
1020     swig_ref    entity_ref;
1021 
1022     entity_ref = swig_make_ref(entity, ipmi_entity_t);
1023     swig_call_cb(cb, "entity_activate_cb", "%p%d", &entity_ref, err);
1024     swig_free_ref_check(entity_ref, ipmi_entity_t);
1025     /* One-time call, get rid of the CB. */
1026     deref_swig_cb_val(cb);
1027 }
1028 
1029 static void
handle_mc_cb(ipmi_mc_t * mc,void * cb_data)1030 handle_mc_cb(ipmi_mc_t *mc, void *cb_data)
1031 {
1032     swig_cb_val *cb = cb_data;
1033     swig_ref    mc_ref;
1034 
1035     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1036     swig_call_cb(cb, "mc_cb", "%p", &mc_ref);
1037     swig_free_ref_check(mc_ref, ipmi_mc_t);
1038 }
1039 
1040 static void
mc_active_handler(ipmi_mc_t * mc,int active,void * cb_data)1041 mc_active_handler(ipmi_mc_t  *mc,
1042 		  int        active,
1043 		  void       *cb_data)
1044 {
1045     swig_cb_val *cb = cb_data;
1046     swig_ref    mc_ref;
1047 
1048     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1049     swig_call_cb(cb, "mc_active_cb", "%p%d", &mc_ref, active);
1050     swig_free_ref_check(mc_ref, ipmi_mc_t);
1051 }
1052 
1053 static void
mc_active_handler_cl(ipmi_mc_active_cb handler,void * handler_data,void * cb_data)1054 mc_active_handler_cl(ipmi_mc_active_cb handler,
1055 		     void              *handler_data,
1056 		     void              *cb_data)
1057 {
1058     if (handler != mc_active_handler)
1059 	return;
1060     swig_cb_val *handler_val = handler_data;
1061     deref_swig_cb_val(handler_val);
1062 }
1063 
1064 static void
mc_fully_up_handler(ipmi_mc_t * mc,void * cb_data)1065 mc_fully_up_handler(ipmi_mc_t *mc, void *cb_data)
1066 {
1067     swig_cb_val *cb = cb_data;
1068     swig_ref    mc_ref;
1069 
1070     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1071     swig_call_cb(cb, "mc_fully_up_cb", "%p", &mc_ref);
1072     swig_free_ref_check(mc_ref, ipmi_mc_t);
1073 }
1074 
1075 static void
mc_fully_up_handler_cl(ipmi_mc_ptr_cb handler,void * handler_data,void * cb_data)1076 mc_fully_up_handler_cl(ipmi_mc_ptr_cb handler,
1077 		       void           *handler_data,
1078 		       void           *cb_data)
1079 {
1080     if (handler != mc_fully_up_handler)
1081 	return;
1082     swig_cb_val *handler_val = handler_data;
1083     deref_swig_cb_val(handler_val);
1084 }
1085 
1086 static void
mc_msg_cb(ipmi_mc_t * mc,ipmi_msg_t * msg,void * cb_data)1087 mc_msg_cb(ipmi_mc_t  *mc,
1088 	  ipmi_msg_t *msg,
1089 	  void       *cb_data)
1090 {
1091     swig_cb_val *cb = cb_data;
1092     swig_ref    mc_ref;
1093 
1094     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1095     swig_call_cb(cb, "mc_cmd_cb", "%p%d%d%*s", &mc_ref,
1096 		 msg->netfn, msg->cmd, msg->data_len, msg->data);
1097     swig_free_ref_check(mc_ref, ipmi_mc_t);
1098     /* One-time call, get rid of the CB. */
1099     deref_swig_cb_val(cb);
1100 }
1101 
1102 static void
mc_reset_handler(ipmi_mc_t * mc,int err,void * cb_data)1103 mc_reset_handler(ipmi_mc_t *mc, int err, void *cb_data)
1104 {
1105     swig_cb_val *cb = cb_data;
1106     swig_ref    mc_ref;
1107 
1108     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1109     swig_call_cb(cb, "mc_reset_cb", "%p%d", &mc_ref, err);
1110     swig_free_ref_check(mc_ref, ipmi_mc_t);
1111     /* One-time call, get rid of the CB. */
1112     deref_swig_cb_val(cb);
1113 }
1114 
1115 static void
mc_events_enable_handler(ipmi_mc_t * mc,int err,void * cb_data)1116 mc_events_enable_handler(ipmi_mc_t *mc, int err, void *cb_data)
1117 {
1118     swig_cb_val *cb = cb_data;
1119     swig_ref    mc_ref;
1120 
1121     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1122     swig_call_cb(cb, "mc_events_enable_cb", "%p%d", &mc_ref, err);
1123     swig_free_ref_check(mc_ref, ipmi_mc_t);
1124     /* One-time call, get rid of the CB. */
1125     deref_swig_cb_val(cb);
1126 }
1127 
1128 static void
mc_get_event_log_enable_handler(ipmi_mc_t * mc,int err,int val,void * cb_data)1129 mc_get_event_log_enable_handler(ipmi_mc_t *mc, int err, int val, void *cb_data)
1130 {
1131     swig_cb_val *cb = cb_data;
1132     swig_ref    mc_ref;
1133 
1134     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1135     swig_call_cb(cb, "mc_get_event_log_enable_cb", "%p%d%d",
1136 		 &mc_ref, err, val);
1137     swig_free_ref_check(mc_ref, ipmi_mc_t);
1138     /* One-time call, get rid of the CB. */
1139     deref_swig_cb_val(cb);
1140 }
1141 
1142 static void
mc_set_event_log_enable_handler(ipmi_mc_t * mc,int err,void * cb_data)1143 mc_set_event_log_enable_handler(ipmi_mc_t *mc, int err, void *cb_data)
1144 {
1145     swig_cb_val *cb = cb_data;
1146     swig_ref    mc_ref;
1147 
1148     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1149     swig_call_cb(cb, "mc_set_event_log_enable_cb", "%p%d", &mc_ref, err);
1150     swig_free_ref_check(mc_ref, ipmi_mc_t);
1151     /* One-time call, get rid of the CB. */
1152     deref_swig_cb_val(cb);
1153 }
1154 
1155 static void
mc_reread_sensors_handler(ipmi_mc_t * mc,int err,void * cb_data)1156 mc_reread_sensors_handler(ipmi_mc_t *mc, int err, void *cb_data)
1157 {
1158     swig_cb_val *cb = cb_data;
1159     swig_ref    mc_ref;
1160 
1161     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1162     swig_call_cb(cb, "mc_reread_sensors_cb", "%p%d", &mc_ref, err);
1163     swig_free_ref_check(mc_ref, ipmi_mc_t);
1164     /* One-time call, get rid of the CB. */
1165     deref_swig_cb_val(cb);
1166 }
1167 
1168 static void
mc_reread_sel_handler(ipmi_mc_t * mc,int err,void * cb_data)1169 mc_reread_sel_handler(ipmi_mc_t *mc, int err, void *cb_data)
1170 {
1171     swig_cb_val *cb = cb_data;
1172     swig_ref    mc_ref;
1173 
1174     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1175     swig_call_cb(cb, "mc_reread_sel_cb", "%p%d", &mc_ref, err);
1176     swig_free_ref_check(mc_ref, ipmi_mc_t);
1177     /* One-time call, get rid of the CB. */
1178     deref_swig_cb_val(cb);
1179 }
1180 
1181 static void
mc_sel_get_time_cb(ipmi_mc_t * mc,int err,unsigned long time,void * cb_data)1182 mc_sel_get_time_cb(ipmi_mc_t     *mc,
1183 		   int           err,
1184 		   unsigned long time,
1185 		   void          *cb_data)
1186 {
1187     swig_cb_val *cb = cb_data;
1188     swig_ref    mc_ref;
1189 
1190     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1191     swig_call_cb(cb, "mc_get_sel_time_cb", "%p%d%ld", &mc_ref, err, time);
1192     swig_free_ref_check(mc_ref, ipmi_mc_t);
1193     /* One-time call, get rid of the CB. */
1194     deref_swig_cb_val(cb);
1195 }
1196 
1197 static void
mc_channel_get_info(ipmi_mc_t * mc,int err,ipmi_channel_info_t * info,void * cb_data)1198 mc_channel_get_info(ipmi_mc_t           *mc,
1199 		    int                 err,
1200 		    ipmi_channel_info_t *info,
1201 		    void                *cb_data)
1202 {
1203     swig_cb_val *cb = cb_data;
1204     swig_ref    mc_ref;
1205     swig_ref    info_ref;
1206 
1207     info = ipmi_channel_info_copy(info);
1208     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1209     info_ref = swig_make_ref_destruct(info, ipmi_channel_info_t);
1210     swig_call_cb(cb, "mc_channel_got_info_cb", "%p%d%p", &mc_ref, err,
1211 		 &info_ref);
1212     swig_free_ref_check(mc_ref, ipmi_mc_t);
1213     swig_free_ref(info_ref);
1214     /* One-time call, get rid of the CB. */
1215     deref_swig_cb_val(cb);
1216 }
1217 
1218 static void
mc_channel_get_access(ipmi_mc_t * mc,int err,ipmi_channel_access_t * info,void * cb_data)1219 mc_channel_get_access(ipmi_mc_t             *mc,
1220 		      int                   err,
1221 		      ipmi_channel_access_t *info,
1222 		      void                  *cb_data)
1223 {
1224     swig_cb_val *cb = cb_data;
1225     swig_ref    mc_ref;
1226     swig_ref    info_ref;
1227 
1228     info = ipmi_channel_access_copy(info);
1229     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1230     info_ref = swig_make_ref_destruct(info, ipmi_channel_access_t);
1231     swig_call_cb(cb, "mc_channel_got_access_cb", "%p%d%p", &mc_ref, err,
1232 		 &info_ref);
1233     swig_free_ref_check(mc_ref, ipmi_mc_t);
1234     swig_free_ref(info_ref);
1235     /* One-time call, get rid of the CB. */
1236     deref_swig_cb_val(cb);
1237 }
1238 
1239 static void
mc_channel_set_access(ipmi_mc_t * mc,int err,void * cb_data)1240 mc_channel_set_access(ipmi_mc_t *mc,
1241 		      int       err,
1242 		      void      *cb_data)
1243 {
1244     swig_cb_val *cb = cb_data;
1245     swig_ref    mc_ref;
1246 
1247     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1248     swig_call_cb(cb, "mc_channel_set_access_cb", "%p%d", &mc_ref, err);
1249     swig_free_ref_check(mc_ref, ipmi_mc_t);
1250     /* One-time call, get rid of the CB. */
1251     deref_swig_cb_val(cb);
1252 }
1253 
1254 static void
mc_channel_got_users(ipmi_mc_t * mc,int err,ipmi_user_list_t * info,void * cb_data)1255 mc_channel_got_users(ipmi_mc_t        *mc,
1256 		     int              err,
1257 		     ipmi_user_list_t *info,
1258 		     void             *cb_data)
1259 {
1260     swig_cb_val  *cb = cb_data;
1261     swig_ref     mc_ref;
1262     swig_ref     *info_ref;
1263     int          count;
1264     swig_ref     dummy;
1265     int          i;
1266     unsigned int max, enabled, fixed;
1267 
1268     if (info) {
1269 	count = ipmi_user_list_get_user_count(info);
1270 	info_ref = malloc(count * sizeof(swig_ref *));
1271 	if (!info_ref) {
1272 	    count = 0;
1273 	    info_ref = &dummy;
1274 	}
1275     } else {
1276 	count = 0;
1277 	info_ref = &dummy;
1278     }
1279 
1280     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1281     for (i=0; i<count; i++) {
1282 	ipmi_user_t *user = ipmi_user_list_get_user(info, i);
1283 	info_ref[i] = swig_make_ref_destruct(user, ipmi_user_t);
1284     }
1285     ipmi_user_list_get_max_user(info, &max);
1286     ipmi_user_list_get_enabled_users(info, &enabled);
1287     ipmi_user_list_get_fixed_users(info, &fixed);
1288     swig_call_cb(cb, "mc_channel_got_users_cb", "%p%d%d%d%d%*o", &mc_ref, err,
1289 		 max, enabled, fixed, count, info_ref);
1290     swig_free_ref_check(mc_ref, ipmi_mc_t);
1291     for (i=0; i<count; i++)
1292 	swig_free_ref(info_ref[i]);
1293     free(info_ref);
1294     /* One-time call, get rid of the CB. */
1295     deref_swig_cb_val(cb);
1296 }
1297 
1298 static void
mc_channel_set_user(ipmi_mc_t * mc,int err,void * cb_data)1299 mc_channel_set_user(ipmi_mc_t *mc,
1300 		    int       err,
1301 		    void      *cb_data)
1302 {
1303     swig_cb_val *cb = cb_data;
1304     swig_ref    mc_ref;
1305 
1306     mc_ref = swig_make_ref(mc, ipmi_mc_t);
1307     swig_call_cb(cb, "mc_channel_set_user_cb", "%p%d", &mc_ref, err);
1308     swig_free_ref_check(mc_ref, ipmi_mc_t);
1309     /* One-time call, get rid of the CB. */
1310     deref_swig_cb_val(cb);
1311 }
1312 
1313 static void
handle_sensor_cb(ipmi_sensor_t * sensor,void * cb_data)1314 handle_sensor_cb(ipmi_sensor_t *sensor, void *cb_data)
1315 {
1316     swig_cb_val *cb = cb_data;
1317     swig_ref    sensor_ref;
1318 
1319     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
1320     swig_call_cb(cb, "sensor_cb", "%p", &sensor_ref);
1321     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
1322 }
1323 
1324 static char *
threshold_str(char * s,enum ipmi_thresh_e thresh)1325 threshold_str(char *s, enum ipmi_thresh_e thresh)
1326 {
1327     if (thresh == IPMI_UPPER_NON_CRITICAL) {
1328 	*s = 'u'; s++; *s = 'n'; s++;
1329     } else if (thresh == IPMI_UPPER_CRITICAL) {
1330 	*s = 'u'; s++; *s = 'c'; s++;
1331     } else if (thresh == IPMI_UPPER_NON_RECOVERABLE) {
1332 	*s = 'u'; s++; *s = 'r'; s++;
1333     } else if (thresh == IPMI_LOWER_NON_CRITICAL) {
1334 	*s = 'l'; s++; *s = 'n'; s++;
1335     } else if (thresh == IPMI_LOWER_CRITICAL) {
1336 	*s = 'l'; s++; *s = 'c'; s++;
1337     } else if (thresh == IPMI_LOWER_NON_RECOVERABLE) {
1338 	*s = 'l'; s++; *s = 'r'; s++;
1339     }
1340 
1341     return s;
1342 }
1343 
1344 static char *
threshold_from_str(char * s,int len,enum ipmi_thresh_e * thresh)1345 threshold_from_str(char *s, int len, enum ipmi_thresh_e *thresh)
1346 {
1347     if (len != 2)
1348 	return NULL;
1349 
1350     if (strncasecmp(s, "un", 2) == 0)
1351 	*thresh = IPMI_UPPER_NON_CRITICAL;
1352     else if (strncasecmp(s, "uc", 2) == 0)
1353 	*thresh = IPMI_UPPER_CRITICAL;
1354     else if (strncasecmp(s, "ur", 2) == 0)
1355 	*thresh = IPMI_UPPER_NON_RECOVERABLE;
1356     else if (strncasecmp(s, "ln", 2) == 0)
1357 	*thresh = IPMI_LOWER_NON_CRITICAL;
1358     else if (strncasecmp(s, "lc", 2) == 0)
1359 	*thresh = IPMI_LOWER_CRITICAL;
1360     else if (strncasecmp(s, "lr", 2) == 0)
1361 	*thresh = IPMI_LOWER_NON_RECOVERABLE;
1362     else
1363 	return NULL;
1364     return s+2;
1365 }
1366 
1367 static char *
threshold_event_str(char * s,enum ipmi_thresh_e thresh,enum ipmi_event_value_dir_e value_dir,enum ipmi_event_dir_e dir)1368 threshold_event_str(char                        *s,
1369 		    enum ipmi_thresh_e          thresh,
1370 		    enum ipmi_event_value_dir_e value_dir,
1371 		    enum ipmi_event_dir_e       dir)
1372 {
1373     s = threshold_str(s, thresh);
1374     if (value_dir == IPMI_GOING_HIGH) {
1375 	*s = 'h'; s++;
1376     } else {
1377 	*s = 'l'; s++;
1378     }
1379     if (dir == IPMI_ASSERTION) {
1380 	*s = 'a'; s++;
1381     } else {
1382 	*s = 'd'; s++;
1383     }
1384     *s = '\0';
1385     return s;
1386 }
1387 
1388 static char *
threshold_event_from_str(char * s,int len,enum ipmi_thresh_e * thresh,enum ipmi_event_value_dir_e * value_dir,enum ipmi_event_dir_e * dir)1389 threshold_event_from_str(char                        *s,
1390 			 int                        len,
1391 			 enum ipmi_thresh_e          *thresh,
1392 			 enum ipmi_event_value_dir_e *value_dir,
1393 			 enum ipmi_event_dir_e       *dir)
1394 {
1395     if (len != 4)
1396 	return NULL;
1397 
1398     s = threshold_from_str(s, 2, thresh);
1399 
1400     if (*s == 'l')
1401 	*value_dir = IPMI_GOING_LOW;
1402     else if (*s == 'h')
1403 	*value_dir = IPMI_GOING_HIGH;
1404     else
1405 	return NULL;
1406     s++;
1407     if (*s == 'a')
1408 	*dir = IPMI_ASSERTION;
1409     else if (*s == 'd')
1410 	*dir = IPMI_DEASSERTION;
1411     else
1412 	return NULL;
1413     s++;
1414     return s;
1415 }
1416 
1417 static char *
discrete_event_from_str(char * s,int len,int * offset,enum ipmi_event_dir_e * dir)1418 discrete_event_from_str(char                  *s,
1419 			int                   len,
1420 			int                   *offset,
1421 			enum ipmi_event_dir_e *dir)
1422 {
1423     if ((len < 2) || (len > 3))
1424 	return NULL;
1425 
1426     *offset = strtoul(s, &s, 0);
1427     if (*offset >= 15)
1428 	return NULL;
1429     if (*s == 'a')
1430 	*dir = IPMI_ASSERTION;
1431     else if (*s == 'd')
1432 	*dir = IPMI_DEASSERTION;
1433     else
1434 	return NULL;
1435     s++;
1436     return s;
1437 }
1438 
1439 static char *
discrete_event_str(char * s,int offset,enum ipmi_event_dir_e dir)1440 discrete_event_str(char                   *s,
1441 		   int                    offset,
1442 		   enum ipmi_event_dir_e dir)
1443 {
1444     if (offset >= 100)
1445 	offset = 99;
1446     if (offset < 0)
1447 	offset = 0;
1448     s += sprintf(s, "%d", offset);
1449     if (dir == IPMI_ASSERTION) {
1450 	*s = 'a'; s++;
1451     } else {
1452 	*s = 'd'; s++;
1453     }
1454     *s = '\0';
1455     return s;
1456 }
1457 
1458 static char *
threshold_event_state_to_str(ipmi_event_state_t * events)1459 threshold_event_state_to_str(ipmi_event_state_t *events)
1460 {
1461     int                         len = 0;
1462     char                        *str;
1463     enum ipmi_thresh_e          thresh;
1464     enum ipmi_event_value_dir_e value_dir;
1465     enum ipmi_event_dir_e       dir;
1466     char                        *s;
1467 
1468     if (ipmi_event_state_get_events_enabled(events))
1469 	len += strlen("events ");
1470     if (ipmi_event_state_get_scanning_enabled(events))
1471 	len += strlen("scanning ");
1472     if (ipmi_event_state_get_busy(events))
1473 	len += strlen("busy ");
1474 
1475     for (thresh = IPMI_LOWER_NON_CRITICAL;
1476 	 thresh <= IPMI_UPPER_NON_RECOVERABLE;
1477 	 thresh++)
1478     {
1479 	for (value_dir = IPMI_GOING_LOW;
1480 	     value_dir <= IPMI_GOING_HIGH;
1481 	     value_dir++)
1482 	{
1483 	    for (dir = IPMI_ASSERTION;
1484 		 dir <= IPMI_DEASSERTION;
1485 		 dir++)
1486 	    {
1487 		if (ipmi_is_threshold_event_set(events,thresh, value_dir, dir))
1488 		    len += 5;
1489 	    }
1490 	}
1491     }
1492 
1493     str = malloc(len+1);
1494     str[0] = '\0';
1495 
1496     if (ipmi_event_state_get_events_enabled(events))
1497 	strcat(str, "events ");
1498     if (ipmi_event_state_get_scanning_enabled(events))
1499 	strcat(str, "scanning ");
1500     if (ipmi_event_state_get_busy(events))
1501 	strcat(str, "busy ");
1502     s = str + strlen(str);
1503 
1504     for (thresh = IPMI_LOWER_NON_CRITICAL;
1505 	 thresh <= IPMI_UPPER_NON_RECOVERABLE;
1506 	 thresh++)
1507     {
1508 	for (value_dir = IPMI_GOING_LOW;
1509 	     value_dir <= IPMI_GOING_HIGH;
1510 	     value_dir++)
1511 	{
1512 	    for (dir = IPMI_ASSERTION;
1513 		 dir <= IPMI_DEASSERTION;
1514 		 dir++)
1515 	    {
1516 		if (!ipmi_is_threshold_event_set(events,thresh,value_dir,dir))
1517 		    continue;
1518 
1519 		s = threshold_event_str(s, thresh, value_dir, dir);
1520 		*s = ' ';
1521 		s++;
1522 	    }
1523 	}
1524     }
1525     *s = '\0';
1526     len = s - str;
1527     if (len > 0)
1528 	str[len-1] = '\0'; /* Remove the final space */
1529 
1530     return str;
1531 }
1532 
1533 static int
str_to_threshold_event_state(char * str,ipmi_event_state_t ** events)1534 str_to_threshold_event_state(char               *str,
1535 			     ipmi_event_state_t **events)
1536 {
1537     enum ipmi_thresh_e          thresh;
1538     enum ipmi_event_value_dir_e value_dir;
1539     enum ipmi_event_dir_e       dir;
1540     ipmi_event_state_t          *e;
1541     int                         start, next;
1542     int                         rv;
1543 
1544     e = malloc(ipmi_event_state_size());
1545     ipmi_event_state_init(e);
1546 
1547     start = 0;
1548     rv = next_parm(str, &start, &next);
1549     while (!rv) {
1550 	char *s = str+start;
1551 	int  len = next - start;
1552 	if (strncasecmp(s, "events", len) == 0)
1553 	    ipmi_event_state_set_events_enabled(e, 1);
1554 	else if (strncasecmp(s, "scanning", len) == 0)
1555 	    ipmi_event_state_set_scanning_enabled(e, 1);
1556 	else if (strncasecmp(s, "busy", len) == 0)
1557 	    ipmi_event_state_set_busy(e, 1);
1558 	else {
1559 	    s = threshold_event_from_str(s, len, &thresh, &value_dir, &dir);
1560 	    if (!s)
1561 		goto out_err;
1562 
1563 	    ipmi_threshold_event_set(e, thresh, value_dir, dir);
1564 	}
1565 
1566 	start = next;
1567 	rv = next_parm(str, &start, &next);
1568     }
1569 
1570     *events = e;
1571     return 0;
1572 
1573  out_err:
1574     free(e);
1575     return EINVAL;
1576 }
1577 
1578 static char *
discrete_event_state_to_str(ipmi_event_state_t * events)1579 discrete_event_state_to_str(ipmi_event_state_t *events)
1580 {
1581     int                   len = 0;
1582     char                  *str;
1583     int                   offset;
1584     enum ipmi_event_dir_e dir;
1585     char                  *s;
1586 
1587     if (ipmi_event_state_get_events_enabled(events))
1588 	len += strlen("events ");
1589     if (ipmi_event_state_get_scanning_enabled(events))
1590 	len += strlen("scanning ");
1591     if (ipmi_event_state_get_busy(events))
1592 	len += strlen("busy ");
1593 
1594     for (offset=0; offset<15; offset++) {
1595 	for (dir = IPMI_ASSERTION;
1596 	     dir <= IPMI_DEASSERTION;
1597 	     dir++)
1598 	{
1599 	    if (ipmi_is_discrete_event_set(events, offset, dir))
1600 		    len += 4;
1601 	}
1602     }
1603 
1604     str = malloc(len+1);
1605     str[0] = '\0';
1606 
1607     if (ipmi_event_state_get_events_enabled(events))
1608 	strcat(str, "events ");
1609     if (ipmi_event_state_get_scanning_enabled(events))
1610 	strcat(str, "scanning ");
1611     if (ipmi_event_state_get_busy(events))
1612 	strcat(str, "busy ");
1613     s = str + strlen(str);
1614 
1615     for (offset=0; offset<15; offset++) {
1616 	for (dir = IPMI_ASSERTION;
1617 	     dir <= IPMI_DEASSERTION;
1618 	     dir++)
1619 	{
1620 	    if (! ipmi_is_discrete_event_set(events, offset, dir))
1621 		continue;
1622 
1623 	    s = discrete_event_str(s, offset, dir);
1624 	    *s = ' ';
1625 	    s++;
1626 	}
1627     }
1628     *s = '\0';
1629 
1630     len = s - str;
1631     if (len > 0)
1632 	str[len-1] = '\0'; /* Remove the final space */
1633 
1634     return str;
1635 }
1636 
1637 static int
str_to_discrete_event_state(char * str,ipmi_event_state_t ** events)1638 str_to_discrete_event_state(char               *str,
1639 			    ipmi_event_state_t **events)
1640 {
1641     int                   offset;
1642     enum ipmi_event_dir_e dir;
1643     ipmi_event_state_t    *e;
1644     int                   start, next;
1645     int                   rv;
1646 
1647     e = malloc(ipmi_event_state_size());
1648     ipmi_event_state_init(e);
1649 
1650     start = 0;
1651     rv = next_parm(str, &start, &next);
1652     while (!rv) {
1653 	char *s = str+start;
1654 	int  len = next - start;
1655 	if (strncasecmp(s, "events", len) == 0)
1656 	    ipmi_event_state_set_events_enabled(e, 1);
1657 	else if (strncasecmp(s, "scanning", len) == 0)
1658 	    ipmi_event_state_set_scanning_enabled(e, 1);
1659 	else if (strncasecmp(s, "busy", len) == 0)
1660 	    ipmi_event_state_set_busy(e, 1);
1661 	else {
1662 	    s = discrete_event_from_str(s, len, &offset, &dir);
1663 	    if (!s)
1664 		goto out_err;
1665 	    ipmi_discrete_event_set(e, offset, dir);
1666 	}
1667 	start = next;
1668 	rv = next_parm(str, &start, &next);
1669     }
1670 
1671     *events = e;
1672     return 0;
1673 
1674  out_err:
1675     free(e);
1676     return EINVAL;
1677 }
1678 
1679 static char *
threshold_states_to_str(ipmi_states_t * states)1680 threshold_states_to_str(ipmi_states_t *states)
1681 {
1682     int                len = 0;
1683     char               *str;
1684     enum ipmi_thresh_e thresh;
1685     char               *s;
1686 
1687     if (ipmi_is_event_messages_enabled(states))
1688 	len += strlen("events ");
1689     if (ipmi_is_sensor_scanning_enabled(states))
1690 	len += strlen("scanning ");
1691     if (ipmi_is_initial_update_in_progress(states))
1692 	len += strlen("busy ");
1693 
1694     for (thresh = IPMI_LOWER_NON_CRITICAL;
1695 	 thresh <= IPMI_UPPER_NON_RECOVERABLE;
1696 	 thresh++)
1697     {
1698 	if (ipmi_is_threshold_out_of_range(states, thresh))
1699 	    len += 3;
1700     }
1701 
1702     str = malloc(len+1);
1703     str[0] = '\0';
1704 
1705     if (ipmi_is_event_messages_enabled(states))
1706 	strcat(str, "events ");
1707     if (ipmi_is_sensor_scanning_enabled(states))
1708 	strcat(str, "scanning ");
1709     if (ipmi_is_initial_update_in_progress(states))
1710 	strcat(str, "busy ");
1711     s = str + strlen(str);
1712 
1713     for (thresh = IPMI_LOWER_NON_CRITICAL;
1714 	 thresh <= IPMI_UPPER_NON_RECOVERABLE;
1715 	 thresh++)
1716     {
1717 	if (!ipmi_is_threshold_out_of_range(states, thresh))
1718 	    continue;
1719 
1720 	s = threshold_str(s, thresh);
1721 	*s = ' ';
1722 	s++;
1723     }
1724     *s = '\0';
1725 
1726     len = s - str;
1727     if (len > 0)
1728 	str[len-1] = '\0'; /* Remove the final space */
1729 
1730     return str;
1731 }
1732 
1733 static char *
discrete_states_to_str(ipmi_states_t * states)1734 discrete_states_to_str(ipmi_states_t *states)
1735 {
1736     int  len = 0;
1737     char *str;
1738     int  offset;
1739     char *s;
1740 
1741     if (ipmi_is_event_messages_enabled(states))
1742 	len += strlen("events ");
1743     if (ipmi_is_sensor_scanning_enabled(states))
1744 	len += strlen("scanning ");
1745     if (ipmi_is_initial_update_in_progress(states))
1746 	len += strlen("busy ");
1747 
1748     for (offset=0; offset<15; offset++) {
1749 	if (ipmi_is_state_set(states, offset))
1750 	    len += 3;
1751     }
1752 
1753     str = malloc(len+1);
1754     str[0] = '\0';
1755 
1756     if (ipmi_is_event_messages_enabled(states))
1757 	strcat(str, "events ");
1758     if (ipmi_is_sensor_scanning_enabled(states))
1759 	strcat(str, "scanning ");
1760     if (ipmi_is_initial_update_in_progress(states))
1761 	strcat(str, "busy ");
1762     s = str + strlen(str);
1763 
1764     for (offset=0; offset<15; offset++) {
1765 	if (! ipmi_is_state_set(states, offset))
1766 	    continue;
1767 
1768 	s += sprintf(s, "%d", offset);
1769 	*s = ' ';
1770 	s++;
1771     }
1772     *s = '\0';
1773 
1774     len = s - str;
1775     if (len > 0)
1776 	str[len-1] = '\0'; /* Remove the final space */
1777 
1778     return str;
1779 }
1780 
1781 static char *
thresholds_to_str(ipmi_thresholds_t * t)1782 thresholds_to_str(ipmi_thresholds_t *t)
1783 {
1784     int                len = 0;
1785     char               *str;
1786     enum ipmi_thresh_e thresh;
1787     char               dummy[3];
1788     char               *s;
1789     double             val;
1790 
1791     for (thresh = IPMI_LOWER_NON_CRITICAL;
1792 	 thresh <= IPMI_UPPER_NON_RECOVERABLE;
1793 	 thresh++)
1794     {
1795 	if (ipmi_threshold_get(t, thresh, &val) == 0)
1796 	    len += snprintf(dummy, 1, "aa %f:", val) + 1;
1797     }
1798 
1799     str = malloc(len+1);
1800     s = str;
1801 
1802     for (thresh = IPMI_LOWER_NON_CRITICAL;
1803 	 thresh <= IPMI_UPPER_NON_RECOVERABLE;
1804 	 thresh++)
1805     {
1806 	if (ipmi_threshold_get(t, thresh, &val) != 0)
1807 	    continue;
1808 
1809 	threshold_str(dummy, thresh);
1810 	dummy[2] = '\0';
1811 
1812 	s += sprintf(s, "%s %f:", dummy, val);
1813 	*s = ' ';
1814 	s++;
1815     }
1816     *s = '\0';
1817 
1818     len = s - str;
1819     if (len > 0)
1820 	str[len-2] = '\0'; /* Remove the final ': ' */
1821 
1822     return str;
1823 }
1824 
1825 static int
str_to_thresholds(char * str,ipmi_sensor_t * sensor,ipmi_thresholds_t ** thresholds)1826 str_to_thresholds(char              *str,
1827 		  ipmi_sensor_t     *sensor,
1828 		  ipmi_thresholds_t **thresholds)
1829 {
1830     enum ipmi_thresh_e thresh;
1831     ipmi_thresholds_t  *t;
1832     int                start, next;
1833     int                rv;
1834     double             val;
1835     int                err = EINVAL;
1836 
1837     t = malloc(ipmi_thresholds_size());
1838     ipmi_thresholds_init(t);
1839 
1840     start = 0;
1841     rv = next_colon_parm(str, &start, &next);
1842     while (!rv) {
1843 	char *s = str+start;
1844 	char *endstr;
1845 	int  len = next - start;
1846 	if (len < 4)
1847 	    goto out_err;
1848 
1849 	if (strncasecmp(s, "un ", 3) == 0)
1850 	    thresh = IPMI_UPPER_NON_CRITICAL;
1851 	else if (strncasecmp(s, "uc ", 3) == 0)
1852 	    thresh = IPMI_UPPER_CRITICAL;
1853 	else if (strncasecmp(s, "ur ", 3) == 0)
1854 	    thresh = IPMI_UPPER_NON_RECOVERABLE;
1855 	else if (strncasecmp(s, "ln ", 3) == 0)
1856 	    thresh = IPMI_LOWER_NON_CRITICAL;
1857 	else if (strncasecmp(s, "lc ", 3) == 0)
1858 	    thresh = IPMI_LOWER_CRITICAL;
1859 	else if (strncasecmp(s, "lr ", 3) == 0)
1860 	    thresh = IPMI_LOWER_NON_RECOVERABLE;
1861 	else
1862 	    goto out_err;
1863 
1864 	val = strtod(s+3, &endstr);
1865 	if ((*endstr != ':') && (*endstr != '\0'))
1866 	    goto out_err;
1867 
1868 	rv = ipmi_threshold_set(t, sensor, thresh, val);
1869 	if (rv) {
1870 	    err = rv;
1871 	    goto out_err;
1872 	}
1873 	start = next;
1874 	rv = next_colon_parm(str, &start, &next);
1875     }
1876 
1877     *thresholds = t;
1878     return 0;
1879 
1880  out_err:
1881     free(t);
1882     return err;
1883 }
1884 
1885 static int
sensor_threshold_event_handler(ipmi_sensor_t * sensor,enum ipmi_event_dir_e dir,enum ipmi_thresh_e threshold,enum ipmi_event_value_dir_e high_low,enum ipmi_value_present_e value_present,unsigned int raw_value,double value,void * cb_data,ipmi_event_t * event)1886 sensor_threshold_event_handler(ipmi_sensor_t               *sensor,
1887 			       enum ipmi_event_dir_e       dir,
1888 			       enum ipmi_thresh_e          threshold,
1889 			       enum ipmi_event_value_dir_e high_low,
1890 			       enum ipmi_value_present_e   value_present,
1891 			       unsigned int                raw_value,
1892 			       double                      value,
1893 			       void                        *cb_data,
1894 			       ipmi_event_t                *event)
1895 {
1896     swig_cb_val *cb = cb_data;
1897     swig_ref    sensor_ref;
1898     char        eventstr[5];
1899     int         raw_set = 0;
1900     int         value_set = 0;
1901     swig_ref    event_ref;
1902     int         rv = IPMI_EVENT_NOT_HANDLED;
1903 
1904     if (value_present == IPMI_RAW_VALUE_PRESENT)
1905 	raw_set = 1;
1906     if (value_present == IPMI_BOTH_VALUES_PRESENT) {
1907 	raw_set = 1;
1908 	value_set = 1;
1909     }
1910     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
1911     threshold_event_str(eventstr, threshold, high_low, dir);
1912     event_ref = swig_make_ref_destruct(ipmi_event_dup(event), ipmi_event_t);
1913     swig_call_cb_rv('I', &rv,
1914 		    cb, "threshold_event_cb", "%p%s%d%d%d%f%p", &sensor_ref,
1915 		    eventstr, raw_set, raw_value, value_set, value,
1916 		    &event_ref);
1917     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
1918     swig_free_ref(event_ref);
1919     return rv;
1920 }
1921 
1922 static void
sensor_threshold_event_handler_cl(ipmi_sensor_threshold_event_cb handler,void * handler_data,void * cb_data)1923 sensor_threshold_event_handler_cl(ipmi_sensor_threshold_event_cb handler,
1924 				  void                           *handler_data,
1925 				  void                           *cb_data)
1926 {
1927     if (handler != sensor_threshold_event_handler)
1928 	return;
1929     swig_cb_val *handler_val = handler_data;
1930     deref_swig_cb_val(handler_val);
1931 }
1932 
1933 static int
sensor_discrete_event_handler(ipmi_sensor_t * sensor,enum ipmi_event_dir_e dir,int offset,int severity,int prev_severity,void * cb_data,ipmi_event_t * event)1934 sensor_discrete_event_handler(ipmi_sensor_t         *sensor,
1935 			      enum ipmi_event_dir_e dir,
1936 			      int                   offset,
1937 			      int                   severity,
1938 			      int                   prev_severity,
1939 			      void                  *cb_data,
1940 			      ipmi_event_t          *event)
1941 {
1942     swig_cb_val *cb = cb_data;
1943     swig_ref    sensor_ref;
1944     char        eventstr[5];
1945     swig_ref    event_ref;
1946     int         rv = IPMI_EVENT_NOT_HANDLED;
1947 
1948     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
1949     discrete_event_str(eventstr, offset, dir);
1950     event_ref = swig_make_ref_destruct(ipmi_event_dup(event), ipmi_event_t);
1951     swig_call_cb_rv('I', &rv,
1952 		    cb, "discrete_event_cb", "%p%s%d%d%p", &sensor_ref,
1953 		    eventstr, severity, prev_severity, &event_ref);
1954     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
1955     swig_free_ref(event_ref);
1956     return rv;
1957 }
1958 
1959 static void
sensor_discrete_event_handler_cl(ipmi_sensor_discrete_event_cb handler,void * handler_data,void * cb_data)1960 sensor_discrete_event_handler_cl(ipmi_sensor_discrete_event_cb handler,
1961 				 void                          *handler_data,
1962 				 void                          *cb_data)
1963 {
1964     if (handler != sensor_discrete_event_handler)
1965 	return;
1966     swig_cb_val *handler_val = handler_data;
1967     deref_swig_cb_val(handler_val);
1968 }
1969 
1970 /*
1971  * For the event method call_handler to use.
1972  */
1973 typedef struct event_call_handler_data_s
1974 {
1975     ipmi_event_t          *event;
1976     swig_cb_val           *handlers_val;
1977     ipmi_event_handlers_t *handlers;
1978     int                   rv;
1979 } event_call_handler_data_t;
1980 
event_call_handler_mc_cb(ipmi_mc_t * mc,void * cb_data)1981 static void event_call_handler_mc_cb(ipmi_mc_t *mc, void *cb_data)
1982 {
1983     event_call_handler_data_t *info = cb_data;
1984     ipmi_domain_t             *domain = ipmi_mc_get_domain(mc);
1985 
1986     info->rv = ipmi_event_call_handler(domain, info->handlers,
1987 				       info->event, info->handlers_val);
1988 }
1989 
1990 /* A generic callback for a lot of things. */
1991 static void
sensor_event_enable_handler(ipmi_sensor_t * sensor,int err,void * cb_data)1992 sensor_event_enable_handler(ipmi_sensor_t *sensor,
1993 			    int           err,
1994 			    void          *cb_data)
1995 {
1996     swig_cb_val *cb = cb_data;
1997     swig_ref    sensor_ref;
1998 
1999     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
2000     swig_call_cb(cb, "sensor_event_enable_cb", "%p%d", &sensor_ref, err);
2001     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
2002     /* One-time call, get rid of the CB. */
2003     deref_swig_cb_val(cb);
2004 }
2005 
2006 static void
sensor_get_event_enables_handler(ipmi_sensor_t * sensor,int err,ipmi_event_state_t * states,void * cb_data)2007 sensor_get_event_enables_handler(ipmi_sensor_t      *sensor,
2008 				 int                err,
2009 				 ipmi_event_state_t *states,
2010 				 void               *cb_data)
2011 {
2012     swig_cb_val *cb = cb_data;
2013     swig_ref    sensor_ref;
2014     char        *st;
2015 
2016     if (ipmi_sensor_get_event_reading_type(sensor)
2017 	== IPMI_EVENT_READING_TYPE_THRESHOLD)
2018     {
2019 	st = threshold_event_state_to_str(states);
2020     } else {
2021 	st = discrete_event_state_to_str(states);
2022     }
2023 
2024     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
2025     swig_call_cb(cb, "sensor_get_event_enable_cb", "%p%d%s",
2026 		 &sensor_ref, err, st);
2027     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
2028     free(st);
2029     /* One-time call, get rid of the CB. */
2030     deref_swig_cb_val(cb);
2031 }
2032 
2033 static void
sensor_rearm_handler(ipmi_sensor_t * sensor,int err,void * cb_data)2034 sensor_rearm_handler(ipmi_sensor_t      *sensor,
2035 		     int                err,
2036 		     void               *cb_data)
2037 {
2038     swig_cb_val *cb = cb_data;
2039     swig_ref    sensor_ref;
2040 
2041     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
2042     swig_call_cb(cb, "sensor_rearm_cb", "%p%d", &sensor_ref, err);
2043     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
2044     /* One-time call, get rid of the CB. */
2045     deref_swig_cb_val(cb);
2046 }
2047 
2048 static void
sensor_get_hysteresis_handler(ipmi_sensor_t * sensor,int err,unsigned int positive_hysteresis,unsigned int negative_hysteresis,void * cb_data)2049 sensor_get_hysteresis_handler(ipmi_sensor_t *sensor,
2050 			      int           err,
2051 			      unsigned int  positive_hysteresis,
2052 			      unsigned int  negative_hysteresis,
2053 			      void          *cb_data)
2054 {
2055     swig_cb_val *cb = cb_data;
2056     swig_ref    sensor_ref;
2057 
2058     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
2059     swig_call_cb(cb, "sensor_get_hysteresis_cb", "%p%d%d%d", &sensor_ref, err,
2060 		 positive_hysteresis, negative_hysteresis);
2061     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
2062     /* One-time call, get rid of the CB. */
2063     deref_swig_cb_val(cb);
2064 }
2065 
2066 static void
sensor_set_hysteresis_handler(ipmi_sensor_t * sensor,int err,void * cb_data)2067 sensor_set_hysteresis_handler(ipmi_sensor_t      *sensor,
2068 			      int                err,
2069 			      void               *cb_data)
2070 {
2071     swig_cb_val *cb = cb_data;
2072     swig_ref    sensor_ref;
2073 
2074     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
2075     swig_call_cb(cb, "sensor_set_hysteresis_cb", "%p%d", &sensor_ref, err);
2076     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
2077     /* One-time call, get rid of the CB. */
2078     deref_swig_cb_val(cb);
2079 }
2080 
2081 static void
sensor_set_thresholds_handler(ipmi_sensor_t * sensor,int err,void * cb_data)2082 sensor_set_thresholds_handler(ipmi_sensor_t      *sensor,
2083 			      int                err,
2084 			      void               *cb_data)
2085 {
2086     swig_cb_val *cb = cb_data;
2087     swig_ref    sensor_ref;
2088 
2089     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
2090     swig_call_cb(cb, "sensor_set_thresholds_cb", "%p%d", &sensor_ref, err);
2091     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
2092     /* One-time call, get rid of the CB. */
2093     deref_swig_cb_val(cb);
2094 }
2095 
sensor_get_thresholds_handler(ipmi_sensor_t * sensor,int err,ipmi_thresholds_t * th,void * cb_data)2096 static void sensor_get_thresholds_handler(ipmi_sensor_t     *sensor,
2097 					  int               err,
2098 					  ipmi_thresholds_t *th,
2099 					  void              *cb_data)
2100 {
2101     swig_cb_val *cb = cb_data;
2102     swig_ref    sensor_ref;
2103     char        *thstr = thresholds_to_str(th);
2104 
2105     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
2106     swig_call_cb(cb, "sensor_get_thresholds_cb", "%p%d%s", &sensor_ref, err,
2107 		 thstr);
2108     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
2109     free(thstr);
2110     /* One-time call, get rid of the CB. */
2111     deref_swig_cb_val(cb);
2112 }
2113 
2114 static void
sensor_get_reading_handler(ipmi_sensor_t * sensor,int err,enum ipmi_value_present_e value_present,unsigned int raw_value,double value,ipmi_states_t * states,void * cb_data)2115 sensor_get_reading_handler(ipmi_sensor_t             *sensor,
2116 			   int                       err,
2117 			   enum ipmi_value_present_e value_present,
2118 			   unsigned int              raw_value,
2119 			   double                    value,
2120 			   ipmi_states_t             *states,
2121 			   void                      *cb_data)
2122 {
2123     swig_cb_val *cb = cb_data;
2124     swig_ref    sensor_ref;
2125     int         raw_set = 0;
2126     int         value_set = 0;
2127     char        *statestr;
2128 
2129     if (value_present == IPMI_RAW_VALUE_PRESENT)
2130 	raw_set = 1;
2131     if (value_present == IPMI_BOTH_VALUES_PRESENT) {
2132 	raw_set = 1;
2133 	value_set = 1;
2134     }
2135     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
2136     statestr = threshold_states_to_str(states);
2137     swig_call_cb(cb, "threshold_reading_cb", "%p%d%d%d%d%f%s", &sensor_ref,
2138 		 err, raw_set, raw_value, value_set, value, statestr);
2139     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
2140     free(statestr);
2141     /* One-time call, get rid of the CB. */
2142     deref_swig_cb_val(cb);
2143 }
2144 
2145 static void
sensor_get_states_handler(ipmi_sensor_t * sensor,int err,ipmi_states_t * states,void * cb_data)2146 sensor_get_states_handler(ipmi_sensor_t *sensor,
2147 			  int           err,
2148 			  ipmi_states_t *states,
2149 			  void          *cb_data)
2150 {
2151     swig_cb_val *cb = cb_data;
2152     swig_ref    sensor_ref;
2153     char        *statestr;
2154 
2155     sensor_ref = swig_make_ref(sensor, ipmi_sensor_t);
2156     statestr = discrete_states_to_str(states);
2157     swig_call_cb(cb, "discrete_states_cb", "%p%d%s", &sensor_ref,
2158 		 err, statestr);
2159     swig_free_ref_check(sensor_ref, ipmi_sensor_t);
2160     free(statestr);
2161     /* One-time call, get rid of the CB. */
2162     deref_swig_cb_val(cb);
2163 }
2164 
2165 static int
str_to_color(char * s,int len,int * color)2166 str_to_color(char *s, int len, int *color)
2167 {
2168     int i;
2169 
2170     for (i=IPMI_CONTROL_COLOR_BLACK; i<=IPMI_CONTROL_COLOR_ORANGE; i++) {
2171 	if (strncasecmp(s, ipmi_get_color_string(i), len) == 0) {
2172 	    *color = i;
2173 	    return 0;
2174 	}
2175     }
2176 
2177     return EINVAL;
2178 }
2179 
2180 static int
str_to_light_setting(char * s,ipmi_light_setting_t ** setting)2181 str_to_light_setting(char *s, ipmi_light_setting_t **setting)
2182 {
2183     int                  rv;
2184     ipmi_light_setting_t *e;
2185     int                  start, next;
2186     int                  count;
2187 
2188     count = 0;
2189     start = 0;
2190     rv = next_colon_parm(s, &start, &next);
2191     while (!rv) {
2192 	start = next;
2193 	count++;
2194 	rv = next_colon_parm(s, &start, &next);
2195     }
2196     if (count == 0)
2197 	return EINVAL;
2198 
2199     e = ipmi_alloc_light_settings(count);
2200 
2201     count = 0;
2202     start = 0;
2203     rv = next_colon_parm(s, &start, &next);
2204     while (!rv) {
2205 	int  color, on_time, off_time;
2206 	char *ms;
2207 	int  mstart, mnext;
2208 	char *endstr;
2209 	char buf[100];
2210 	int  len = next - start;
2211 
2212 	if (len >= 100)
2213 	    goto out_err;
2214 
2215 	memcpy(buf, s+start, len);
2216 	buf[len] = '\0';
2217 
2218 	ms = buf;
2219 	mstart = 0;
2220 	rv = next_parm(ms, &mstart, &mnext);
2221 	if (rv)
2222 	    goto out_err;
2223 	len = mnext - mstart;
2224 	if ((len == 2) && (strncasecmp(ms+mstart, "lc", 2) == 0)) {
2225 	    rv = ipmi_light_setting_set_local_control(e, count, 1);
2226 	    if (rv)
2227 		goto out_err;
2228 
2229 	    mstart = mnext;
2230 	    rv = next_parm(ms, &mstart, &mnext);
2231 	    if (rv)
2232 		goto out_err;
2233 	}
2234 
2235 	rv = str_to_color(ms+mstart, mnext-mstart, &color);
2236 	if (rv)
2237 	    goto out_err;
2238 
2239 	mstart = mnext;
2240 	rv = next_parm(ms, &mstart, &mnext);
2241 	if (rv)
2242 	    goto out_err;
2243 	on_time = strtoul(ms+mstart, &endstr, 0);
2244 	if (endstr != (ms+mnext))
2245 	    goto out_err;
2246 
2247 	mstart = mnext;
2248 	rv = next_parm(ms, &mstart, &mnext);
2249 	if (rv)
2250 	    goto out_err;
2251 	off_time = strtoul(ms+mstart, &endstr, 0);
2252 	if (endstr != (ms+mnext))
2253 	    goto out_err;
2254 
2255 	rv = ipmi_light_setting_set_color(e, count, color);
2256 	rv |= ipmi_light_setting_set_on_time(e, count, on_time);
2257 	rv |= ipmi_light_setting_set_off_time(e, count, off_time);
2258 	if (rv)
2259 	    goto out_err;
2260 
2261 	count++;
2262 
2263 	start = next;
2264 	rv = next_colon_parm(s, &start, &next);
2265     }
2266 
2267     *setting = e;
2268     return 0;
2269 
2270  out_err:
2271     ipmi_free_light_settings(e);
2272     return EINVAL;
2273 }
2274 
2275 static char *
light_setting_to_str(ipmi_light_setting_t * e)2276 light_setting_to_str(ipmi_light_setting_t *e)
2277 {
2278     char *s, *str;
2279     int  i;
2280     int  count = ipmi_light_setting_get_count(e);
2281     char dummy[1];
2282     int  size = 0;
2283 
2284     for (i = 0; i < count; i++) {
2285 	int val;
2286 	size += 1; /* For the colon */
2287 	val = 0;
2288 	ipmi_light_setting_in_local_control(e, i, &val);
2289 	if (val)
2290 	    size += 3;
2291 	val = 0;
2292 	ipmi_light_setting_get_color(e, i, &val);
2293 	size += strlen(ipmi_get_color_string(val)) + 1;
2294 	val = 0;
2295 	ipmi_light_setting_get_on_time(e, i, &val);
2296 	size += snprintf(dummy, 1, "%d ", val);
2297 	val = 0;
2298 	ipmi_light_setting_get_off_time(e, i, &val);
2299 	size += snprintf(dummy, 1, "%d ", val);
2300     }
2301 
2302     str = malloc(size + 1);
2303     if (!str)
2304 	return NULL;
2305     s = str;
2306 
2307     for (i = 0; i < count; i++) {
2308 	int val;
2309 	const char *ov;
2310 
2311 	val = 0;
2312 	ipmi_light_setting_in_local_control(e, i, &val);
2313 	if (val) {
2314 	    strcpy(s, "lc ");
2315 	    s += 3;
2316 	}
2317 
2318 	val = 0;
2319 	ipmi_light_setting_get_color(e, i, &val);
2320 	ov = ipmi_get_color_string(val);
2321 	strcpy(s, ov);
2322 	s += strlen(ov);
2323 	*s = ' ';
2324 	s++;
2325 
2326 	val = 0;
2327 	ipmi_light_setting_get_on_time(e, i, &val);
2328 	s += sprintf(s, "%d ", val);
2329 
2330 	val = 0;
2331 	ipmi_light_setting_get_off_time(e, i, &val);
2332 	s += sprintf(s, "%d", val);
2333 
2334 	*s = ':';
2335 	s++;
2336     }
2337     if (s != str) {
2338 	/* Remove the final colon. */
2339 	s--;
2340 	*s = '\0';
2341     } else {
2342 	*s = '\0';
2343     }
2344 
2345     return str;
2346 }
2347 
2348 static void
handle_control_cb(ipmi_control_t * control,void * cb_data)2349 handle_control_cb(ipmi_control_t *control, void *cb_data)
2350 {
2351     swig_cb_val *cb = cb_data;
2352     swig_ref    control_ref;
2353 
2354     control_ref = swig_make_ref(control, ipmi_control_t);
2355     swig_call_cb(cb, "control_cb", "%p", &control_ref);
2356     swig_free_ref_check(control_ref, ipmi_control_t);
2357 }
2358 
2359 static void
control_val_set_handler(ipmi_control_t * control,int err,void * cb_data)2360 control_val_set_handler(ipmi_control_t *control, int err, void *cb_data)
2361 {
2362     swig_cb_val *cb = cb_data;
2363     swig_ref    control_ref;
2364 
2365     control_ref = swig_make_ref(control, ipmi_control_t);
2366     swig_call_cb(cb, "control_set_val_cb", "%p%d", &control_ref, err);
2367     swig_free_ref_check(control_ref, ipmi_control_t);
2368     /* One-time call, get rid of the CB. */
2369     deref_swig_cb_val(cb);
2370 }
2371 
2372 static void
control_val_get_handler(ipmi_control_t * control,int err,int * val,void * cb_data)2373 control_val_get_handler(ipmi_control_t *control, int err, int *val,
2374 			void *cb_data)
2375 {
2376     swig_cb_val *cb = cb_data;
2377     swig_ref    control_ref;
2378 
2379     control_ref = swig_make_ref(control, ipmi_control_t);
2380     if (err) {
2381 	/* On err, value may be NULL */
2382 	int dummy;
2383 	swig_call_cb(cb, "control_get_val_cb", "%p%d%*p", &control_ref, err,
2384 		     1, &dummy);
2385     } else {
2386 	swig_call_cb(cb, "control_get_val_cb", "%p%d%*p", &control_ref, err,
2387 		     ipmi_control_get_num_vals(control), val);
2388     }
2389     swig_free_ref_check(control_ref, ipmi_control_t);
2390     /* One-time call, get rid of the CB. */
2391     deref_swig_cb_val(cb);
2392 }
2393 
2394 static void
control_val_get_light_handler(ipmi_control_t * control,int err,ipmi_light_setting_t * val,void * cb_data)2395 control_val_get_light_handler(ipmi_control_t *control, int err,
2396 			      ipmi_light_setting_t *val,
2397 			      void *cb_data)
2398 {
2399     swig_cb_val *cb = cb_data;
2400     swig_ref    control_ref;
2401     char        *str;
2402 
2403     control_ref = swig_make_ref(control, ipmi_control_t);
2404     str = light_setting_to_str(val);
2405     if (!str)
2406 	str = "err";
2407     swig_call_cb(cb, "control_get_light_cb", "%p%d%s", &control_ref, err, str);
2408     swig_free_ref_check(control_ref, ipmi_control_t);
2409     /* One-time call, get rid of the CB. */
2410     deref_swig_cb_val(cb);
2411 }
2412 
2413 static void
control_val_get_id_handler(ipmi_control_t * control,int err,unsigned char * val,int length,void * cb_data)2414 control_val_get_id_handler(ipmi_control_t *control, int err,
2415 			   unsigned char *val, int length,
2416 			   void *cb_data)
2417 {
2418     swig_cb_val *cb = cb_data;
2419     swig_ref    control_ref;
2420 
2421     control_ref = swig_make_ref(control, ipmi_control_t);
2422     swig_call_cb(cb, "control_get_id_cb", "%p%d%*s", &control_ref, err,
2423 		 length, val);
2424     swig_free_ref_check(control_ref, ipmi_control_t);
2425     /* One-time call, get rid of the CB. */
2426     deref_swig_cb_val(cb);
2427 }
2428 
2429 static int
control_val_event_handler(ipmi_control_t * control,int * valid_vals,int * val,void * cb_data,ipmi_event_t * event)2430 control_val_event_handler(ipmi_control_t *control, int *valid_vals, int *val,
2431 			  void *cb_data, ipmi_event_t *event)
2432 {
2433     swig_cb_val *cb = cb_data;
2434     swig_ref    control_ref;
2435     swig_ref    event_ref;
2436     int         rv = IPMI_EVENT_NOT_HANDLED;
2437 
2438     control_ref = swig_make_ref(control, ipmi_control_t);
2439     event_ref = swig_make_ref_destruct(ipmi_event_dup(event), ipmi_event_t);
2440     swig_call_cb_rv('I', &rv,
2441 		    cb, "control_event_val_cb", "%p%p%*p%*p", &control_ref,
2442 		    &event_ref,
2443 		    ipmi_control_get_num_vals(control), valid_vals,
2444 		    ipmi_control_get_num_vals(control), val);
2445     swig_free_ref_check(control_ref, ipmi_control_t);
2446     swig_free_ref(event_ref);
2447     return rv;
2448 }
2449 
2450 static void
control_val_event_handler_cl(ipmi_control_val_event_cb handler,void * handler_data,void * cb_data)2451 control_val_event_handler_cl(ipmi_control_val_event_cb handler,
2452 			     void                      *handler_data,
2453 			     void                      *cb_data)
2454 {
2455     if (handler != control_val_event_handler)
2456 	return;
2457     swig_cb_val *handler_val = handler_data;
2458     deref_swig_cb_val(handler_val);
2459 }
2460 
2461 static void
lanparm_get_parm(ipmi_lanparm_t * lanparm,int err,unsigned char * data,unsigned int data_len,void * cb_data)2462 lanparm_get_parm(ipmi_lanparm_t *lanparm,
2463 		 int            err,
2464 		 unsigned char  *data,
2465 		 unsigned int   data_len,
2466 		 void           *cb_data)
2467 {
2468     swig_cb_val *cb = cb_data;
2469     swig_ref    lanparm_ref;
2470 
2471     lanparm_ref = swig_make_ref_destruct(lanparm, ipmi_lanparm_t);
2472     swig_call_cb(cb, "lanparm_got_parm_cb", "%p%d%*s", &lanparm_ref, err,
2473 		 data_len, (char *) data);
2474     /* One-time call, get rid of the CB. */
2475     deref_swig_cb_val(cb);
2476     swig_free_ref(lanparm_ref);
2477 }
2478 
2479 static void
lanparm_set_parm(ipmi_lanparm_t * lanparm,int err,void * cb_data)2480 lanparm_set_parm(ipmi_lanparm_t *lanparm,
2481 		 int            err,
2482 		 void           *cb_data)
2483 {
2484     swig_cb_val *cb = cb_data;
2485     swig_ref    lanparm_ref;
2486 
2487     if (cb) {
2488 	lanparm_ref = swig_make_ref_destruct(lanparm, ipmi_lanparm_t);
2489 	swig_call_cb(cb, "lanparm_set_parm_cb", "%p%d", &lanparm_ref, err);
2490 	/* One-time call, get rid of the CB. */
2491 	deref_swig_cb_val(cb);
2492 	swig_free_ref(lanparm_ref);
2493     }
2494 }
2495 
2496 static void
lanparm_get_config(ipmi_lanparm_t * lanparm,int err,ipmi_lan_config_t * config,void * cb_data)2497 lanparm_get_config(ipmi_lanparm_t    *lanparm,
2498 		   int               err,
2499 		   ipmi_lan_config_t *config,
2500 		   void              *cb_data)
2501 {
2502     swig_cb_val *cb = cb_data;
2503     swig_ref    lanparm_ref;
2504     swig_ref    config_ref;
2505 
2506     lanparm_ref = swig_make_ref_destruct(lanparm, ipmi_lanparm_t);
2507     config_ref = swig_make_ref_destruct(config, ipmi_lan_config_t);
2508     swig_call_cb(cb, "lanparm_got_config_cb", "%p%d%p", &lanparm_ref, err,
2509 		 &config_ref);
2510     /* One-time call, get rid of the CB. */
2511     deref_swig_cb_val(cb);
2512     swig_free_ref(lanparm_ref);
2513     swig_free_ref(config_ref);
2514 }
2515 
2516 static void
lanparm_set_config(ipmi_lanparm_t * lanparm,int err,void * cb_data)2517 lanparm_set_config(ipmi_lanparm_t    *lanparm,
2518 		   int               err,
2519 		   void              *cb_data)
2520 {
2521     swig_cb_val *cb = cb_data;
2522     swig_ref    lanparm_ref;
2523 
2524     if (cb) {
2525 	lanparm_ref = swig_make_ref_destruct(lanparm, ipmi_lanparm_t);
2526 	swig_call_cb(cb, "lanparm_set_config_cb", "%p%d", &lanparm_ref, err);
2527 	/* One-time call, get rid of the CB. */
2528 	deref_swig_cb_val(cb);
2529 	swig_free_ref(lanparm_ref);
2530     }
2531 }
2532 
2533 static void
lanparm_clear_lock(ipmi_lanparm_t * lanparm,int err,void * cb_data)2534 lanparm_clear_lock(ipmi_lanparm_t    *lanparm,
2535 		   int               err,
2536 		   void              *cb_data)
2537 {
2538     swig_cb_val *cb = cb_data;
2539     swig_ref    lanparm_ref;
2540 
2541     if (cb) {
2542 	lanparm_ref = swig_make_ref_destruct(lanparm, ipmi_lanparm_t);
2543 	swig_call_cb(cb, "lanparm_clear_lock_cb", "%p%d", &lanparm_ref, err);
2544 	/* One-time call, get rid of the CB. */
2545 	deref_swig_cb_val(cb);
2546 	swig_free_ref(lanparm_ref);
2547     }
2548 }
2549 
2550 static void
get_pef(ipmi_pef_t * pef,int err,void * cb_data)2551 get_pef(ipmi_pef_t *pef, int err, void *cb_data)
2552 {
2553     swig_cb_val *cb = cb_data;
2554     swig_ref    pef_ref;
2555 
2556     pef_ref = swig_make_ref_destruct(pef, ipmi_pef_t);
2557     ipmi_pef_ref(pef);
2558     swig_call_cb(cb, "got_pef_cb", "%p%d", &pef_ref, err);
2559     /* One-time call, get rid of the CB. */
2560     deref_swig_cb_val(cb);
2561     swig_free_ref(pef_ref);
2562 }
2563 
2564 static void
pef_get_parm(ipmi_pef_t * pef,int err,unsigned char * data,unsigned int data_len,void * cb_data)2565 pef_get_parm(ipmi_pef_t    *pef,
2566 	     int           err,
2567 	     unsigned char *data,
2568 	     unsigned int  data_len,
2569 	     void          *cb_data)
2570 {
2571     swig_cb_val *cb = cb_data;
2572     swig_ref    pef_ref;
2573 
2574     pef_ref = swig_make_ref_destruct(pef, ipmi_pef_t);
2575     swig_call_cb(cb, "pef_got_parm_cb", "%p%d%*s", &pef_ref, err,
2576 		 data_len, (char *) data);
2577     /* One-time call, get rid of the CB. */
2578     deref_swig_cb_val(cb);
2579     swig_free_ref(pef_ref);
2580 }
2581 
2582 static void
pef_set_parm(ipmi_pef_t * pef,int err,void * cb_data)2583 pef_set_parm(ipmi_pef_t *pef,
2584 	     int        err,
2585 	     void       *cb_data)
2586 {
2587     swig_cb_val *cb = cb_data;
2588     swig_ref    pef_ref;
2589 
2590     if (cb) {
2591 	pef_ref = swig_make_ref_destruct(pef, ipmi_pef_t);
2592 	swig_call_cb(cb, "pef_set_parm_cb", "%p%d", &pef_ref, err);
2593 	/* One-time call, get rid of the CB. */
2594 	deref_swig_cb_val(cb);
2595 	swig_free_ref(pef_ref);
2596     }
2597 }
2598 
2599 static void
pef_get_config(ipmi_pef_t * pef,int err,ipmi_pef_config_t * config,void * cb_data)2600 pef_get_config(ipmi_pef_t        *pef,
2601 	       int               err,
2602 	       ipmi_pef_config_t *config,
2603 	       void              *cb_data)
2604 {
2605     swig_cb_val *cb = cb_data;
2606     swig_ref    pef_ref;
2607     swig_ref    config_ref;
2608 
2609     pef_ref = swig_make_ref_destruct(pef, ipmi_pef_t);
2610     config_ref = swig_make_ref_destruct(config, ipmi_pef_config_t);
2611     swig_call_cb(cb, "pef_got_config_cb", "%p%d%p", &pef_ref, err,
2612 		 &config_ref);
2613     /* One-time call, get rid of the CB. */
2614     deref_swig_cb_val(cb);
2615     swig_free_ref(pef_ref);
2616     swig_free_ref(config_ref);
2617 }
2618 
2619 static void
pef_set_config(ipmi_pef_t * pef,int err,void * cb_data)2620 pef_set_config(ipmi_pef_t    *pef,
2621 	       int           err,
2622 	       void          *cb_data)
2623 {
2624     swig_cb_val *cb = cb_data;
2625     swig_ref    pef_ref;
2626 
2627     if (cb) {
2628 	pef_ref = swig_make_ref_destruct(pef, ipmi_pef_t);
2629 	swig_call_cb(cb, "pef_set_config_cb", "%p%d", &pef_ref, err);
2630 	/* One-time call, get rid of the CB. */
2631 	deref_swig_cb_val(cb);
2632 	swig_free_ref(pef_ref);
2633     }
2634 }
2635 
2636 static void
pef_clear_lock(ipmi_pef_t * pef,int err,void * cb_data)2637 pef_clear_lock(ipmi_pef_t    *pef,
2638 	       int           err,
2639 	       void          *cb_data)
2640 {
2641     swig_cb_val *cb = cb_data;
2642     swig_ref    pef_ref;
2643 
2644     if (cb) {
2645 	pef_ref = swig_make_ref_destruct(pef, ipmi_pef_t);
2646 	swig_call_cb(cb, "pef_clear_lock_cb", "%p%d", &pef_ref, err);
2647 	/* One-time call, get rid of the CB. */
2648 	deref_swig_cb_val(cb);
2649 	swig_free_ref(pef_ref);
2650     }
2651 }
2652 
2653 static void
get_pet(ipmi_pet_t * pet,int err,void * cb_data)2654 get_pet(ipmi_pet_t *pet, int err, void *cb_data)
2655 {
2656     swig_cb_val *cb = cb_data;
2657     swig_ref    pet_ref;
2658 
2659     pet_ref = swig_make_ref_destruct(pet, ipmi_pet_t);
2660     ipmi_pet_ref(pet);
2661     swig_call_cb(cb, "got_pet_cb", "%p%d", &pet_ref, err);
2662     /* One-time call, get rid of the CB. */
2663     deref_swig_cb_val(cb);
2664     swig_free_ref(pet_ref);
2665 }
2666 
2667 static void
event_deleted_handler(ipmi_domain_t * domain,int err,void * cb_data)2668 event_deleted_handler(ipmi_domain_t *domain, int err, void *cb_data)
2669 {
2670     swig_cb_val *cb = cb_data;
2671     swig_ref    domain_ref;
2672 
2673     domain_ref = swig_make_ref(domain, ipmi_domain_t);
2674     swig_call_cb(cb, "event_delete_cb", "%p%d", &domain_ref, err);
2675     swig_free_ref_check(domain_ref, ipmi_domain_t);
2676     /* One-time call, get rid of the CB. */
2677     deref_swig_cb_val(cb);
2678 }
2679 
2680 static void
sol_connection_state_change_cb(ipmi_sol_conn_t * conn,ipmi_sol_state state,int error,void * cb_data)2681 sol_connection_state_change_cb(ipmi_sol_conn_t *conn,
2682 			       ipmi_sol_state  state,
2683 			       int             error,
2684 			       void            *cb_data)
2685 {
2686     swig_cb_val *cb = cb_data;
2687     swig_ref    conn_ref;
2688 
2689     conn_ref = swig_make_ref(conn, ipmi_sol_conn_t);
2690     swig_call_cb(cb, "sol_connection_state_change", "%p%d%d",
2691 		 &conn_ref, state, error);
2692     swig_free_ref_check(conn_ref, ipmi_sol_conn_t);
2693 }
2694 
2695 
2696 static int
sol_data_received_cb(ipmi_sol_conn_t * conn,const void * buf,size_t count,void * cb_data)2697 sol_data_received_cb(ipmi_sol_conn_t *conn,
2698 		     const void      *buf,
2699 		     size_t          count,
2700 		     void            *cb_data)
2701 {
2702     swig_cb_val *cb = cb_data;
2703     swig_ref    conn_ref;
2704     int         rv = 0;
2705 
2706     conn_ref = swig_make_ref(conn, ipmi_sol_conn_t);
2707     swig_call_cb_rv('i', &rv, cb, "sol_data_received", "%p%*b",
2708 		    &conn_ref, count, buf);
2709     swig_free_ref_check(conn_ref, ipmi_sol_conn_t);
2710     return rv;
2711 }
2712 
2713 static void
sol_break_detected_cb(ipmi_sol_conn_t * conn,void * cb_data)2714 sol_break_detected_cb(ipmi_sol_conn_t *conn,
2715 		      void            *cb_data)
2716 {
2717     swig_cb_val *cb = cb_data;
2718     swig_ref    conn_ref;
2719 
2720     conn_ref = swig_make_ref(conn, ipmi_sol_conn_t);
2721     swig_call_cb(cb, "sol_break_detected", "%p", &conn_ref);
2722     swig_free_ref_check(conn_ref, ipmi_sol_conn_t);
2723 }
2724 
2725 static void
sol_bmc_transmit_overrun_cb(ipmi_sol_conn_t * conn,void * cb_data)2726 sol_bmc_transmit_overrun_cb(ipmi_sol_conn_t *conn,
2727 			    void            *cb_data)
2728 {
2729     swig_cb_val *cb = cb_data;
2730     swig_ref    conn_ref;
2731 
2732     conn_ref = swig_make_ref(conn, ipmi_sol_conn_t);
2733     swig_call_cb(cb, "sol_bmc_transmit_overrun", "%p", &conn_ref);
2734     swig_free_ref_check(conn_ref, ipmi_sol_conn_t);
2735 }
2736 
2737 static void
sol_write_complete_cb(ipmi_sol_conn_t * conn,int error,void * cb_data)2738 sol_write_complete_cb(ipmi_sol_conn_t *conn,
2739 		      int             error,
2740 		      void            *cb_data)
2741 {
2742     swig_cb_val *cb = cb_data;
2743     swig_ref    conn_ref;
2744 
2745     conn_ref = swig_make_ref(conn, ipmi_sol_conn_t);
2746     swig_call_cb(cb, "sol_write_complete", "%p%d", &conn_ref, error);
2747     swig_free_ref_check(conn_ref, ipmi_sol_conn_t);
2748     /* One-time callback */
2749     deref_swig_cb_val(cb);
2750 }
2751 
2752 static void
sol_send_break_cb(ipmi_sol_conn_t * conn,int error,void * cb_data)2753 sol_send_break_cb(ipmi_sol_conn_t *conn,
2754 		  int             error,
2755 		  void            *cb_data)
2756 {
2757     swig_cb_val *cb = cb_data;
2758     swig_ref    conn_ref;
2759 
2760     conn_ref = swig_make_ref(conn, ipmi_sol_conn_t);
2761     swig_call_cb(cb, "sol_send_break", "%p%d", &conn_ref, error);
2762     swig_free_ref_check(conn_ref, ipmi_sol_conn_t);
2763     /* One-time callback */
2764     deref_swig_cb_val(cb);
2765 }
2766 
2767 static void
sol_set_CTS_assertable_cb(ipmi_sol_conn_t * conn,int error,void * cb_data)2768 sol_set_CTS_assertable_cb(ipmi_sol_conn_t *conn,
2769 			  int             error,
2770 			  void            *cb_data)
2771 {
2772     swig_cb_val *cb = cb_data;
2773     swig_ref    conn_ref;
2774 
2775     conn_ref = swig_make_ref(conn, ipmi_sol_conn_t);
2776     swig_call_cb(cb, "sol_set_CTS_assertable", "%p%d", &conn_ref, error);
2777     swig_free_ref_check(conn_ref, ipmi_sol_conn_t);
2778     /* One-time callback */
2779     deref_swig_cb_val(cb);
2780 }
2781 
2782 static void
sol_set_DCD_DSR_asserted_cb(ipmi_sol_conn_t * conn,int error,void * cb_data)2783 sol_set_DCD_DSR_asserted_cb(ipmi_sol_conn_t *conn,
2784 			    int             error,
2785 			    void            *cb_data)
2786 {
2787     swig_cb_val *cb = cb_data;
2788     swig_ref    conn_ref;
2789 
2790     conn_ref = swig_make_ref(conn, ipmi_sol_conn_t);
2791     swig_call_cb(cb, "sol_set_DCD_DSR_asserted", "%p%d", &conn_ref, error);
2792     swig_free_ref_check(conn_ref, ipmi_sol_conn_t);
2793     /* One-time callback */
2794     deref_swig_cb_val(cb);
2795 }
2796 
2797 static void
sol_set_RI_asserted_cb(ipmi_sol_conn_t * conn,int error,void * cb_data)2798 sol_set_RI_asserted_cb(ipmi_sol_conn_t *conn,
2799 		       int             error,
2800 		       void            *cb_data)
2801 {
2802     swig_cb_val *cb = cb_data;
2803     swig_ref    conn_ref;
2804 
2805     conn_ref = swig_make_ref(conn, ipmi_sol_conn_t);
2806     swig_call_cb(cb, "sol_set_RI_asserted", "%p%d", &conn_ref, error);
2807     swig_free_ref_check(conn_ref, ipmi_sol_conn_t);
2808     /* One-time callback */
2809     deref_swig_cb_val(cb);
2810 }
2811 
2812 static void
sol_flush_complete_cb(ipmi_sol_conn_t * conn,int error,int queue_selectors_flushed,void * cb_data)2813 sol_flush_complete_cb(ipmi_sol_conn_t *conn,
2814 		      int             error,
2815 		      int             queue_selectors_flushed,
2816 		      void            *cb_data)
2817 {
2818     swig_cb_val *cb = cb_data;
2819     swig_ref    conn_ref;
2820 
2821     conn_ref = swig_make_ref(conn, ipmi_sol_conn_t);
2822     swig_call_cb(cb, "sol_flush_complete", "%p%d%d", &conn_ref, error,
2823 		 queue_selectors_flushed);
2824     swig_free_ref_check(conn_ref, ipmi_sol_conn_t);
2825     /* One-time callback */
2826     deref_swig_cb_val(cb);
2827 }
2828 
2829 static void
solparm_get_parm(ipmi_solparm_t * solparm,int err,unsigned char * data,unsigned int data_len,void * cb_data)2830 solparm_get_parm(ipmi_solparm_t *solparm,
2831 		 int            err,
2832 		 unsigned char  *data,
2833 		 unsigned int   data_len,
2834 		 void           *cb_data)
2835 {
2836     swig_cb_val *cb = cb_data;
2837     swig_ref    solparm_ref;
2838 
2839     solparm_ref = swig_make_ref_destruct(solparm, ipmi_solparm_t);
2840     swig_call_cb(cb, "solparm_got_parm_cb", "%p%d%*s", &solparm_ref, err,
2841 		 data_len, (char *) data);
2842     /* One-time call, get rid of the CB. */
2843     deref_swig_cb_val(cb);
2844     swig_free_ref(solparm_ref);
2845 }
2846 
2847 static void
solparm_set_parm(ipmi_solparm_t * solparm,int err,void * cb_data)2848 solparm_set_parm(ipmi_solparm_t *solparm,
2849 		 int            err,
2850 		 void           *cb_data)
2851 {
2852     swig_cb_val *cb = cb_data;
2853     swig_ref    solparm_ref;
2854 
2855     if (cb) {
2856 	solparm_ref = swig_make_ref_destruct(solparm, ipmi_solparm_t);
2857 	swig_call_cb(cb, "solparm_set_parm_cb", "%p%d", &solparm_ref, err);
2858 	/* One-time call, get rid of the CB. */
2859 	deref_swig_cb_val(cb);
2860 	swig_free_ref(solparm_ref);
2861     }
2862 }
2863 
2864 static void
solparm_get_config(ipmi_solparm_t * solparm,int err,ipmi_sol_config_t * config,void * cb_data)2865 solparm_get_config(ipmi_solparm_t    *solparm,
2866 		   int               err,
2867 		   ipmi_sol_config_t *config,
2868 		   void              *cb_data)
2869 {
2870     swig_cb_val *cb = cb_data;
2871     swig_ref    solparm_ref;
2872     swig_ref    config_ref;
2873 
2874     solparm_ref = swig_make_ref_destruct(solparm, ipmi_solparm_t);
2875     config_ref = swig_make_ref_destruct(config, ipmi_sol_config_t);
2876     swig_call_cb(cb, "solparm_got_config_cb", "%p%d%p", &solparm_ref, err,
2877 		 &config_ref);
2878     /* One-time call, get rid of the CB. */
2879     deref_swig_cb_val(cb);
2880     swig_free_ref(solparm_ref);
2881     swig_free_ref(config_ref);
2882 }
2883 
2884 static void
solparm_set_config(ipmi_solparm_t * solparm,int err,void * cb_data)2885 solparm_set_config(ipmi_solparm_t    *solparm,
2886 		   int               err,
2887 		   void              *cb_data)
2888 {
2889     swig_cb_val *cb = cb_data;
2890     swig_ref    solparm_ref;
2891 
2892     if (cb) {
2893 	solparm_ref = swig_make_ref_destruct(solparm, ipmi_solparm_t);
2894 	swig_call_cb(cb, "solparm_set_config_cb", "%p%d", &solparm_ref, err);
2895 	/* One-time call, get rid of the CB. */
2896 	deref_swig_cb_val(cb);
2897 	swig_free_ref(solparm_ref);
2898     }
2899 }
2900 
2901 static void
solparm_clear_lock(ipmi_solparm_t * solparm,int err,void * cb_data)2902 solparm_clear_lock(ipmi_solparm_t    *solparm,
2903 		   int               err,
2904 		   void              *cb_data)
2905 {
2906     swig_cb_val *cb = cb_data;
2907     swig_ref    solparm_ref;
2908 
2909     if (cb) {
2910 	solparm_ref = swig_make_ref_destruct(solparm, ipmi_solparm_t);
2911 	swig_call_cb(cb, "solparm_clear_lock_cb", "%p%d", &solparm_ref, err);
2912 	/* One-time call, get rid of the CB. */
2913 	deref_swig_cb_val(cb);
2914 	swig_free_ref(solparm_ref);
2915     }
2916 }
2917 
2918 #if defined(HAVE_GLIB) || defined(HAVE_GLIB12)
2919 #include <OpenIPMI/ipmi_glib.h>
2920 static void
glib_handle_log(const char * domain,const char * pfx,const char * message)2921 glib_handle_log(const char *domain,
2922 		const char *pfx,
2923 		const char *message)
2924 {
2925     swig_cb_val *handler = swig_log_handler;
2926 
2927     if (! handler)
2928 	return;
2929 
2930     swig_call_cb(handler, "log", "%s%s", pfx, message);
2931 }
2932 
2933 #if defined(HAVE_GLIB) && defined(HAVE_GLIB12)
2934 #include <dlfcn.h>
2935 #endif
2936 
2937 /*
2938  * Initialize the OS handler with the glib version.
2939  */
2940 os_handler_t *
init_glib_shim(char * ver)2941 init_glib_shim(char *ver)
2942 {
2943     os_handler_t *swig_os_hnd;
2944 #if defined(HAVE_GLIB) && defined(HAVE_GLIB12)
2945 /* Two versions of glib.  Go through special machinations to make this
2946    work right.  We can't directly link with glib, we have to dlopen it
2947    to get the right version. */
2948 
2949     static char  *olibst = "libOpenIPMIglib%s.so";
2950     char         dummy[1];
2951     char         *name;
2952     void         *hndl;
2953     os_handler_t *(*get)(int);
2954     void         (*setlog)(void (*hndlr)(const char *domain,
2955 					 const char *pfx,
2956 					 const char *msg));
2957     int          len;
2958 
2959     len = snprintf(dummy, 1, olibst, ver);
2960     name = malloc(len+1);
2961     if (!name) {
2962 	fprintf(stderr, "Unable to allocation memory for glib\n");
2963 	abort();
2964     }
2965     snprintf(name, len+1, olibst, ver);
2966     hndl = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
2967     if (!hndl) {
2968 	fprintf(stderr, "Unable to open the glib library: %s: %s\n",
2969 		name, dlerror());
2970 	free(name);
2971 	abort();
2972     }
2973     free(name);
2974     get = dlsym(hndl, "ipmi_glib_get_os_handler");
2975     if (!get) {
2976 	fprintf(stderr,
2977 		"Could not find glib function: ipmi_glib_get_os_handler: %s\n",
2978 		dlerror());
2979 	abort();
2980     }
2981     setlog = dlsym(hndl, "ipmi_glib_set_log_handler");
2982     if (!setlog) {
2983 	fprintf(stderr,
2984 		"Could not find glib function: ipmi_glib_set_log_handler: %s\n",
2985 		dlerror());
2986 	abort();
2987     }
2988 
2989     swig_os_hnd = get(0);
2990     swig_os_hnd->set_log_handler(swig_os_hnd, openipmi_swig_vlog);
2991     ipmi_init(swig_os_hnd);
2992     ipmi_cmdlang_init(swig_os_hnd);
2993     setlog(glib_handle_log);
2994 #else
2995     swig_os_hnd = ipmi_glib_get_os_handler(0);
2996     swig_os_hnd->set_log_handler(swig_os_hnd, openipmi_swig_vlog);
2997     ipmi_init(swig_os_hnd);
2998     ipmi_cmdlang_init(swig_os_hnd);
2999     ipmi_glib_set_log_handler(glib_handle_log);
3000 #endif
3001     return swig_os_hnd;
3002 }
3003 #endif
3004 
3005 %}
3006 
3007 typedef struct {
3008 } ipmi_domain_t;
3009 
3010 typedef struct {
3011 } ipmi_domain_id_t;
3012 
3013 typedef struct {
3014 } ipmi_args_t;
3015 
3016 typedef struct {
3017 } ipmi_entity_t;
3018 
3019 typedef struct {
3020 } ipmi_entity_id_t;
3021 
3022 typedef struct {
3023 } ipmi_fru_t;
3024 
3025 typedef struct {
3026 } ipmi_fru_node_t;
3027 
3028 typedef struct {
3029 } ipmi_mc_t;
3030 
3031 typedef struct {
3032 } ipmi_mcid_t;
3033 
3034 typedef struct {
3035 } ipmi_event_t;
3036 
3037 typedef struct {
3038 } ipmi_sensor_t;
3039 
3040 typedef struct {
3041 } ipmi_sensor_id_t;
3042 
3043 typedef struct {
3044 } ipmi_control_t;
3045 
3046 typedef struct {
3047 } ipmi_control_id_t;
3048 
3049 typedef struct {
3050 } ipmi_channel_info_t;
3051 
3052 typedef struct {
3053 } ipmi_channel_access_t;
3054 
3055 typedef struct {
3056 } ipmi_user_t;
3057 
3058 typedef struct {
3059 } ipmi_lanparm_t;
3060 
3061 typedef struct {
3062 } ipmi_lan_config_t;
3063 
3064 typedef struct {
3065 } ipmi_pef_t;
3066 
3067 typedef struct {
3068 } ipmi_pef_config_t;
3069 
3070 typedef struct {
3071 } ipmi_pet_t;
3072 
3073 typedef struct {
3074 } ipmi_cmdlang_t;
3075 
3076 typedef struct {
3077 } ipmi_cmdlang_event_t;
3078 
3079 typedef struct {
3080 } ipmi_sol_conn_t;
3081 
3082 typedef struct {
3083 } ipmi_sol_config_t;
3084 
3085 typedef struct {
3086 } ipmi_solparm_t;
3087 
3088 %inline %{
enable_debug_malloc()3089 void enable_debug_malloc()
3090 {
3091     if (!swig_os_hnd) {
3092 	DEBUG_MALLOC_ENABLE();
3093     }
3094 }
3095 
enable_debug_msg()3096 void enable_debug_msg()
3097 {
3098     DEBUG_MSG_ENABLE();
3099 }
3100 
disable_debug_msg()3101 void disable_debug_msg()
3102 {
3103     DEBUG_MSG_DISABLE();
3104 }
3105 
enable_debug_rawmsg()3106 void enable_debug_rawmsg()
3107 {
3108     DEBUG_RAWMSG_ENABLE();
3109 }
3110 
disable_debug_rawmsg()3111 void disable_debug_rawmsg()
3112 {
3113     DEBUG_RAWMSG_DISABLE();
3114 }
3115 
3116 int
init_glib(void)3117 init_glib(void)
3118 {
3119 #ifdef HAVE_GLIB
3120     if (swig_os_hnd)
3121 	return 0;
3122 #ifdef OpenIPMI_HAVE_INIT_LANG
3123     init_lang();
3124 #endif
3125     swig_os_hnd = init_glib_shim("");
3126 #else
3127     return ENOSYS;
3128 #endif
3129 }
3130 
3131 int
init_glib12(void)3132 init_glib12(void)
3133 {
3134 #ifdef HAVE_GLIB12
3135     if (swig_os_hnd)
3136 	return 0;
3137 #ifdef OpenIPMI_HAVE_INIT_LANG
3138     init_lang();
3139 #endif
3140     swig_os_hnd = init_glib_shim("12");
3141 #else
3142     return ENOSYS;
3143 #endif
3144 }
3145 
3146 #if defined(HAVE_TCL)
3147 #include <OpenIPMI/ipmi_tcl.h>
3148 #endif
3149 
3150 int
init_tcl(void)3151 init_tcl(void)
3152 {
3153 #ifdef HAVE_TCL
3154     if (swig_os_hnd)
3155 	return 0;
3156 #ifdef OpenIPMI_HAVE_INIT_LANG
3157     init_lang();
3158 #endif
3159     swig_os_hnd = ipmi_tcl_get_os_handler(0);
3160     swig_os_hnd->set_log_handler(swig_os_hnd, openipmi_swig_vlog);
3161     ipmi_init(swig_os_hnd);
3162     ipmi_cmdlang_init(swig_os_hnd);
3163     return 0;
3164 #else
3165     return ENOSYS;
3166 #endif
3167 }
3168 
3169 /*
3170  * Initialize the OS handler and use the POSIX version.
3171  */
3172 int
init_posix(void)3173 init_posix(void)
3174 {
3175     if (swig_os_hnd)
3176 	return 0;
3177 #ifdef OpenIPMI_HAVE_INIT_LANG
3178     init_lang();
3179 #endif
3180 #ifdef USE_POSIX_THREADS
3181     swig_os_hnd = ipmi_posix_thread_setup_os_handler(SIGUSR1);
3182 #else
3183     swig_os_hnd = ipmi_posix_setup_os_handler();
3184 #endif
3185     swig_os_hnd->set_log_handler(swig_os_hnd, openipmi_swig_vlog);
3186     ipmi_init(swig_os_hnd);
3187     ipmi_cmdlang_init(swig_os_hnd);
3188     return 0;
3189 }
3190 
3191 /*
3192  * Initialize the OS handler with the default version.  This is glib
3193  * if it is present, POSIX if it is not.
3194  */
3195 int
init(void)3196 init(void)
3197 {
3198     int rv;
3199 
3200     if (rv = init_glib())
3201         rv = init_posix();
3202     return rv;
3203 }
3204 
3205 /*
3206  * Free up all the memory used by OpenIPMI.
3207  */
3208 void
shutdown_everything()3209 shutdown_everything()
3210 {
3211     IPMI_SWIG_C_CB_ENTRY
3212     ipmi_cmdlang_cleanup();
3213     ipmi_shutdown();
3214     swig_os_hnd->free_os_handler(swig_os_hnd);
3215     swig_os_hnd = NULL;
3216 #ifdef OpenIPMI_HAVE_CLEANUP_LANG
3217     void cleanup_lang();
3218 #endif
3219     IPMI_SWIG_C_CB_EXIT
3220 }
3221 
3222 /*
3223  * Perform one operation.  The first parameter is a timeout in
3224  * milliseconds.
3225  */
3226 void
wait_io(int timeout)3227 wait_io(int timeout)
3228 {
3229     struct timeval tv = { (timeout / 1000), ((timeout + 999) % 1000) };
3230     IPMI_SWIG_C_BLOCK_ENTRY
3231     swig_os_hnd->perform_one_op(swig_os_hnd, &tv);
3232     IPMI_SWIG_C_BLOCK_EXIT
3233 }
3234 
3235 %}
3236 
3237 /*
3238  * Error return constants returned by OpenIPMI.
3239  */
3240 %constant int ebadf = EBADF;
3241 %constant int einval = EINVAL;
3242 %constant int e2big = E2BIG;
3243 %constant int enomem = ENOMEM;
3244 %constant int enoent = ENOENT;
3245 %constant int ecanceled = ECANCELED;
3246 %constant int enosys = ENOSYS;
3247 %constant int eexist = EEXIST;
3248 %constant int eagain = EAGAIN;
3249 %constant int eperm = EPERM;
3250 
3251 /*
3252  * Return values for event handlers
3253  */
3254 %constant int EVENT_NOT_HANDLED = IPMI_EVENT_NOT_HANDLED;
3255 %constant int EVENT_HANDLED = IPMI_EVENT_HANDLED;
3256 %constant int EVENT_HANDLED_PASS = IPMI_EVENT_HANDLED_PASS;
3257 
3258 /* These two defines simplify the functions that do addition/removal
3259    of callbacks.  The type is the object type (domain, entity, etc)
3260    and the name is the stuff in the middle of the name, ie
3261    (ipmi_<type>_add_<name>_handler.  The function that will be called
3262    with the info is <type>_<name>_handler. */
3263 #define cb_add(type, name, func) \
3264 	int         rv;							\
3265 	swig_cb_val *handler_val;					\
3266 	IPMI_SWIG_C_CB_ENTRY						\
3267 	if (! valid_swig_cb(handler, func))				\
3268 	    rv = EINVAL;						\
3269 	else {								\
3270 	    handler_val = ref_swig_cb(handler, func);			\
3271 	    rv = ipmi_ ## type ## _add_ ## name ## _handler		\
3272 		 (self, type ## _ ## name ## _handler, handler_val);	\
3273 	    if (rv)							\
3274 		deref_swig_cb_val(handler_val);				\
3275 	}								\
3276 	IPMI_SWIG_C_CB_EXIT						\
3277 	return rv;
3278 #define cb_rm(type, name, func) \
3279 	int         rv;							\
3280 	swig_cb_val *handler_val;					\
3281 	IPMI_SWIG_C_CB_ENTRY						\
3282 	if (! valid_swig_cb(handler, func))				\
3283 	    rv = EINVAL;						\
3284 	else {								\
3285 	    handler_val = get_swig_cb(handler, func);			\
3286 	    rv = ipmi_ ## type ## _remove_ ## name ##_handler		\
3287 		 (self, type ## _ ## name ## _handler, handler_val);	\
3288 	    if (!rv)							\
3289 		deref_swig_cb_val(handler_val);				\
3290 	}								\
3291 	IPMI_SWIG_C_CB_EXIT						\
3292 	return rv;
3293 
3294 
3295 /*
3296  * A bug in swig (default parameters not used in inline) causes this
3297  * to have to not be in an inline and done the hard way.
3298  */
3299 %{
3300 static void
domain_cleanup_add(ipmi_domain_t * domain,void * cb_data)3301 domain_cleanup_add(ipmi_domain_t *domain, void *cb_data)
3302 {
3303     ipmi_domain_add_connect_change_handler_cl
3304 	(domain, domain_connect_change_handler_cl, NULL);
3305 }
3306 
3307 static ipmi_domain_id_t *
open_domain(char * name,argarray * args,swig_cb * done,swig_cb * up)3308 open_domain(char *name, argarray *args, swig_cb *done, swig_cb *up)
3309 {
3310     int                i, j;
3311     int                num_options = 0;
3312     ipmi_open_option_t options[10];
3313     int                set = 0;
3314     ipmi_args_t        *con_parms[2];
3315     ipmi_con_t         *con[2];
3316     ipmi_domain_id_t   *nd;
3317     int                rv;
3318     swig_cb_val        *done_val = NULL;
3319     swig_cb_val        *up_val = NULL;
3320     ipmi_domain_con_cb con_change = NULL;
3321     ipmi_domain_ptr_cb domain_up = NULL;
3322 
3323     IPMI_SWIG_C_CB_ENTRY
3324     nd = malloc(sizeof(*nd));
3325 
3326     for (i=0; i<args->len; i++) {
3327 	if (num_options >= 10) {
3328 	    free(nd);
3329 	    nd = NULL;
3330 	    goto out_err;
3331 	}
3332 
3333 	if (! ipmi_parse_options(options+num_options, args->val[i]))
3334 	    num_options++;
3335 	else
3336 	    break;
3337     }
3338 
3339     rv = ipmi_parse_args(&i, args->len, args->val, &con_parms[set]);
3340     if (rv) {
3341 	free(nd);
3342 	nd = NULL;
3343 	goto out_err;
3344     }
3345     set++;
3346 
3347     if (i < args->len) {
3348 	rv = ipmi_parse_args(&i, args->len, args->val, &con_parms[set]);
3349 	if (rv) {
3350 	    ipmi_free_args(con_parms[0]);
3351 	    free(nd);
3352 	    nd = NULL;
3353 	    goto out_err;
3354 	}
3355 	set++;
3356     }
3357 
3358     for (i=0; i<set; i++) {
3359 	rv = ipmi_args_setup_con(con_parms[i],
3360 				 swig_os_hnd,
3361 				 NULL,
3362 				 &con[i]);
3363 	if (rv) {
3364 	    for (j=0; j<i; j++)
3365 		con[j]->close_connection(con[j]);
3366             free(nd);
3367 	    nd = NULL;
3368 	    goto out;
3369 	}
3370     }
3371 
3372     if (!nil_swig_cb(up)) {
3373 	if (valid_swig_cb(up, domain_up_cb)) {
3374 	    up_val = ref_swig_cb(up, domain_up_cb);
3375 	    domain_up = domain_fully_up;
3376 	} else {
3377 	    free(nd);
3378 	    nd = NULL;
3379 	    goto out;
3380 	}
3381     }
3382     if (!nil_swig_cb(done)){
3383 	if (valid_swig_cb(done, conn_change_cb)) {
3384 	    done_val = ref_swig_cb(done, conn_change_cb);
3385 	    con_change = domain_connect_change_handler;
3386 	} else {
3387 	    if (domain_up)
3388 		deref_swig_cb(up);
3389 	    free(nd);
3390 	    nd = NULL;
3391 	    goto out;
3392 	}
3393     }
3394     rv = ipmi_open_domain(name, con, set, con_change, done_val,
3395 			  domain_up, up_val,
3396 			  options, num_options, nd);
3397     if (rv) {
3398 	if (domain_up)
3399 	    deref_swig_cb(up);
3400 	if (con_change)
3401 	    deref_swig_cb(done);
3402 	for (i=0; i<set; i++)
3403 	    con[i]->close_connection(con[i]);
3404 	free(nd);
3405 	nd = NULL;
3406 	goto out;
3407     }
3408 
3409     ipmi_domain_pointer_cb(*nd, domain_cleanup_add, NULL);
3410 
3411  out:
3412     for (i=0; i<set; i++)
3413 	ipmi_free_args(con_parms[i]);
3414 
3415  out_err:
3416     IPMI_SWIG_C_CB_EXIT
3417     return nd;
3418 }
3419 
3420 static ipmi_domain_id_t *
open_domain2(char * name,argarray * args,swig_cb * done,swig_cb * up)3421 open_domain2(char *name, argarray *args, swig_cb *done, swig_cb *up)
3422 {
3423     int                i, j;
3424     int                num_options = 0;
3425     ipmi_open_option_t options[10];
3426     int                set = 0;
3427     ipmi_args_t        *con_parms[2];
3428     ipmi_con_t         *con[2];
3429     ipmi_domain_id_t   *nd;
3430     int                rv;
3431     swig_cb_val        *done_val = NULL;
3432     swig_cb_val        *up_val = NULL;
3433     ipmi_domain_con_cb con_change = NULL;
3434     ipmi_domain_ptr_cb domain_up = NULL;
3435 
3436     IPMI_SWIG_C_CB_ENTRY
3437     nd = malloc(sizeof(*nd));
3438 
3439     for (i=0; i<args->len; i++) {
3440 	if (num_options >= 10) {
3441 	    free(nd);
3442 	    nd = NULL;
3443 	    goto out_err;
3444 	}
3445 
3446 	if (! ipmi_parse_options(options+num_options, args->val[i]))
3447 	    num_options++;
3448 	else
3449 	    break;
3450     }
3451 
3452     rv = ipmi_parse_args2(&i, args->len, args->val, &con_parms[set]);
3453     if (rv) {
3454 	free(nd);
3455 	nd = NULL;
3456 	goto out_err;
3457     }
3458     set++;
3459 
3460     if (i < args->len) {
3461 	rv = ipmi_parse_args2(&i, args->len, args->val, &con_parms[set]);
3462 	if (rv) {
3463 	    ipmi_free_args(con_parms[0]);
3464 	    free(nd);
3465 	    nd = NULL;
3466 	    goto out_err;
3467 	}
3468 	set++;
3469     }
3470 
3471     for (i=0; i<set; i++) {
3472 	rv = ipmi_args_setup_con(con_parms[i],
3473 				 swig_os_hnd,
3474 				 NULL,
3475 				 &con[i]);
3476 	if (rv) {
3477 	    for (j=0; j<i; j++)
3478 		con[j]->close_connection(con[j]);
3479             free(nd);
3480 	    nd = NULL;
3481 	    goto out;
3482 	}
3483     }
3484 
3485     if (!nil_swig_cb(up)) {
3486 	if (valid_swig_cb(up, domain_up_cb)) {
3487 	    up_val = ref_swig_cb(up, domain_up_cb);
3488 	    domain_up = domain_fully_up;
3489 	} else {
3490 	    free(nd);
3491 	    nd = NULL;
3492 	    goto out;
3493 	}
3494     }
3495     if (!nil_swig_cb(done)){
3496 	if (valid_swig_cb(done, conn_change_cb)) {
3497 	    done_val = ref_swig_cb(done, conn_change_cb);
3498 	    con_change = domain_connect_change_handler;
3499 	} else {
3500 	    if (domain_up)
3501 		deref_swig_cb(up);
3502 	    free(nd);
3503 	    nd = NULL;
3504 	    goto out;
3505 	}
3506     }
3507     rv = ipmi_open_domain(name, con, set, con_change, done_val,
3508 			  domain_up, up_val,
3509 			  options, num_options, nd);
3510     if (rv) {
3511 	if (domain_up)
3512 	    deref_swig_cb(up);
3513 	if (con_change)
3514 	    deref_swig_cb(done);
3515 	for (i=0; i<set; i++)
3516 	    con[i]->close_connection(con[i]);
3517 	free(nd);
3518 	nd = NULL;
3519 	goto out;
3520     }
3521 
3522     ipmi_domain_pointer_cb(*nd, domain_cleanup_add, NULL);
3523 
3524  out:
3525     for (i=0; i<set; i++)
3526 	ipmi_free_args(con_parms[i]);
3527 
3528  out_err:
3529     IPMI_SWIG_C_CB_EXIT
3530     return nd;
3531 }
3532 
3533 static ipmi_domain_id_t *
open_domain3(char * name,argarray * ioptions,iargarray * args,swig_cb * done,swig_cb * up)3534 open_domain3(char *name, argarray *ioptions, iargarray *args,
3535 	     swig_cb *done, swig_cb *up)
3536 {
3537     int                i, j;
3538     int                num_options = 0;
3539     ipmi_open_option_t options[10];
3540     int                set = 0;
3541     ipmi_con_t         *con[2];
3542     ipmi_domain_id_t   *nd;
3543     int                rv;
3544     swig_cb_val        *done_val = NULL;
3545     swig_cb_val        *up_val = NULL;
3546     ipmi_domain_con_cb con_change = NULL;
3547     ipmi_domain_ptr_cb domain_up = NULL;
3548 
3549     IPMI_SWIG_C_CB_ENTRY
3550     nd = malloc(sizeof(*nd));
3551 
3552     for (i=0; i<ioptions->len; i++) {
3553 	if (num_options >= 10) {
3554 	    free(nd);
3555 	    nd = NULL;
3556 	    goto out_err;
3557 	}
3558 
3559 	if (! ipmi_parse_options(options+num_options, ioptions->val[i]))
3560 	    num_options++;
3561 	else
3562 	    break;
3563     }
3564 
3565     for (i=0; i<args->len; i++) {
3566 	rv = ipmi_args_setup_con(args->val[i],
3567 				 swig_os_hnd,
3568 				 NULL,
3569 				 &con[i]);
3570 	if (rv) {
3571 	    for (j=0; j<i; j++)
3572 		con[j]->close_connection(con[j]);
3573             free(nd);
3574 	    nd = NULL;
3575 	    goto out;
3576 	}
3577 	set++;
3578     }
3579 
3580     if (!nil_swig_cb(up)) {
3581 	if (valid_swig_cb(up, domain_up_cb)) {
3582 	    up_val = ref_swig_cb(up, domain_up_cb);
3583 	    domain_up = domain_fully_up;
3584 	} else {
3585 	    free(nd);
3586 	    nd = NULL;
3587 	    goto out;
3588 	}
3589     }
3590     if (!nil_swig_cb(done)){
3591 	if (valid_swig_cb(done, conn_change_cb)) {
3592 	    done_val = ref_swig_cb(done, conn_change_cb);
3593 	    con_change = domain_connect_change_handler;
3594 	} else {
3595 	    if (domain_up)
3596 		deref_swig_cb(up);
3597 	    free(nd);
3598 	    nd = NULL;
3599 	    goto out;
3600 	}
3601     }
3602     rv = ipmi_open_domain(name, con, set, con_change, done_val,
3603 			  domain_up, up_val,
3604 			  options, num_options, nd);
3605     if (rv) {
3606 	if (domain_up)
3607 	    deref_swig_cb(up);
3608 	if (con_change)
3609 	    deref_swig_cb(done);
3610 	for (i=0; i<set; i++)
3611 	    con[i]->close_connection(con[i]);
3612 	free(nd);
3613 	nd = NULL;
3614 	goto out;
3615     }
3616 
3617     ipmi_domain_pointer_cb(*nd, domain_cleanup_add, NULL);
3618 
3619  out:
3620 
3621  out_err:
3622     IPMI_SWIG_C_CB_EXIT
3623     return nd;
3624 }
3625 
3626 static void
set_log_handler(swig_cb * handler)3627 set_log_handler(swig_cb *handler)
3628 {
3629     swig_cb_val *old_handler = swig_log_handler;
3630     IPMI_SWIG_C_CB_ENTRY
3631     if (valid_swig_cb(handler, log))
3632 	swig_log_handler = ref_swig_cb(handler, log);
3633     else
3634 	swig_log_handler = NULL;
3635     if (old_handler)
3636 	deref_swig_cb_val(old_handler);
3637     IPMI_SWIG_C_CB_EXIT
3638 }
3639 
3640 static const char *
color_string(int color)3641 color_string(int color)
3642 {
3643     return ipmi_get_color_string(color);
3644 }
3645 
3646 static const char *
lanparm_parm_to_str(int parm)3647 lanparm_parm_to_str(int parm)
3648 {
3649     return ipmi_lanconfig_parm_to_str(parm);
3650 }
3651 
3652 static int
lanconfig_enum_val(int parm,int val,int * nval,const char ** sval)3653 lanconfig_enum_val(int parm, int val, int *nval, const char **sval)
3654 {
3655     return ipmi_lanconfig_enum_val(parm, val, nval, sval);
3656 }
3657 
3658 static int
lanconfig_enum_idx(int parm,int idx,const char ** sval)3659 lanconfig_enum_idx(int parm, int idx, const char **sval)
3660 {
3661     return ipmi_lanconfig_enum_idx(parm, idx, sval);
3662 }
3663 
3664 
3665 static int
lanparm_str_to_parm(char * str)3666 lanparm_str_to_parm(char *str)
3667 {
3668     return ipmi_lanconfig_str_to_parm(str);
3669 }
3670 
3671 static const char *
pef_parm_to_str(int parm)3672 pef_parm_to_str(int parm)
3673 {
3674     return ipmi_pefconfig_parm_to_str(parm);
3675 }
3676 
3677 static int
pef_str_to_parm(char * str)3678 pef_str_to_parm(char *str)
3679 {
3680     return ipmi_pefconfig_str_to_parm(str);
3681 }
3682 
3683 static int
pefconfig_enum_val(int parm,int val,int * nval,const char ** sval)3684 pefconfig_enum_val(int parm, int val, int *nval, const char **sval)
3685 {
3686     return ipmi_lanconfig_enum_val(parm, val, nval, sval);
3687 }
3688 
3689 static int
pefconfig_enum_idx(int parm,int idx,const char ** sval)3690 pefconfig_enum_idx(int parm, int idx, const char **sval)
3691 {
3692     return ipmi_pefconfig_enum_idx(parm, idx, sval);
3693 }
3694 
3695 static const char *
get_threshold_access_support_string(int val)3696 get_threshold_access_support_string(int val)
3697 {
3698     return ipmi_get_threshold_access_support_string(val);
3699 }
3700 
3701 static const char *
get_hysteresis_support_string(int val)3702 get_hysteresis_support_string(int val)
3703 {
3704     return ipmi_get_hysteresis_support_string(val);
3705 }
3706 
3707 static const char *
get_event_support_string(int val)3708 get_event_support_string(int val)
3709 {
3710     return ipmi_get_event_support_string(val);
3711 }
3712 
3713 static const char *
channel_medium_string(int val)3714 channel_medium_string(int val)
3715 {
3716     return ipmi_channel_medium_string(val);
3717 }
3718 
3719 static const char *
channel_protocol_string(int val)3720 channel_protocol_string(int val)
3721 {
3722     return ipmi_channel_protocol_string(val);
3723 }
3724 
3725 static const char *
channel_session_support_string(int val)3726 channel_session_support_string(int val)
3727 {
3728     return ipmi_channel_session_support_string(val);
3729 }
3730 
3731 static const char *
channel_access_mode_string(int val)3732 channel_access_mode_string(int val)
3733 {
3734     return ipmi_channel_access_mode_string(val);
3735 }
3736 
3737 static const char *
privilege_string(int val)3738 privilege_string(int val)
3739 {
3740     return ipmi_privilege_string(val);
3741 }
3742 
3743 static const char *
authtype_string(int val)3744 authtype_string(int val)
3745 {
3746     return ipmi_authtype_string(val);
3747 }
3748 
3749 static const char *
solparm_parm_to_str(int parm)3750 solparm_parm_to_str(int parm)
3751 {
3752     return ipmi_solconfig_parm_to_str(parm);
3753 }
3754 
3755 static int
solparm_str_to_parm(char * str)3756 solparm_str_to_parm(char *str)
3757 {
3758     return ipmi_solconfig_str_to_parm(str);
3759 }
3760 
3761 static int
solconfig_enum_val(int parm,int val,int * nval,const char ** sval)3762 solconfig_enum_val(int parm, int val, int *nval, const char **sval)
3763 {
3764     return ipmi_solconfig_enum_val(parm, val, nval, sval);
3765 }
3766 
3767 static int
solconfig_enum_idx(int parm,int idx,const char ** sval)3768 solconfig_enum_idx(int parm, int idx, const char **sval)
3769 {
3770     return ipmi_solconfig_enum_idx(parm, idx, sval);
3771 }
3772 
3773 static char *
get_error_string(unsigned int err)3774 get_error_string(unsigned int err)
3775 {
3776     int  len;
3777     char *buf;
3778 
3779     len = ipmi_get_error_string_len(err);
3780     buf = malloc(len);
3781     if (!buf)
3782 	return NULL;
3783     ipmi_get_error_string(err, buf, len);
3784     return buf;
3785 }
3786 
3787 static void
domain_change_handler(ipmi_domain_t * domain,enum ipmi_update_e op,void * cb_data)3788 domain_change_handler(ipmi_domain_t      *domain,
3789 		      enum ipmi_update_e op,
3790 		      void               *cb_data)
3791 {
3792     swig_cb_val *cb = cb_data;
3793     swig_ref    domain_ref;
3794     domain_ref = swig_make_ref(domain, ipmi_domain_t);
3795     swig_call_cb(cb, "domain_change_cb", "%s%p",
3796 		 ipmi_update_e_string(op), &domain_ref);
3797     swig_free_ref_check(domain_ref, ipmi_domain_t);
3798 }
3799 
3800 int
add_domain_change_handler(swig_cb * handler)3801 add_domain_change_handler(swig_cb *handler)
3802 {
3803     int rv;
3804     swig_cb_val *handler_val;
3805     IPMI_SWIG_C_CB_ENTRY
3806     if (! valid_swig_cb(handler, domain_change_cb)) {
3807 	rv = EINVAL;
3808 	goto out_err;
3809     }
3810     handler_val = ref_swig_cb(handler, domain_change_cb);
3811     rv = ipmi_domain_add_domain_change_handler(domain_change_handler,
3812 					       handler_val);
3813     if (rv)
3814 	deref_swig_cb_val(handler_val);
3815 out_err:
3816     IPMI_SWIG_C_CB_EXIT
3817     return rv;
3818 }
3819 
3820 int
remove_domain_change_handler(swig_cb * handler)3821 remove_domain_change_handler(swig_cb *handler)
3822 {
3823     int rv;
3824     swig_cb_val *handler_val;
3825     IPMI_SWIG_C_CB_ENTRY
3826     if (! valid_swig_cb(handler, domain_change_cb)) {
3827 	rv = EINVAL;
3828 	goto out_err;
3829     }
3830     handler_val = get_swig_cb(handler, domain_change_cb);
3831     rv = ipmi_domain_remove_domain_change_handler(domain_change_handler,
3832 						  handler_val);
3833     if (!rv)
3834 	deref_swig_cb_val(handler_val);
3835 out_err:
3836     IPMI_SWIG_C_CB_EXIT
3837     return rv;
3838 }
3839 
3840 %}
3841 
3842 %newobject open_domain;
3843 %newobject open_domain2;
3844 %newobject open_domain3;
3845 /*
3846  * Create a new domain.  The domain will be named with the first parm,
3847  * the startup arguments are in a reference to a list in the second
3848  * parm (\@args), the third parm is a callback object whose
3849  * conn_change_cb method will be called when the domain has connected
3850  * (but it may not be fully up yet).  The fourth parameter's
3851  * domain_up_cb method will be called when the domain is completely up
3852  * Note that the done method will be kept around and will continue to
3853  * be called on connection changes.  If you don't want it any more,
3854  * it must be deregistered with remove_connect_change_handler.
3855  * Passing in a reference to an undefined value will cause the handlers
3856  * to not be called.
3857  * The domain_up_cb methods is called with the following parmeters:
3858  * <self> <domain>
3859  * The parameters of the connection change handler are defined in
3860  * the domain->add_connect_change_handler method.
3861  * The third and fourth parameters are optional, if not provided
3862  * or undefined the handler will be ignored.
3863  *
3864  * The format of the arguments is the same as described in the
3865  * ipmi_cmdlang.7 man page for domain open, except the -wait_til_up
3866  * option is not supported.  See that for more details.  These options
3867  * allow you to turn on and off various automatic operations that
3868  * OpenIPMI does, such as scanning SDRs, fetching the SEL, etc.
3869  */
3870 ipmi_domain_id_t *open_domain(char *name, argarray *args,
3871 			      swig_cb *done = NULL, swig_cb *up = NULL);
3872 
3873 /*
3874  * Like open_domain, but takes the new parameter types and is more
3875  * flexible.  This is required for RMCP+.
3876  */
3877 ipmi_domain_id_t *open_domain2(char *name, argarray *args,
3878 			       swig_cb *done = NULL, swig_cb *up = NULL);
3879 
3880 /*
3881  * Like open_domain2, but takes ipmi_args_t.  Works with RMCP+.
3882  */
3883 ipmi_domain_id_t *open_domain3(char *name, argarray *options,
3884 			       iargarray *args,
3885 			       swig_cb *done = NULL, swig_cb *up = NULL);
3886 
3887 /*
3888  * Iterate through the help for the various connection types used with
3889  * open_domain2() and open_domain3() and argument parsing and
3890  * allocating.  This will call the parse_args_iter_help_cb method on
3891  * the supplied object for each registered connection type.  The
3892  * parameters are <self> <name> <help>.  This can also be used to find
3893  * the names of all registered connections.
3894  */
3895 void parse_args_iter_help(swig_cb *help_cb);
3896 %{
parse_args_iter_help(swig_cb * help_cb)3897     static void parse_args_iter_help(swig_cb *help_cb)
3898     {
3899 	int         rv;
3900 	swig_cb_val *handler_val;
3901 
3902 	IPMI_SWIG_C_CB_ENTRY
3903 	if (! valid_swig_cb(help_cb, parse_args_iter_help_cb))
3904 	    rv = EINVAL;
3905 	else {
3906 	    handler_val = get_swig_cb(help_cb, parse_args_iter_help_cb);
3907 	    ipmi_parse_args_iter_help(parse_args_iter_help_hnd, handler_val);
3908 	}
3909 	IPMI_SWIG_C_CB_EXIT
3910     }
3911 %}
3912 
3913 const char *parse_option_help();
3914 %{
parse_option_help(void)3915     static const char *parse_option_help(void)
3916     {
3917 	return ipmi_parse_options_help();
3918     }
3919 %}
3920 
3921 /*
3922  * Add a handler whose domain_change_cb method will be called whenever
3923  * a domain is added or removed.  The handler will be called with the
3924  * following parameters: <self> added|deleted|changed <domain>
3925  */
3926 int add_domain_change_handler(swig_cb *handler);
3927 
3928 /*
3929  * Remove a previously registered domain handler.
3930  */
3931 int
3932 remove_domain_change_handler(swig_cb *handler);
3933 
3934 /*
3935  * Set the handler for OpenIPMI logs.  This is a global value and
3936  * there is only one, setting it replaces the old one.  The logs will
3937  * be sent to the "log" method of the first parameter.  The log method
3938  * will receive the following parameters: <self>, <log_level (a
3939  * string)>, and <log (a string)>.  If the log method is undefined or
3940  * not provided, the current log handler will be removed.
3941  */
3942 void set_log_handler(swig_cb *handler = NULL);
3943 
3944 
3945 /*
3946  * Convert the given color to a string.
3947  */
3948 char *color_string(int color);
3949 
3950 /* Convert between lanparm string names and parm numbers. */
3951 char *lanparm_parm_to_str(int parm);
3952 int lanparm_str_to_parm(char *str);
3953 
3954 /* Used to discover enum values for lanparms. */
3955 int lanconfig_enum_val(int parm, int val, int *nval, const char **sval);
3956 int lanconfig_enum_idx(int parm, int idx, const char **sval);
3957 
3958 /* Convert between pef string names and parm numbers. */
3959 char *pef_parm_to_str(int parm);
3960 int pef_str_to_parm(char *str);
3961 
3962 /* Used to discover enum values for lanparms. */
3963 int pefconfig_enum_val(int parm, int val, int *nval, const char **sval);
3964 int pefconfig_enum_idx(int parm, int idx, const char **sval);
3965 
3966 /* Convert between SoL string names and parm numbers. */
3967 char *solparm_parm_to_str(int parm);
3968 int solparm_str_to_parm(char *str);
3969 
3970 /* Used to discover enum values for solparms. */
3971 int solconfig_enum_val(int parm, int val, int *nval, const char **sval);
3972 int solconfig_enum_idx(int parm, int idx, const char **sval);
3973 
3974 /* Convert various sensor values to strings. */
3975 char *get_threshold_access_support_string(int val);
3976 char *get_hysteresis_support_string(int val);
3977 char *get_event_support_string(int val);
3978 
3979 /* Convert various channel/mc values to strings. */
3980 char *channel_medium_string(int val);
3981 char *channel_protocol_string(int val);
3982 char *channel_session_support_string(int val);
3983 char *channel_access_mode_string(int val);
3984 char *privilege_string(int val);
3985 char *authtype_string(int val);
3986 
3987 %newobject get_error_string;
3988 char *get_error_string(unsigned int val);
3989 
3990 %constant long long TIMEOUT_FOREVER = IPMI_TIMEOUT_FOREVER;
3991 
3992 /*
3993  * A domain id object.  This object is guaranteed to be valid and
3994  * can be converted into a domain pointer later.
3995  */
3996 %extend ipmi_domain_id_t {
~ipmi_domain_id_t()3997     ~ipmi_domain_id_t()
3998     {
3999 	free(self);
4000     }
4001 
4002     /* Compare self with other, return -1 if self<other, 0 if
4003        self==other, or 1 if self>other.  */
cmp(ipmi_domain_id_t * other)4004     int cmp(ipmi_domain_id_t *other)
4005     {
4006 	return ipmi_cmp_domain_id(*self, *other);
4007     }
4008 
4009     /*
4010      * Convert a domain id to a domain pointer.  The "domain_cb" method
4011      * will be called on the first parameter with the following parameters:
4012      * <self> <domain>
4013      */
to_domain(swig_cb * handler)4014     int to_domain(swig_cb *handler)
4015     {
4016 	int rv;
4017 	IPMI_SWIG_C_CB_ENTRY
4018 	if (! valid_swig_cb(handler, domain_cb))
4019 	    rv = EINVAL;
4020 	else
4021 	    rv = ipmi_domain_pointer_cb(*self, handle_domain_cb,
4022 					get_swig_cb(handler, domain_cb));
4023 	IPMI_SWIG_C_CB_EXIT
4024 	return rv;
4025     }
4026 }
4027 
4028 /*
4029  * A domain object.
4030  */
4031 %extend ipmi_domain_t {
4032     %newobject get_name;
4033     /*
4034      * Get the name of the domain.
4035      */
get_name()4036     char *get_name()
4037     {
4038 	char name[IPMI_DOMAIN_NAME_LEN];
4039 
4040 	ipmi_domain_get_name(self, name, sizeof(name));
4041 	return strdup(name);
4042     }
4043 
4044     %newobject get_id;
4045     /*
4046      * Get the ID of the domain so you can hold on to the reference.
4047      */
get_id()4048     ipmi_domain_id_t *get_id()
4049     {
4050 	ipmi_domain_id_t *rv = malloc(sizeof(*rv));
4051 	if (rv)
4052 	    *rv = ipmi_domain_convert_to_id(self);
4053 	return rv;
4054     }
4055 
4056     %newobject get_guid;
4057     /*
4058      * Get the system GUID for the domain.  Returns NULL if it is not
4059      * supported.
4060      */
get_guid()4061     char *get_guid()
4062     {
4063 	char          *str = NULL;
4064 	unsigned char guid[16];
4065 
4066 	if (ipmi_domain_get_guid(self, guid) == 0) {
4067 	    str = malloc(16 * 3);
4068 	    if (str) {
4069 		char *s = str;
4070 		int  i;
4071 		s += sprintf(s, "%2.2x", guid[0]);
4072 		for (i=1; i<16; i++)
4073 		    s += sprintf(s, " %2.2x", guid[i]);
4074 	    }
4075 	}
4076 	return str;
4077     }
4078 
4079     /*
4080      * Shut down the connections to the domain and free it up.  The
4081      * domain_close_done_cb method for the handler object will be
4082      * called with the following parameters: <self>
4083      */
close(swig_cb * handler)4084     int close(swig_cb *handler)
4085     {
4086 	int         rv;
4087 	swig_cb_val *handler_val;
4088 
4089 	IPMI_SWIG_C_CB_ENTRY
4090 	if (! valid_swig_cb(handler, domain_close_done_cb))
4091 	    rv = EINVAL;
4092 	else {
4093 	    handler_val = ref_swig_cb(handler, domain_close_done_cb);
4094 	    rv = ipmi_domain_close(self, domain_close_done, handler_val);
4095 	    if (rv)
4096 		deref_swig_cb_val(handler_val);
4097 	}
4098 	IPMI_SWIG_C_CB_EXIT
4099 	return rv;
4100     }
4101 
4102     /*
4103      * Add a handler to be called when the connection changes status.
4104      * The conn_change_cb method on the first parameter will be
4105      * called when the connection changes status with the following
4106      * parameters: <self>, <domain>, <errorval>, <connection_number>,
4107      * <port_number>, <anything_still_connected>.
4108      */
add_connect_change_handler(swig_cb * handler)4109     int add_connect_change_handler(swig_cb *handler)
4110     {
4111 	/* cleanup handler is added when the domain is added. */
4112 	cb_add(domain, connect_change, conn_change_cb);
4113     }
4114 
4115     /*
4116      * Remove the connection change handler.
4117      */
remove_connect_change_handler(swig_cb * handler)4118     int remove_connect_change_handler(swig_cb *handler)
4119     {
4120 	cb_rm(domain, connect_change, conn_change_cb);
4121     }
4122 
4123     /*
4124      * Iterate through all the connections in the object.  The
4125      * domain_iter_connection_cb method will be called on the first
4126      * parameter for each connection in the domain.  The parameters it
4127      * receives will be: <self>, <domain>, <connection (integer)>.
4128      */
iterate_connections(swig_cb * handler)4129     int iterate_connections(swig_cb *handler)
4130     {
4131 	swig_cb_val *handler_val;
4132 	int         rv = 0;
4133 
4134 	IPMI_SWIG_C_CB_ENTRY
4135 	if (! valid_swig_cb(handler, domain_iter_connection_cb))
4136 	    rv = EINVAL;
4137 	else {
4138 	    handler_val = get_swig_cb(handler, domain_iter_connection_cb);
4139 	    ipmi_domain_iterate_connections(self,
4140 					    domain_iterate_connections_handler,
4141 					    handler_val);
4142 	}
4143 	IPMI_SWIG_C_CB_EXIT
4144 	return rv;
4145     }
4146 
4147     /*
4148      * Attempt to activate the given connection.
4149      */
activate_connection(int connection)4150     int activate_connection(int connection)
4151     {
4152 	int rv;
4153 	IPMI_SWIG_C_CB_ENTRY
4154 	rv = ipmi_domain_activate_connection(self, connection);
4155 	IPMI_SWIG_C_CB_EXIT
4156 	return rv;
4157     }
4158 
4159     /*
4160      * Parm 1 is a connection number.  Sets the second parameter to
4161      * true if the connection is active, false if not.  Returns an
4162      * error value.
4163      */
is_connection_active(int connection,unsigned int * active)4164     int is_connection_active(int connection, unsigned int *active)
4165     {
4166 	return ipmi_domain_is_connection_active(self, connection, active);
4167     }
4168 
4169     /*
4170      * Parm 1 is a connection number.  Sets the second parameter to true
4171      * if the connection is up, false if not.  Returns an error value.
4172      */
is_connection_up(int connection,unsigned int * up)4173     int is_connection_up(int connection, unsigned int *up)
4174     {
4175 	return ipmi_domain_is_connection_up(self, connection, up);
4176     }
4177 
4178     /*
4179      * Parm 1 is a connection number.  Sets the second parameter to
4180      * the number of ports in the connection.  A connection may have
4181      * multiple ports (ie, multiple IP addresses to the same BMC,
4182      * whereas a separate connection is a connection to a different
4183      * BMC); these functions let you check their status.  Returns an
4184      * error value.
4185      */
num_connection_ports(int connection,unsigned int * ports)4186     int num_connection_ports(int connection, unsigned int *ports)
4187     {
4188 	return ipmi_domain_num_connection_ports(self, connection, ports);
4189     }
4190 
4191     /*
4192      * Parm 1 is a connection number, parm 2 is a port number.  Sets
4193      * parm 3 to true if the given port is up, false if not.  Returns
4194      * an error value.
4195      */
is_connection_port_up(int connection,int port,unsigned int * up)4196     int is_connection_port_up(int          connection,
4197 			      int          port,
4198 			      unsigned int *up)
4199     {
4200 	return ipmi_domain_is_connection_port_up(self, connection, port, up);
4201     }
4202 
4203     %newobject get_port_info;
get_port_info(int connection,int port)4204     char *get_port_info(int connection, int port)
4205     {
4206 	int rv;
4207 	char buf[256];
4208 	int  len = sizeof(buf);
4209 	rv = ipmi_domain_get_port_info(self, connection, port, buf, &len);
4210 	if (rv)
4211 	    return NULL;
4212 	return strdup(buf);
4213     }
4214 
4215     %newobject get_connection_args;
get_connection_args(int connection)4216     ipmi_args_t *get_connection_args(int connection)
4217     {
4218 	return ipmi_domain_get_connection_args(self, connection);
4219     }
4220 
get_connection_type(int connection)4221     char *get_connection_type(int connection)
4222     {
4223 	return ipmi_domain_get_connection_type(self, connection);
4224     }
4225 
4226     /*
4227      * Add a handler to be called when an entity is added, updated, or
4228      * removed. When the entity is updated the entity_update_cb
4229      * method on the first parameter will be called with the following
4230      * parameters: <self>, added|deleted|changed <domain>, <entity>.
4231      */
add_entity_update_handler(swig_cb * handler)4232     int add_entity_update_handler(swig_cb *handler)
4233     {
4234 	ipmi_domain_add_entity_update_handler_cl
4235 	    (self, domain_entity_update_handler_cl, NULL);
4236 	cb_add(domain, entity_update, entity_update_cb);
4237     }
4238 
4239     /*
4240      * Remove the entity change handler.
4241      */
remove_entity_update_handler(swig_cb * handler)4242     int remove_entity_update_handler(swig_cb *handler)
4243     {
4244 	cb_rm(domain, entity_update, entity_update_cb);
4245     }
4246 
4247     /*
4248      * Iterate through all the entities in the object.  The
4249      * domain_iter_entities_cb method will be called on the first
4250      * parameter for each entity in the domain.  The parameters it
4251      * receives will be: <self> <domain> <entity>.
4252      */
iterate_entities(swig_cb * handler)4253     int iterate_entities(swig_cb *handler)
4254     {
4255 	swig_cb_val *handler_val;
4256 	int         rv = 0;
4257 
4258 	IPMI_SWIG_C_CB_ENTRY
4259 	if (! valid_swig_cb(handler, domain_iter_entities_cb))
4260 	    rv = EINVAL;
4261 	else {
4262 	    handler_val = get_swig_cb(handler, domain_iter_entities_cb);
4263 	    ipmi_domain_iterate_entities(self, domain_iterate_entities_handler,
4264 					 handler_val);
4265 	}
4266 	IPMI_SWIG_C_CB_EXIT
4267 	return rv;
4268     }
4269 
4270     /*
4271      * Add a handler to be called when an MC is added, updated, or
4272      * removed. When the mc is updated the mc_update_cb method on the
4273      * first parameter will be called with the following parameters:
4274      * <self>, added|deleted|changed <domain>, <mc>.
4275      */
add_mc_update_handler(swig_cb * handler)4276     int add_mc_update_handler(swig_cb *handler)
4277     {
4278 	ipmi_domain_add_mc_updated_handler_cl
4279 	    (self, domain_mc_updated_handler_cl, NULL);
4280 	cb_add(domain, mc_updated, mc_update_cb);
4281     }
4282 
4283     /*
4284      * Remove the mc change handler.
4285      */
remove_mc_update_handler(swig_cb * handler)4286     int remove_mc_update_handler(swig_cb *handler)
4287     {
4288 	cb_rm(domain, mc_updated, mc_update_cb);
4289     }
4290 
4291     /*
4292      * Iterate through all the MCs in the object.  The
4293      * domain_iter_mc_cb method will be called on the first parameter for
4294      * each mc in the domain.  The parameters it receives will be:
4295      * <self> <domain> <mc>.
4296      */
iterate_mcs(swig_cb * handler)4297     int iterate_mcs(swig_cb *handler)
4298     {
4299 	swig_cb_val *handler_val;
4300 	int         rv = 0;
4301 
4302 	IPMI_SWIG_C_CB_ENTRY
4303 	if (! valid_swig_cb(handler, domain_iter_mc_cb))
4304 	    rv = EINVAL;
4305 	else {
4306 	    handler_val = get_swig_cb(handler, domain_iter_mc_cb);
4307 	    ipmi_domain_iterate_mcs(self, domain_iterate_mcs_handler,
4308 				    handler_val);
4309 	}
4310 	IPMI_SWIG_C_CB_EXIT
4311 	return rv;
4312     }
4313 
4314     /*
4315      * Return the type of the domain, either unknown, mxp, or atca.
4316      * Others may be added later.
4317      */
get_type()4318     const char *get_type()
4319     {
4320 	return ipmi_domain_get_type_string(ipmi_domain_get_type(self));
4321     }
4322 
4323     /*
4324      * Scan all the addresses on the given channel (parm 1) between
4325      * (and including) start_addr (parm 2) and end_addr (parm 3) and
4326      * call the "domain_ipmb_mc_scan_cb" method on the handler (parm4)
4327      * with the following parms (if the parm is provided and defined):
4328      * <self>, <domain>, <error val>
4329      */
4330     int start_ipmb_mc_scan(int channel, int start_addr, int end_addr,
4331 			   swig_cb *handler = NULL)
4332     {
4333 	int            rv;
4334 	swig_cb_val    *handler_val = NULL;
4335 	ipmi_domain_cb domain_cb = NULL;
4336 
4337 	IPMI_SWIG_C_CB_ENTRY
4338 	if (!nil_swig_cb(handler)) {
4339 	    if (!valid_swig_cb(handler, domain_ipmb_mc_scan_cb)) {
4340 		rv = EINVAL;
4341 		goto out_err;
4342 	    }
4343 	    domain_cb = ipmb_mc_scan_handler;
4344 	    handler_val = ref_swig_cb(handler, domain_ipmb_mc_scan_cb);
4345 	}
4346 	rv = ipmi_start_ipmb_mc_scan(self, channel, start_addr, end_addr,
4347 				     domain_cb, handler_val);
4348 	if (rv && handler_val)
4349 	    deref_swig_cb_val(handler_val);
4350     out_err:
4351 	IPMI_SWIG_C_CB_EXIT
4352 	return rv;
4353     }
4354 
4355     /* Scan all IPMB busses for new/lost MCs. */
start_full_ipmb_scan()4356     void start_full_ipmb_scan()
4357     {
4358 	ipmi_domain_start_full_ipmb_scan(self);
4359     }
4360 
4361     /*
4362      * Send a command to a given address (parm 1) with the given lun
4363      * (parm 2), netfn (parm 3), command (parm 4).  Parm 5 is the
4364      * message data in an array reference.  Parm 6 is the handler, it
4365      * will be called with the response.  The addr_cmd_cb method will
4366      * be called on the handler handler if it is provided and defined;
4367      * its parameters are: <domain> <addr> <lun> <netfn> <cmd>
4368      * <response data>
4369      */
4370     int send_command_addr(char *addr, int lun, int netfn, int cmd,
4371 			  intarray msg_data, swig_cb *handler = NULL)
4372     {
4373 	int                          rv;
4374 	swig_cb_val                  *handler_val = NULL;
4375 	ipmi_addr_response_handler_t msg_cb = NULL;
4376 	ipmi_addr_t                  iaddr;
4377 	unsigned int                 addr_len;
4378 	ipmi_msg_t                   msg;
4379 	unsigned char                data[MAX_IPMI_DATA_SIZE];
4380 	unsigned int                 data_len;
4381 
4382 	IPMI_SWIG_C_CB_ENTRY
4383 	rv = parse_ipmi_addr(addr, lun, &iaddr, &addr_len);
4384 	if (rv)
4385 	    goto out_err;
4386 
4387 	msg.netfn = netfn;
4388 	msg.cmd = cmd;
4389 	msg.data = data;
4390 	rv = parse_ipmi_data(msg_data, data, sizeof(data), &data_len);
4391 	msg.data_len = data_len;
4392 	if (rv)
4393 	    goto out_err;
4394 
4395 	if (!nil_swig_cb(handler)) {
4396 	    if (!valid_swig_cb(handler, addr_cmd_cb)) {
4397 		rv = EINVAL;
4398 		goto out_err;
4399 	    }
4400 	    msg_cb = domain_msg_cb;
4401 	    handler_val = ref_swig_cb(handler, addr_cmd_cb);
4402 	}
4403 	rv = ipmi_send_command_addr(self, &iaddr, addr_len, &msg,
4404 				    msg_cb, handler_val, NULL);
4405 	if (rv && handler_val)
4406 	    deref_swig_cb_val(handler_val);
4407     out_err:
4408 	IPMI_SWIG_C_CB_EXIT
4409 	return rv;
4410     }
4411 
4412     /*
4413      * Cause the domain to start detecting presence changes.  If parm
4414      * 1 is supplied, it tells whether to force all entities to have
4415      * their presence checked (if true) or just detect entity presence
4416      * for ones that might have changed.
4417      */
4418     int detect_presence_changes(int force = 0)
4419     {
4420 	return ipmi_detect_domain_presence_changes(self, force);
4421     }
4422 
4423     /*
4424      * Set the time (in seconds) between SEL rescans for all
4425      * SELs in the domain
4426      */
set_sel_rescan_time(int seconds)4427     void set_sel_rescan_time(int seconds)
4428     {
4429 	return ipmi_domain_set_sel_rescan_time(self, seconds);
4430     }
4431 
4432     /*
4433      * Get the default SEL rescan time for the domain.
4434      */
get_sel_rescan_time()4435     int get_sel_rescan_time()
4436     {
4437 	return ipmi_domain_get_sel_rescan_time(self);
4438     }
4439 
4440     /*
4441      * Set the time (in seconds) between IPMB bus rescans for the
4442      * domain.
4443      */
set_ipmb_rescan_time(int seconds)4444     void set_ipmb_rescan_time(int seconds)
4445     {
4446 	return ipmi_domain_set_ipmb_rescan_time(self, seconds);
4447     }
4448 
4449     /*
4450      * Get the default IPMB rescan time for the domain.
4451      */
get_ipmb_rescan_time()4452     int get_ipmb_rescan_time()
4453     {
4454 	return ipmi_domain_get_ipmb_rescan_time(self);
4455     }
4456 
4457     /*
4458      * Add a handler to be called when a new unhandled event comes
4459      * into the domain.  When the event comes in, the event_cb method
4460      * on the first parameter will be called with the following
4461      * parameters: <self>, <domain>, <event>
4462      */
add_event_handler(swig_cb * handler)4463     int add_event_handler(swig_cb *handler)
4464     {
4465 	ipmi_domain_add_event_handler_cl
4466 	    (self, domain_event_handler_cl, NULL);
4467 	cb_add(domain, event, event_cb);
4468     }
4469 
4470     /*
4471      * Remove the event handler.
4472      */
remove_event_handler(swig_cb * handler)4473     int remove_event_handler(swig_cb *handler)
4474     {
4475 	cb_rm(domain, event, event_cb);
4476     }
4477 
4478     %newobject first_event;
4479     /*
4480      * Retrieve the first event from the domain.  Return NULL (undef)
4481      * if the event does not exist.
4482      */
first_event()4483     ipmi_event_t *first_event()
4484     {
4485 	return ipmi_domain_first_event(self);
4486     }
4487 
4488     %newobject last_event;
4489     /*
4490      * Retrieve the last event from the domain.
4491      */
last_event()4492     ipmi_event_t *last_event()
4493     {
4494 	return ipmi_domain_last_event(self);
4495     }
4496 
4497     %newobject next_event;
4498     /*
4499      * Retrieve the event after the given event from the domain.
4500      */
next_event(ipmi_event_t * event)4501     ipmi_event_t *next_event(ipmi_event_t  *event)
4502     {
4503 	return ipmi_domain_next_event(self, event);
4504     }
4505 
4506     %newobject prev_event;
4507     /*
4508      * Retrieve the event before the given event from the domain.
4509      */
prev_event(ipmi_event_t * event)4510     ipmi_event_t *prev_event(ipmi_event_t  *event)
4511     {
4512 	return ipmi_domain_prev_event(self, event);
4513     }
4514 
4515     /*
4516      * Number of live entries in the local SEL copy.
4517      */
sel_count()4518     int sel_count()
4519     {
4520 	int          rv;
4521 	unsigned int count;
4522 	rv = ipmi_domain_sel_count(self, &count);
4523 	if (rv)
4524 	    return 0;
4525 	else
4526 	    return count;
4527     }
4528 
4529     /*
4530      * Number of entries in the the remote SEL.  If an entry has been
4531      * deleted in the local copy of the SEL but has not yet finished
4532      * being deleted in the remote copy, it will be counted here.
4533      */
sel_entries_used()4534     int sel_entries_used()
4535     {
4536 	int          rv;
4537 	unsigned int count;
4538 	rv = ipmi_domain_sel_entries_used(self, &count);
4539 	if (rv)
4540 	    return 0;
4541 	else
4542 	    return count;
4543     }
4544 
4545     /*
4546      * Reread all SELs in the domain.  The domain_reread_sels_cb
4547      * method on the first parameter (if supplied) will be called with
4548      * the following values: <domain> <error value>
4549      */
4550     int reread_sels(swig_cb *handler = NULL)
4551     {
4552 	int            rv;
4553 	swig_cb_val    *handler_val = NULL;
4554 	ipmi_domain_cb domain_cb = NULL;
4555 
4556 	IPMI_SWIG_C_CB_ENTRY
4557 	if (!nil_swig_cb(handler)) {
4558 	    if (!valid_swig_cb(handler, domain_reread_sels_cb)) {
4559 		rv = EINVAL;
4560 		goto out_err;
4561 	    }
4562 	    domain_cb = domain_reread_sels_handler;
4563 	    handler_val = ref_swig_cb(handler, domain_reread_sels_cb);
4564 	}
4565 	rv = ipmi_domain_reread_sels(self, domain_cb, handler_val);
4566 	if (rv && handler_val)
4567 	    deref_swig_cb_val(handler_val);
4568     out_err:
4569 	IPMI_SWIG_C_CB_EXIT
4570 	return rv;
4571     }
4572 
4573     /*
4574      * Fetch a FRU with the given parameters.  The first parameter (the object)
4575      * is the domain, successive parameters are:
4576      *  is_logical - do a logical or physical FRU fetch.
4577      *  device_address - The IPMB address of the FRU device.
4578      *  device_id - The particular FRU device id to fetch.
4579      *  LUN - The LUN to talk to for the device.
4580      *  private_bus - for physical FRUs, the bus it is on.
4581      *  channel - The channel where the device is located.
4582      * If the handler is supplied, then the fru_fetched method on that
4583      * will be called upon completion with the handler object as the first
4584      * parameter, the domain as the second, the FRU as the third, and an
4585      * error value as the fourth.
4586      * This returns the FRU, or undefined if a failure occurred.
4587      */
4588     %newobject fru_alloc;
4589     ipmi_fru_t *fru_alloc(int is_logical, int device_address, int device_id,
4590 			  int lun, int private_bus, int channel,
4591 			  swig_cb *handler = NULL)
4592     {
4593 	ipmi_fru_t *fru = NULL;
4594 	int         rv;
4595 	swig_cb_val *handler_val = NULL;
4596 	ipmi_fru_cb cb_handler = NULL;
4597 
4598 	IPMI_SWIG_C_CB_ENTRY
4599 	if (!nil_swig_cb(handler)) {
4600 	    if (!valid_swig_cb(handler, fru_fetched))
4601 		goto out_err;
4602 	    cb_handler = fru_fetched;
4603 	    handler_val = ref_swig_cb(handler, fru_fetched);
4604 	}
4605 
4606 	rv = ipmi_domain_fru_alloc(self, is_logical, device_address, device_id,
4607 				   lun, private_bus, channel, cb_handler,
4608 				   handler_val, &fru);
4609 	if (rv) {
4610 	    if (handler_val)
4611 		deref_swig_cb_val(handler_val);
4612 	    fru = NULL;
4613 	} else {
4614 	    /* We have one ref for the callback already, add a ref for
4615 	       the returned value. */
4616 	    if (handler_val)
4617 		ipmi_fru_ref(fru);
4618 	}
4619 
4620     out_err:
4621 	IPMI_SWIG_C_CB_EXIT
4622 	return fru;
4623     }
4624 
4625     /*
4626      * Allocate a pet object for the domain over the given connection.
4627      * The pet is returned.  The ninth parameter is an optional
4628      * callback object, the got_pet_cb method will be called on it
4629      * when the PET fetch is complete.  It will have the following
4630      * parameters: <self> <pet> <err>.  The parameters are:
4631      *   int connection: the connection to the domain to set up the PET for
4632      *   int channel: the channel number to set the PET for
4633      *   char ip_addr: the address to send the traps to
4634      *   char mac_addr: the mac address to send the traps to
4635      * The rest are the selectors in the various tables, you have to
4636      * read the spec and know your system to know how to set them.
4637      *   int eft_sel:
4638      *   int policy_num:
4639      *   int apt_sel:
4640      *   int lan_dest_sel:
4641      *
4642      * Note that you must keep a reference to the pet around, or it will
4643      * be automatically destroyed by the garbage collector.
4644      */
4645     %newobject get_pet;
4646     ipmi_pet_t *get_pet(int     connection,
4647 			int     channel,
4648 			char    *ip_addr,
4649 			char    *mac_addr,
4650 			int     eft_sel,
4651 			int     policy_num,
4652 			int     apt_sel,
4653 			int     lan_dest_sel,
4654 			swig_cb *handler = NULL)
4655     {
4656 	int              rv;
4657 	ipmi_pet_t       *pet = NULL;
4658 	swig_cb_val      *handler_val = NULL;
4659 	struct in_addr   ip;
4660 	unsigned char    mac[6];
4661 	ipmi_pet_done_cb done = NULL;
4662 
4663 	IPMI_SWIG_C_CB_ENTRY
4664         rv = parse_ip_addr(ip_addr, &ip);
4665 	if (rv)
4666 	    goto out_err;
4667 
4668         rv = parse_mac_addr(mac_addr, mac);
4669 	if (rv)
4670 	    goto out_err;
4671 
4672 	if (!nil_swig_cb(handler)) {
4673 	    if (!valid_swig_cb(handler, got_pet_cb))
4674 		goto out_err;
4675 	    handler_val = ref_swig_cb(handler, got_pet_cb);
4676 	    done = get_pet;
4677 	}
4678 	rv = ipmi_pet_create(self, connection, channel, ip, mac, eft_sel,
4679 			     policy_num, apt_sel, lan_dest_sel, get_pet,
4680 			     handler_val, &pet);
4681 	if (rv && handler_val)
4682 	    deref_swig_cb_val(handler_val);
4683     out_err:
4684 	IPMI_SWIG_C_CB_EXIT
4685 	return pet;
4686     }
4687 
4688     /*
4689      * Allocate a SoL object using the given domain's connection.
4690      * Note that this does not cause a connection, it just creates an
4691      * object for doing an SoL connection.
4692      *
4693      * The handler val will handle all events from the SOL session.
4694      * this means it must implement the following callbacks:
4695      *
4696      *  sol_connection_state_change <self> <conn> <state> <error>
4697      *  sol_data_received <self> <conn> <string>
4698      *  sol_break_detected <self> <conn>
4699      *  sol_bmc_transmit_overrun <self> <conn>
4700      */
4701     %newobject create_sol;
create_sol(int connection,swig_cb * handler)4702     ipmi_sol_conn_t *create_sol(int connection, swig_cb *handler)
4703     {
4704 	ipmi_con_t      *con;
4705 	ipmi_sol_conn_t *scon;
4706 	int             rv;
4707 	swig_cb_val     *handler_val;
4708 
4709 	if (nil_swig_cb(handler))
4710 	    return NULL;
4711 
4712 	if (!valid_swig_cb(handler, sol_connection_state_change))
4713 	    return NULL;
4714 	if (!valid_swig_cb(handler, sol_data_received))
4715 	    return NULL;
4716 	if (!valid_swig_cb(handler, sol_break_detected))
4717 	    return NULL;
4718 	if (!valid_swig_cb(handler, sol_bmc_transmit_overrun))
4719 	    return NULL;
4720 
4721 	con = ipmi_domain_get_connection(self, connection);
4722 	if (!con)
4723 	    return NULL;
4724 
4725 	rv = ipmi_sol_create(con, &scon);
4726 	if (rv) {
4727 	    con->close_connection(con);
4728 	    return NULL;
4729 	}
4730 
4731 	handler_val = ref_swig_gencb(handler);
4732 
4733 	rv = ipmi_sol_register_connection_state_callback
4734 	    (scon,
4735 	     sol_connection_state_change_cb,
4736 	     handler_val);
4737 	if (rv)
4738 	    goto out_err;
4739 
4740 	rv = ipmi_sol_register_data_received_callback
4741 	    (scon,
4742 	     sol_data_received_cb,
4743 	     handler_val);
4744 	if (rv)
4745 	    goto out_err;
4746 
4747 	rv = ipmi_sol_register_break_detected_callback
4748 	    (scon,
4749 	     sol_break_detected_cb,
4750 	     handler_val);
4751 	if (rv)
4752 	    goto out_err;
4753 
4754 	rv = ipmi_sol_register_bmc_transmit_overrun_callback
4755 	    (scon,
4756 	     sol_bmc_transmit_overrun_cb,
4757 	     handler_val);
4758 	if (rv)
4759 	    goto out_err;
4760 
4761 	return scon;
4762 
4763     out_err:
4764 	deref_swig_cb_val(handler_val);
4765 	ipmi_sol_free(scon);
4766 	return NULL;
4767     }
4768 }
4769 
4770 /*
4771  * Allocate an args structure of the given connection type, generally
4772  * "smi" or Lan".
4773  */
4774 %newobject alloc_empty_args;
4775 ipmi_args_t *alloc_empty_args(char *con_type);
4776 %{
4777     static ipmi_args_t *
alloc_empty_args(char * con_type)4778     alloc_empty_args(char *con_type)
4779     {
4780 	int         rv;
4781 	ipmi_args_t *argv;
4782 	rv = ipmi_args_alloc(con_type, &argv);
4783 	if (rv)
4784 	    return NULL;
4785 	return argv;
4786     }
4787 %}
4788 
4789 /*
4790  * Parse the array of arguments.  The arguments is a list/array of
4791  * strings and parsed using the standard algorithms.
4792  */
4793 %newobject alloc_parse_args;
4794 ipmi_args_t *alloc_parse_args(argarray *args);
4795 %{
4796     static ipmi_args_t *
alloc_parse_args(argarray * args)4797     alloc_parse_args(argarray *args)
4798     {
4799 	int         rv;
4800 	ipmi_args_t *argv;
4801 	int         i = 0;
4802 
4803 	rv = ipmi_parse_args(&i, args->len, args->val, &argv);
4804 	if (rv)
4805 	    return NULL;
4806 	return argv;
4807     }
4808 %}
4809 
4810 %extend ipmi_args_t {
~ipmi_args_t()4811     ~ipmi_args_t()
4812     {
4813 	ipmi_free_args(self);
4814     }
4815 
4816     /*
4817      * Return the type of connection, generally "lan" or "smi".
4818      */
get_type()4819     const char *get_type()
4820     {
4821 	return ipmi_args_get_type(self);
4822     }
4823 
4824     /*
4825      * An args is a set of fields indexed by argnum.  Fetching an
4826      * argument returns the name, type, help string, and value.  E2BIG
4827      * is returned if argnum is larger than the number of fields.
4828      * Type will be either "str" for a string or integer or IP address
4829      * or other field like that, "bool" for a boolean, and "enum" for
4830      * an enumeration type.  The "str" type, obviously, may have
4831      * semantics behind it.  The "bool" value will be either "true" or
4832      * "false".  For enums, an array of strings is returned as "range"
4833      * and the value will be one of these strings.
4834      */
get_val(int argnum,const char ** name,const char ** type,const char ** help,char ** value,strconstarray * range)4835     int get_val(int           argnum,
4836 		const char    **name,
4837 		const char    **type,
4838 		const char    **help,
4839 		char          **value,
4840 		strconstarray *range)
4841     {
4842 	int        rv;
4843 	const char **irange = NULL;
4844 	char       *ivalue = NULL;
4845 
4846 	rv = ipmi_args_get_val(self, argnum, name, type, help,
4847 			       &ivalue, &irange);
4848 	if (rv)
4849 	    return rv;
4850 	if (ivalue) {
4851 	    /* Convert it to a normal malloc() so char ** will work. */
4852 	    char *ivalue2 = strdup(ivalue);
4853 	    ipmi_args_free_str(self, ivalue);
4854 	    ivalue = ivalue2;
4855 	}
4856 	*value = ivalue;
4857 	if (irange) {
4858 	    int len;
4859 	    for (len=0; irange[len]; len++)
4860 		;
4861 	    range->len = len;
4862 	    range->val = irange;
4863 	}
4864 	return 0;
4865     }
4866 
4867     /*
4868      * Set the given field.  If name is not NULL, then find the field
4869      * by name.  If name is NULL, then argnum is used for the field.
4870      * If the value does not match the semantics of the field, an
4871      * error is returned.
4872      */
set_val(int argnum,const char * name,const char * value)4873     int set_val(int argnum, const char *name, const char *value)
4874     {
4875 	return ipmi_args_set_val(self, argnum, name, value);
4876     }
4877 }
4878 
4879 /*
4880  * A entity id object.  This object is guaranteed to be valid and
4881  * can be converted into a entity pointer later.
4882  */
4883 %extend ipmi_entity_id_t {
~ipmi_entity_id_t()4884     ~ipmi_entity_id_t()
4885     {
4886 	free(self);
4887     }
4888 
4889     /* Compare self with other, return -1 if self<other, 0 if
4890        self==other, or 1 if self>other.  */
cmp(ipmi_entity_id_t * other)4891     int cmp(ipmi_entity_id_t *other)
4892     {
4893 	return ipmi_cmp_entity_id(*self, *other);
4894     }
4895 
4896     /*
4897      * Convert a entity id to a entity pointer.  The "entity_cb" method
4898      * will be called on the first parameter with the following parameters:
4899      * <self> <entity>
4900      */
to_entity(swig_cb * handler)4901     int to_entity(swig_cb *handler)
4902     {
4903 	int rv;
4904 
4905 	IPMI_SWIG_C_CB_ENTRY
4906 	if (! valid_swig_cb(handler, entity_cb))
4907 	    rv = EINVAL;
4908 	else
4909 	    rv = ipmi_entity_pointer_cb(*self, handle_entity_cb,
4910 					get_swig_cb(handler, entity_cb));
4911 	IPMI_SWIG_C_CB_EXIT
4912 	return rv;
4913     }
4914 }
4915 
4916 %constant int ENTITY_ID_UNSPECIFIED = IPMI_ENTITY_ID_UNSPECIFIED;
4917 %constant int ENTITY_ID_OTHER = IPMI_ENTITY_ID_OTHER;
4918 %constant int ENTITY_ID_UNKOWN = IPMI_ENTITY_ID_UNKOWN;
4919 %constant int ENTITY_ID_PROCESSOR = IPMI_ENTITY_ID_PROCESSOR;
4920 %constant int ENTITY_ID_DISK = IPMI_ENTITY_ID_DISK;
4921 %constant int ENTITY_ID_PERIPHERAL = IPMI_ENTITY_ID_PERIPHERAL;
4922 %constant int ENTITY_ID_SYSTEM_MANAGEMENT_MODULE = IPMI_ENTITY_ID_SYSTEM_MANAGEMENT_MODULE;
4923 %constant int ENTITY_ID_SYSTEM_BOARD = IPMI_ENTITY_ID_SYSTEM_BOARD;
4924 %constant int ENTITY_ID_MEMORY_MODULE = IPMI_ENTITY_ID_MEMORY_MODULE;
4925 %constant int ENTITY_ID_PROCESSOR_MODULE = IPMI_ENTITY_ID_PROCESSOR_MODULE;
4926 %constant int ENTITY_ID_POWER_SUPPLY = IPMI_ENTITY_ID_POWER_SUPPLY;
4927 %constant int ENTITY_ID_ADD_IN_CARD = IPMI_ENTITY_ID_ADD_IN_CARD;
4928 %constant int ENTITY_ID_FRONT_PANEL_BOARD = IPMI_ENTITY_ID_FRONT_PANEL_BOARD;
4929 %constant int ENTITY_ID_BACK_PANEL_BOARD = IPMI_ENTITY_ID_BACK_PANEL_BOARD;
4930 %constant int ENTITY_ID_POWER_SYSTEM_BOARD = IPMI_ENTITY_ID_POWER_SYSTEM_BOARD;
4931 %constant int ENTITY_ID_DRIVE_BACKPLANE = IPMI_ENTITY_ID_DRIVE_BACKPLANE;
4932 %constant int ENTITY_ID_SYSTEM_INTERNAL_EXPANSION_BOARD = IPMI_ENTITY_ID_SYSTEM_INTERNAL_EXPANSION_BOARD;
4933 %constant int ENTITY_ID_OTHER_SYSTEM_BOARD = IPMI_ENTITY_ID_OTHER_SYSTEM_BOARD;
4934 %constant int ENTITY_ID_PROCESSOR_BOARD = IPMI_ENTITY_ID_PROCESSOR_BOARD;
4935 %constant int ENTITY_ID_POWER_UNIT = IPMI_ENTITY_ID_POWER_UNIT;
4936 %constant int ENTITY_ID_POWER_MODULE = IPMI_ENTITY_ID_POWER_MODULE;
4937 %constant int ENTITY_ID_POWER_MANAGEMENT_BOARD = IPMI_ENTITY_ID_POWER_MANAGEMENT_BOARD;
4938 %constant int ENTITY_ID_CHASSIS_BACK_PANEL_BOARD = IPMI_ENTITY_ID_CHASSIS_BACK_PANEL_BOARD;
4939 %constant int ENTITY_ID_SYSTEM_CHASSIS = IPMI_ENTITY_ID_SYSTEM_CHASSIS;
4940 %constant int ENTITY_ID_SUB_CHASSIS = IPMI_ENTITY_ID_SUB_CHASSIS;
4941 %constant int ENTITY_ID_OTHER_CHASSIS_BOARD = IPMI_ENTITY_ID_OTHER_CHASSIS_BOARD;
4942 %constant int ENTITY_ID_DISK_DRIVE_BAY = IPMI_ENTITY_ID_DISK_DRIVE_BAY;
4943 %constant int ENTITY_ID_PERIPHERAL_BAY = IPMI_ENTITY_ID_PERIPHERAL_BAY;
4944 %constant int ENTITY_ID_DEVICE_BAY = IPMI_ENTITY_ID_DEVICE_BAY;
4945 %constant int ENTITY_ID_FAN_COOLING = IPMI_ENTITY_ID_FAN_COOLING;
4946 %constant int ENTITY_ID_COOLING_UNIT = IPMI_ENTITY_ID_COOLING_UNIT;
4947 %constant int ENTITY_ID_CABLE_INTERCONNECT = IPMI_ENTITY_ID_CABLE_INTERCONNECT;
4948 %constant int ENTITY_ID_MEMORY_DEVICE = IPMI_ENTITY_ID_MEMORY_DEVICE;
4949 %constant int ENTITY_ID_SYSTEM_MANAGEMENT_SOFTWARE = IPMI_ENTITY_ID_SYSTEM_MANAGEMENT_SOFTWARE;
4950 %constant int ENTITY_ID_BIOS = IPMI_ENTITY_ID_BIOS;
4951 %constant int ENTITY_ID_OPERATING_SYSTEM = IPMI_ENTITY_ID_OPERATING_SYSTEM;
4952 %constant int ENTITY_ID_SYSTEM_BUS = IPMI_ENTITY_ID_SYSTEM_BUS;
4953 %constant int ENTITY_ID_GROUP = IPMI_ENTITY_ID_GROUP;
4954 %constant int ENTITY_ID_REMOTE_MGMT_COMM_DEVICE = IPMI_ENTITY_ID_REMOTE_MGMT_COMM_DEVICE;
4955 %constant int ENTITY_ID_EXTERNAL_ENVIRONMENT = IPMI_ENTITY_ID_EXTERNAL_ENVIRONMENT;
4956 %constant int ENTITY_ID_BATTERY = IPMI_ENTITY_ID_BATTERY;
4957 %constant int ENTITY_ID_PROCESSING_BLADE = IPMI_ENTITY_ID_PROCESSING_BLADE;
4958 %constant int ENTITY_ID_CONNECTIVITY_SWITCH = IPMI_ENTITY_ID_CONNECTIVITY_SWITCH;
4959 %constant int ENTITY_ID_PROCESSOR_MEMORY_MODULE = IPMI_ENTITY_ID_PROCESSOR_MEMORY_MODULE;
4960 %constant int ENTITY_ID_IO_MODULE = IPMI_ENTITY_ID_IO_MODULE;
4961 %constant int ENTITY_ID_PROCESSOR_IO_MODULE = IPMI_ENTITY_ID_PROCESSOR_IO_MODULE;
4962 %constant int ENTITY_ID_MGMT_CONTROLLER_FIRMWARE = IPMI_ENTITY_ID_MGMT_CONTROLLER_FIRMWARE;
4963 %constant int ENTITY_ID_IPMI_CHANNEL = IPMI_ENTITY_ID_IPMI_CHANNEL;
4964 %constant int ENTITY_ID_PCI_BUS = IPMI_ENTITY_ID_PCI_BUS;
4965 %constant int ENTITY_ID_PCI_EXPRESS_BUS = IPMI_ENTITY_ID_PCI_EXPRESS_BUS;
4966 %constant int ENTITY_ID_SCSI_BUS = IPMI_ENTITY_ID_SCSI_BUS;
4967 %constant int ENTITY_ID_SATA_SAS_BUS = IPMI_ENTITY_ID_SATA_SAS_BUS;
4968 %constant int ENTITY_ID_PROCESSOR_FRONT_SIDE_BUS = IPMI_ENTITY_ID_PROCESSOR_FRONT_SIDE_BUS;
4969 
4970 /*
4971  * An entity object.
4972  */
4973 %extend ipmi_entity_t {
4974     /*
4975      * Get the domain the entity belongs to.
4976      */
get_domain()4977     ipmi_domain_t *get_domain()
4978     {
4979 	return ipmi_entity_get_domain(self);
4980     }
4981 
4982     %newobject get_name;
4983     /*
4984      * Get the name of an entity.
4985      */
get_name()4986     char *get_name()
4987     {
4988 	char name[IPMI_ENTITY_NAME_LEN];
4989 
4990 	ipmi_entity_get_name(self, name, sizeof(name));
4991 	return strdup(name);
4992     }
4993 
4994     %newobject get_id;
4995     /*
4996      * Get the id for the entity.
4997      */
get_id()4998     ipmi_entity_id_t *get_id()
4999     {
5000 	ipmi_entity_id_t *rv = malloc(sizeof(*rv));
5001 	if (rv)
5002 	    *rv = ipmi_entity_convert_to_id(self);
5003 	return rv;
5004     }
5005 
5006     /*
5007      * Iterate through all the entity's children.  The
5008      * entity_iter_entities_cb method will be called on the first
5009      * parameter for each child entity of the parent.  The parameters
5010      * it receives will be: <self> <parent> <child>.
5011      */
iterate_children(swig_cb * handler)5012     int iterate_children(swig_cb *handler)
5013     {
5014 	swig_cb_val *handler_val;
5015 	int         rv = 0;
5016 
5017 	IPMI_SWIG_C_CB_ENTRY
5018 	if (! valid_swig_cb(handler, entity_iter_entities_cb))
5019 	    rv = EINVAL;
5020 	else {
5021 	    handler_val = get_swig_cb(handler, entity_iter_entities_cb);
5022 	    ipmi_entity_iterate_children(self, entity_iterate_entities_handler,
5023 					 handler_val);
5024 	}
5025 	IPMI_SWIG_C_CB_EXIT
5026 	return rv;
5027     }
5028 
5029     /*
5030      * Iterate through all the entity's parents.  The
5031      * entity_iter_entities_cb method will be called on the first
5032      * parameter for each parent entity of the child.  The parameters
5033      * it receives will be: <self> <child> <parent>.
5034      */
iterate_parents(swig_cb * handler)5035     int iterate_parents(swig_cb *handler)
5036     {
5037 	swig_cb_val *handler_val;
5038 	int         rv = 0;
5039 
5040 	IPMI_SWIG_C_CB_ENTRY
5041 	if (! valid_swig_cb(handler, entity_iter_entities_cb))
5042 	    rv = EINVAL;
5043 	else {
5044 	    handler_val = get_swig_cb(handler, entity_iter_entities_cb);
5045 	    ipmi_entity_iterate_parents(self, entity_iterate_entities_handler,
5046 					handler_val);
5047 	}
5048 	IPMI_SWIG_C_CB_EXIT
5049 	return rv;
5050     }
5051 
5052     /*
5053      * Iterate through all the entity's sensors.  The
5054      * entity_iter_sensors_cb method will be called on the first
5055      * parameter for each sensor of the entity.  The parameters
5056      * it receives will be: <self> <entity> <sensor>.
5057      */
iterate_sensors(swig_cb * handler)5058     int iterate_sensors(swig_cb *handler)
5059     {
5060 	swig_cb_val *handler_val;
5061 	int         rv = 0;
5062 
5063 	IPMI_SWIG_C_CB_ENTRY
5064 	if (! valid_swig_cb(handler, entity_iter_sensors_cb))
5065 	    rv = EINVAL;
5066 	else {
5067 	    handler_val = get_swig_cb(handler, entity_iter_sensors_cb);
5068 	    ipmi_entity_iterate_sensors(self, entity_iterate_sensors_handler,
5069 					handler_val);
5070 	}
5071 	IPMI_SWIG_C_CB_EXIT
5072 	return rv;
5073     }
5074 
5075     /*
5076      * Iterate through all the entity's controls.  The
5077      * entity_iter_controls_cb method will be called on the first
5078      * parameter for each control of the entity.  The parameters
5079      * it receives will be: <self> <entity> <control>.
5080      */
iterate_controls(swig_cb * handler)5081     int iterate_controls(swig_cb *handler)
5082     {
5083 	swig_cb_val *handler_val;
5084 	int         rv = 0;
5085 
5086 	IPMI_SWIG_C_CB_ENTRY
5087 	if (! valid_swig_cb(handler, entity_iter_controls_cb))
5088 	    rv = EINVAL;
5089 	else {
5090 	    handler_val = get_swig_cb(handler, entity_iter_controls_cb);
5091 	    ipmi_entity_iterate_controls(self, entity_iterate_controls_handler,
5092 					 handler_val);
5093 	}
5094 	IPMI_SWIG_C_CB_EXIT
5095 	return rv;
5096     }
5097 
5098     /*
5099      * Add a handler to be called when an entity's presence
5100      * changes. When the presence changes the entity_presence_cb
5101      * method on the first parameter will be called with the following
5102      * parameters: <self> <entity> <present (boolean integer)> <event>.
5103      * The event is optional and may not be present.
5104      */
add_presence_handler(swig_cb * handler)5105     int add_presence_handler(swig_cb *handler)
5106     {
5107 	ipmi_entity_add_presence_handler_cl
5108 	    (self, entity_presence_handler_cl, NULL);
5109 	cb_add(entity, presence, entity_presence_cb);
5110     }
5111 
5112     /*
5113      * Remove the presence handler.
5114      */
remove_presence_handler(swig_cb * handler)5115     int remove_presence_handler(swig_cb *handler)
5116     {
5117 	cb_rm(entity, presence, entity_presence_cb);
5118     }
5119 
5120     /*
5121      * Add a handler to be called when a sensor in the entity is
5122      * added, deleted, or updated.  When the sensor changes the
5123      * entity_sensor_update_cb method on the first parameter will be
5124      * called with the following parameters: <self>
5125      * added|deleted|changed <entity> <sensor>.
5126      */
add_sensor_update_handler(swig_cb * handler)5127     int add_sensor_update_handler(swig_cb *handler)
5128     {
5129 	ipmi_entity_add_sensor_update_handler_cl
5130 	    (self, entity_sensor_update_handler_cl, NULL);
5131 	cb_add(entity, sensor_update, entity_sensor_update_cb);
5132     }
5133 
5134     /*
5135      * Remove the sensor update handler.
5136      */
remove_sensor_update_handler(swig_cb * handler)5137     int remove_sensor_update_handler(swig_cb *handler)
5138     {
5139 	cb_rm(entity, sensor_update, entity_sensor_update_cb);
5140     }
5141 
5142     /*
5143      * Add a handler to be called when a control in the entity is
5144      * added, deleted, or updated.  When the control changes the
5145      * entity_control_update_cb method on the first parameter will be
5146      * called with the following parameters: <self>
5147      * added|deleted|changed <entity> <control>.
5148      */
add_control_update_handler(swig_cb * handler)5149     int add_control_update_handler(swig_cb *handler)
5150     {
5151 	ipmi_entity_add_control_update_handler_cl
5152 	    (self, entity_control_update_handler_cl, NULL);
5153 	cb_add(entity, control_update, entity_control_update_cb);
5154     }
5155 
5156     /*
5157      * Remove the control update handler.
5158      */
remove_control_update_handler(swig_cb * handler)5159     int remove_control_update_handler(swig_cb *handler)
5160     {
5161 	cb_rm(entity, control_update, entity_control_update_cb);
5162     }
5163 
5164     /*
5165      * Add a handler to be called when the FRU data in the entity is
5166      * added, deleted, or updated.  When the FRU data changes the
5167      * entity_fru_update_cb method on the first parameter will be
5168      * called with the following parameters: <self>
5169      * added|deleted|changed <entity> <fru>.
5170      *
5171      * Deprecated, use the werr version below so you can get errors
5172      * reported.
5173      */
add_fru_update_handler(swig_cb * handler)5174     int add_fru_update_handler(swig_cb *handler)
5175     {
5176 	ipmi_entity_add_fru_update_handler_cl
5177 	    (self, entity_fru_update_handler_cl, NULL);
5178 	cb_add(entity, fru_update, entity_fru_update_cb);
5179     }
5180 
5181     /*
5182      * Remove the FRU data update handler.
5183      */
remove_fru_update_handler(swig_cb * handler)5184     int remove_fru_update_handler(swig_cb *handler)
5185     {
5186 	cb_rm(entity, fru_update, entity_fru_update_cb);
5187     }
5188 
5189     /*
5190      * Add a handler to be called when the FRU data in the entity is
5191      * added, deleted, or updated.  When the FRU data changes the
5192      * entity_fru_update_werr_cb method on the first parameter will be
5193      * called with the following parameters: <self>
5194      * added|deleted|changed|error <errnum> <entity> <fru>.
5195      */
add_fru_update_werr_handler(swig_cb * handler)5196     int add_fru_update_werr_handler(swig_cb *handler)
5197     {
5198 	ipmi_entity_add_fru_update_werr_handler_cl
5199 	    (self, entity_fru_update_werr_handler_cl, NULL);
5200 	cb_add(entity, fru_update_werr, entity_fru_update_werr_cb);
5201     }
5202 
5203     /*
5204      * Remove the FRU data update handler.
5205      */
remove_fru_update_werr_handler(swig_cb * handler)5206     int remove_fru_update_werr_handler(swig_cb *handler)
5207     {
5208 	cb_rm(entity, fru_update_werr, entity_fru_update_werr_cb);
5209     }
5210 
5211     /*
5212      * Get the entities type, return "mc", "fru", "generic", or "unknown".
5213      */
get_type()5214     char *get_type()
5215     {
5216 	switch (ipmi_entity_get_type(self)) {
5217 	case IPMI_ENTITY_MC: return "mc";
5218 	case IPMI_ENTITY_FRU: return "fru";
5219 	case IPMI_ENTITY_GENERIC: return "generic";
5220 	default: return "unknown";
5221 	}
5222     }
5223 
5224     /*
5225      * Returns if the entity has FRU data or not.
5226      */
is_fru()5227     int is_fru()
5228     {
5229 	return ipmi_entity_get_is_fru(self);
5230     }
5231 
5232     %newobject get_id_string;
5233     /*
5234      * Get the ID string from the SDR
5235      */
get_id_string()5236     char *get_id_string()
5237     {
5238 	int length = ipmi_entity_get_id_length(self);
5239 	char *str;
5240 	if (length < 2)
5241 	    return NULL;
5242 	str = malloc(length);
5243 	if (!str)
5244 	    return NULL;
5245 	ipmi_entity_get_id(self, str, length);
5246 	return str;
5247     }
5248 
5249     /*
5250      * Get the entity id for the entity
5251      */
get_entity_id()5252     int get_entity_id()
5253     {
5254 	return ipmi_entity_get_entity_id(self);
5255     }
5256 
5257     /*
5258      * Get the string representation of the entity id
5259      */
get_entity_id_string()5260     const char *get_entity_id_string()
5261     {
5262 	return ipmi_entity_get_entity_id_string(self);
5263     }
5264 
5265     /*
5266      * Get the entity instance for the entity
5267      */
get_entity_instance()5268     int get_entity_instance()
5269     {
5270 	return ipmi_entity_get_entity_instance(self);
5271     }
5272 
5273     /*
5274      * Get the channel for the entity.  Only valid if the entity
5275      * instance is 0x60 or larger.
5276      */
get_entity_device_channel()5277     int get_entity_device_channel()
5278     {
5279 	return ipmi_entity_get_device_channel(self);
5280     }
5281 
5282     /*
5283      * Get the address for the entity.  Only valid if the entity
5284      * instance is 0x60 or larger.
5285      */
get_entity_device_address()5286     int get_entity_device_address()
5287     {
5288 	return ipmi_entity_get_device_address(self);
5289     }
5290 
5291     /*
5292      * Get the FRU data for the entity.  Note that you cannot hold the
5293      * FRU data pointer outside the context of where the entity pointer
5294      * is valid.
5295      */
5296     %newobject get_fru;
get_fru()5297     ipmi_fru_t *get_fru()
5298     {
5299 	ipmi_fru_t *fru = ipmi_entity_get_fru(self);
5300 	if (fru)
5301 	    ipmi_fru_ref(fru);
5302 	return fru;
5303     }
5304 
5305     /*
5306      * If this returns true, then the presence sensor is always there
5307      * for this entity.
5308      */
get_presence_sensor_always_there()5309     int get_presence_sensor_always_there()
5310     {
5311 	return ipmi_entity_get_presence_sensor_always_there(self);
5312     }
5313 
5314     /*
5315      * Returns if the entity has a parent.
5316      */
is_child()5317     int is_child()
5318     {
5319 	return ipmi_entity_get_is_child(self);
5320     }
5321 
5322     /*
5323      * Returns if the entity has a child.
5324      */
is_parent()5325     int is_parent()
5326     {
5327 	return ipmi_entity_get_is_parent(self);
5328     }
5329 
5330     /*
5331      * Return the channel from the device locator record.  Valid for
5332      * all entities except unknown.
5333      */
get_channel()5334     int get_channel()
5335     {
5336 	return ipmi_entity_get_channel(self);
5337     }
5338 
5339     /*
5340      * Return the LUN from the device locator record.  Valid for
5341      * all entities except unknown.
5342      */
get_lun()5343     int get_lun()
5344     {
5345 	return ipmi_entity_get_lun(self);
5346     }
5347 
5348     /*
5349      * Return the OEM byte from the device locator record.  Valid for
5350      * all entities except unknown.
5351      */
get_oem()5352     int get_oem()
5353     {
5354 	return ipmi_entity_get_oem(self);
5355     }
5356 
5357     /*
5358      * Return the access address from the device locator record.  Valid for
5359      * FRU and generic entities.
5360      */
get_access_address()5361     int get_access_address()
5362     {
5363 	return ipmi_entity_get_access_address(self);
5364     }
5365 
5366     /*
5367      * Return the private bus id from the device locator record.  Valid for
5368      * FRU and generic entities.
5369      */
get_private_bus_id()5370     int get_private_bus_id()
5371     {
5372 	return ipmi_entity_get_private_bus_id(self);
5373     }
5374 
5375     /*
5376      * Return the device type from the device locator record.  Valid for
5377      * FRU and generic entities.
5378      */
get_device_type()5379     int get_device_type()
5380     {
5381 	return ipmi_entity_get_device_type(self);
5382     }
5383 
5384     /*
5385      * Return the device modifier from the device locator record.
5386      * Valid for FRU and generic entities.
5387      */
get_device_modifier()5388     int get_device_modifier()
5389     {
5390 	return ipmi_entity_get_device_modifier(self);
5391     }
5392 
5393     /*
5394      * Return the slave address from the device locator record.  Valid for
5395      * MC and generic entities.
5396      */
get_slave_address()5397     int get_slave_address()
5398     {
5399 	return ipmi_entity_get_slave_address(self);
5400     }
5401 
5402     %newobject get_mc_id;
get_mc_id()5403     ipmi_mcid_t *get_mc_id()
5404     {
5405 	ipmi_mcid_t *mc_id = malloc(sizeof(*mc_id));
5406 	int rv;
5407 	rv = ipmi_entity_get_mc_id(self, mc_id);
5408 	if (rv) {
5409 	    free(mc_id);
5410 	    mc_id = NULL;
5411 	}
5412 	return mc_id;
5413     }
5414     /*
5415      * Return if the FRU is logical (from the device locator record).
5416      * Valid for FRU entities.
5417      */
get_is_logical_fru()5418     int get_is_logical_fru()
5419     {
5420 	return ipmi_entity_get_is_logical_fru(self);
5421     }
5422 
5423     /*
5424      * Return the device id from the device locator record.  Valid for
5425      * FRU entities.
5426      */
get_fru_device_id()5427     int get_fru_device_id()
5428     {
5429 	return ipmi_entity_get_fru_device_id(self);
5430     }
5431 
5432     /*
5433      * Return the ACPI system power notify required bit from the
5434      * device locator record.  Valid for MC entities.
5435      */
get_ACPI_system_power_notify_required()5436     int get_ACPI_system_power_notify_required()
5437     {
5438 	return ipmi_entity_get_ACPI_system_power_notify_required(self);
5439     }
5440 
5441     /*
5442      * Return the ACPI device power notify required bit from the
5443      * device locator record.  Valid for MC entities.
5444      */
get_ACPI_device_power_notify_required()5445     int get_ACPI_device_power_notify_required()
5446     {
5447 	return ipmi_entity_get_ACPI_device_power_notify_required(self);
5448     }
5449 
5450     /*
5451      * Return the controller logs init agent errors bit from the
5452      * device locator record.  Valid for MC entities.
5453      */
get_controller_logs_init_agent_errors()5454     int get_controller_logs_init_agent_errors()
5455     {
5456 	return ipmi_entity_get_controller_logs_init_agent_errors(self);
5457     }
5458 
5459     /*
5460      * Return the log init agent errors accessing bit from the
5461      * device locator record.  Valid for MC entities.
5462      */
get_log_init_agent_errors_accessing()5463     int get_log_init_agent_errors_accessing()
5464     {
5465 	return ipmi_entity_get_log_init_agent_errors_accessing(self);
5466     }
5467 
5468     /*
5469      * Return the global init bit from the
5470      * device locator record.  Valid for MC entities.
5471      */
get_global_init()5472     int get_global_init()
5473     {
5474 	return ipmi_entity_get_global_init(self);
5475     }
5476 
5477     /*
5478      * Return the chassis device bit from the
5479      * device locator record.  Valid for MC entities.
5480      */
get_chassis_device()5481     int get_chassis_device()
5482     {
5483 	return ipmi_entity_get_chassis_device(self);
5484     }
5485 
5486     /*
5487      * Return the !bridge bit from the
5488      * device locator record.  Valid for MC entities.
5489      */
get_bridge()5490     int get_bridge()
5491     {
5492 	return ipmi_entity_get_bridge(self);
5493     }
5494 
5495     /*
5496      * Return the IPMB event generator bit from the
5497      * device locator record.  Valid for MC entities.
5498      */
get_IPMB_event_generator()5499     int get_IPMB_event_generator()
5500     {
5501 	return ipmi_entity_get_IPMB_event_generator(self);
5502     }
5503 
5504     /*
5505      * Return the IPMB event receiver bit from the
5506      * device locator record.  Valid for MC entities.
5507      */
get_IPMB_event_receiver()5508     int get_IPMB_event_receiver()
5509     {
5510 	return ipmi_entity_get_IPMB_event_receiver(self);
5511     }
5512 
5513     /*
5514      * Return the FRU inventory device bit from the
5515      * device locator record.  Valid for MC entities.
5516      */
get_FRU_inventory_device()5517     int get_FRU_inventory_device()
5518     {
5519 	return ipmi_entity_get_FRU_inventory_device(self);
5520     }
5521 
5522     /*
5523      * Return the SEL device bit from the
5524      * device locator record.  Valid for MC entities.
5525      */
get_SEL_device()5526     int get_SEL_device()
5527     {
5528 	return ipmi_entity_get_SEL_device(self);
5529     }
5530 
5531     /*
5532      * Return the SDR repository device bit from the
5533      * device locator record.  Valid for MC entities.
5534      */
get_SDR_repository_device()5535     int get_SDR_repository_device()
5536     {
5537 	return ipmi_entity_get_SDR_repository_device(self);
5538     }
5539 
5540     /*
5541      * Return the sensor device bit from the
5542      * device locator record.  Valid for MC entities.
5543      */
get_sensor_device()5544     int get_sensor_device()
5545     {
5546 	return ipmi_entity_get_sensor_device(self);
5547     }
5548 
5549     /*
5550      * Return the address span from the device locator record.  Valid
5551      * for generic entities.
5552      */
get_address_span()5553     int get_address_span()
5554     {
5555 	return ipmi_entity_get_address_span(self);
5556     }
5557 
5558     %newobject get_dlr_id;
5559     /*
5560      * Return the id string from the DLR.
5561      */
get_dlr_id()5562     char *get_dlr_id()
5563     {
5564 	/* FIXME - no unicode handling. */
5565 	int len = ipmi_entity_get_id_length(self) + 1;
5566 	char *id = malloc(len);
5567 	ipmi_entity_get_id(self, id, len);
5568 	return id;
5569     }
5570 
5571     /*
5572      * Returns true if the entity is present, false if not.
5573      */
is_present()5574     int is_present()
5575     {
5576 	return ipmi_entity_is_present(self);
5577     }
5578 
5579     /*
5580      * Returns the physical slot number, or -1 if there is not
5581      * a slot number.
5582      */
get_physical_slot_num()5583     int get_physical_slot_num()
5584     {
5585 	unsigned int num;
5586 	if (ipmi_entity_get_physical_slot_num(self, &num) == 0)
5587 	    return num;
5588 	else
5589 	    return -1;
5590     }
5591 
5592     /*
5593      * Returns true if the entity is hot-swappable, false if not.
5594      */
is_hot_swappable()5595     int is_hot_swappable()
5596     {
5597 	return ipmi_entity_hot_swappable(self);
5598     }
5599 
supports_managed_hot_swap()5600     int supports_managed_hot_swap()
5601     {
5602 	return ipmi_entity_supports_managed_hot_swap(self);
5603     }
5604 
5605     /*
5606      * Add a handler to be called when the hot-swap state for the
5607      * entity changes.  When the hot-swap state changes the
5608      * entity_hot_swap_update_cb method on the first parameter will be
5609      * called with the following parameters: <self> <entity> <old
5610      * state> <new state> <event>.  The event is optional and may not
5611      * be present.
5612      */
add_hot_swap_handler(swig_cb * handler)5613     int add_hot_swap_handler(swig_cb *handler)
5614     {
5615 	ipmi_entity_add_hot_swap_handler_cl
5616 	    (self, entity_hot_swap_handler_cl, NULL);
5617 	cb_add(entity, hot_swap, entity_hot_swap_update_cb);
5618     }
5619 
5620     /*
5621      * Remove the hot-swap update handler.
5622      */
remove_hot_swap_handler(swig_cb * handler)5623     int remove_hot_swap_handler(swig_cb *handler)
5624     {
5625 	cb_rm(entity, hot_swap, entity_hot_swap_update_cb);
5626     }
5627 
5628     /*
5629      * Get the current hot-swap state for the entity.  The
5630      * entity_hot_swap_cb handler will be called with the following
5631      * parameters: <self> <entity> <err> <state>
5632      */
get_hot_swap_state(swig_cb * handler)5633     int get_hot_swap_state(swig_cb *handler)
5634     {
5635 	swig_cb_val *handler_val;
5636 	int         rv;
5637 
5638 	IPMI_SWIG_C_CB_ENTRY
5639 	if (! valid_swig_cb(handler, entity_hot_swap_cb))
5640 	    rv = EINVAL;
5641 	else {
5642 	    handler_val = ref_swig_cb(handler, entity_hot_swap_cb);
5643 	    rv = ipmi_entity_get_hot_swap_state(self,
5644 						entity_get_hot_swap_handler,
5645 						handler_val);
5646 	    if (rv)
5647 		deref_swig_cb_val(handler_val);
5648 	}
5649 	IPMI_SWIG_C_CB_EXIT
5650 	return rv;
5651     }
5652 
5653     /* Returns if the entity supports auto-activate. */
supports_auto_activate_time()5654     int supports_auto_activate_time()
5655     {
5656 	return ipmi_entity_supports_auto_activate_time(self);
5657     }
5658 
5659     /*
5660      * Get the current hot-swap activation time for the entity.  The
5661      * entity_hot_swap_get_time_cb handler will be called with the
5662      * following parameters: <self> <entity> <err> <time>
5663      */
get_auto_activate_time(swig_cb * handler)5664     int get_auto_activate_time(swig_cb *handler)
5665     {
5666 	swig_cb_val *handler_val;
5667 	int         rv;
5668 
5669 	IPMI_SWIG_C_CB_ENTRY
5670 	if (! valid_swig_cb(handler, entity_hot_swap_get_time_cb))
5671 	    rv = EINVAL;
5672 	else {
5673 	    handler_val = ref_swig_cb(handler, entity_hot_swap_get_time_cb);
5674 	    rv = ipmi_entity_get_auto_activate_time
5675 		(self,
5676 		 entity_get_hot_swap_time_handler,
5677 		 handler_val);
5678 	    if (rv)
5679 		deref_swig_cb_val(handler_val);
5680 	}
5681 	IPMI_SWIG_C_CB_EXIT
5682 	return rv;
5683     }
5684 
5685     /*
5686      * Set the current hot-swap activation time for the entity.  The
5687      * entity_hot_swap_set_time_cb handler will be called with the
5688      * following parameters (if it is supplied): <self> <entity> <err>
5689      */
5690     int set_auto_activate_time(ipmi_timeout_t auto_act,
5691 			       swig_cb *handler = NULL)
5692     {
5693 	swig_cb_val    *handler_val = NULL;
5694 	ipmi_entity_cb done = NULL;
5695 	int            rv;
5696 
5697 	IPMI_SWIG_C_CB_ENTRY
5698 	if (!nil_swig_cb(handler)) {
5699 	    if (!valid_swig_cb(handler, entity_hot_swap_set_time_cb)) {
5700 		rv = EINVAL;
5701 		goto out_err;
5702 	    }
5703 	    handler_val = ref_swig_cb(handler, entity_hot_swap_set_time_cb);
5704 	    done = entity_set_hot_swap_time_handler;
5705 	}
5706 	rv = ipmi_entity_set_auto_activate_time
5707 	    (self, auto_act, done, handler_val);
5708 	if (rv && handler_val)
5709 	    deref_swig_cb_val(handler_val);
5710     out_err:
5711 	IPMI_SWIG_C_CB_EXIT
5712 	return rv;
5713     }
5714 
5715     /* Returns if the entity supports auto-deactivate. */
supports_auto_deactivate_time()5716     int supports_auto_deactivate_time()
5717     {
5718 	return ipmi_entity_supports_auto_deactivate_time(self);
5719     }
5720 
5721     /*
5722      * Get the current hot-swap deactivation time for the entity.  The
5723      * entity_hot_swap_get_time_cb handler will be called with the
5724      * following parameters: <self> <entity> <err> <time>
5725      */
get_auto_deactivate_time(swig_cb * handler)5726     int get_auto_deactivate_time(swig_cb *handler)
5727     {
5728 	swig_cb_val *handler_val;
5729 	int         rv;
5730 
5731 	IPMI_SWIG_C_CB_ENTRY
5732 	if (! valid_swig_cb(handler, entity_hot_swap_get_time_cb))
5733 	    rv = EINVAL;
5734 	else {
5735 	    handler_val = ref_swig_cb(handler, entity_hot_swap_get_time_cb);
5736 	    rv = ipmi_entity_get_auto_deactivate_time
5737 		(self,
5738 		 entity_get_hot_swap_time_handler,
5739 		 handler_val);
5740 	    if (rv)
5741 		deref_swig_cb_val(handler_val);
5742 	}
5743 	IPMI_SWIG_C_CB_EXIT
5744 	return rv;
5745     }
5746 
5747     /*
5748      * Set the current hot-swap deactivation time for the entity.  The
5749      * entity_hot_swap_set_time_cb handler will be called with the
5750      * following parameters (if it is supplied): <self> <entity> <err>
5751      */
5752     int set_auto_deactivate_time(ipmi_timeout_t auto_act,
5753 				 swig_cb        *handler = NULL)
5754     {
5755 	swig_cb_val    *handler_val = NULL;
5756 	ipmi_entity_cb done = NULL;
5757 	int            rv;
5758 
5759 	IPMI_SWIG_C_CB_ENTRY
5760 	if (!nil_swig_cb(handler)) {
5761 	    if (!valid_swig_cb(handler, entity_hot_swap_set_time_cb)) {
5762 		rv = EINVAL;
5763 		goto out_err;
5764 	    }
5765 	    handler_val = ref_swig_cb(handler, entity_hot_swap_set_time_cb);
5766 	    done = entity_set_hot_swap_time_handler;
5767 	}
5768 	rv = ipmi_entity_set_auto_deactivate_time
5769 	    (self, auto_act, done, handler_val);
5770 	if (rv && handler_val)
5771 	    deref_swig_cb_val(handler_val);
5772     out_err:
5773 	IPMI_SWIG_C_CB_EXIT
5774 	return rv;
5775     }
5776 
5777     /*
5778      * Cause the entity to move from INACTIVE to ACTIVATION_REQUESTED
5779      * state, if possible. If the entity does not support this
5780      * operation, this will return ENOSYS and you can move straight
5781      * from INACTIVE to ACTIVE state by calling ipmi_entity_activate.
5782      * After this is done, the entity_activate_cb handler will be
5783      * called with the following parameters (if it is supplied):
5784      * <self> <entity> <err>
5785      */
5786     int set_activation_requested(swig_cb *handler = NULL)
5787     {
5788 	swig_cb_val    *handler_val = NULL;
5789 	ipmi_entity_cb done = NULL;
5790 	int            rv;
5791 
5792 	IPMI_SWIG_C_CB_ENTRY
5793 	if (!nil_swig_cb(handler)) {
5794 	    if (! valid_swig_cb(handler, entity_activate_cb)) {
5795 		rv = EINVAL;
5796 		goto out_err;
5797 	    }
5798 	    handler_val = ref_swig_cb(handler, entity_activate_cb);
5799 	    done = entity_activate_handler;
5800 	}
5801 	rv = ipmi_entity_set_activation_requested(self, done, handler_val);
5802 	if (rv && handler_val)
5803 	    deref_swig_cb_val(handler_val);
5804     out_err:
5805 	IPMI_SWIG_C_CB_EXIT
5806 	return rv;
5807     }
5808 
5809     /*
5810      * Attempt to activate an entity.  Activate will cause a
5811      * transition from INACTIVE to ACTIVE (but only if
5812      * ipmi_entity_set_activation_requested() returns ENOSYS), or from
5813      * ACTIVATION_REQUESTED to ACTIVE.  After this is done, the
5814      * entity_activate_cb handler will be called with the following
5815      * parameters (if it is supplied): <self> <entity> <err>
5816      */
5817     int activate(swig_cb *handler = NULL)
5818     {
5819 	swig_cb_val    *handler_val = NULL;
5820 	ipmi_entity_cb done = NULL;
5821 	int            rv;
5822 
5823 	IPMI_SWIG_C_CB_ENTRY
5824 	if (!nil_swig_cb(handler)) {
5825 	    if (! valid_swig_cb(handler, entity_activate_cb)) {
5826 		rv = EINVAL;
5827 		goto out_err;
5828 	    }
5829 	    handler_val = ref_swig_cb(handler, entity_activate_cb);
5830 	    done = entity_activate_handler;
5831 	}
5832 	rv = ipmi_entity_activate(self, done, handler_val);
5833 	if (rv && handler_val)
5834 	    deref_swig_cb_val(handler_val);
5835     out_err:
5836 	IPMI_SWIG_C_CB_EXIT
5837 	return rv;
5838     }
5839 
5840     /*
5841      * Attempt to deactivate an entity.  Deactivate will cause a
5842      * transition from DEACTIVATION_REQUESTED or ACTIVE to INACTIVE.
5843      * After this is done, the entity_activate_cb handler will be
5844      * called with the following parameters (if it is supplied):
5845      * <self> <entity> <err>
5846      */
5847     int deactivate(swig_cb *handler = NULL)
5848     {
5849 	swig_cb_val    *handler_val = NULL;
5850 	ipmi_entity_cb done = NULL;
5851 	int            rv;
5852 
5853 	IPMI_SWIG_C_CB_ENTRY
5854 	if (!nil_swig_cb(handler)) {
5855 	    if (! valid_swig_cb(handler, entity_activate_cb)) {
5856 		rv = EINVAL;
5857 		goto out_err;
5858 	    }
5859 	    handler_val = ref_swig_cb(handler, entity_activate_cb);
5860 	    done = entity_activate_handler;
5861 	}
5862 	rv = ipmi_entity_deactivate(self, done, handler_val);
5863 	if (rv && handler_val)
5864 	    deref_swig_cb_val(handler_val);
5865     out_err:
5866 	IPMI_SWIG_C_CB_EXIT
5867 	return rv;
5868     }
5869 
5870     /*
5871      * Check the state of hot-swap for the entity.  This causes the
5872      * local state to be audited against the actual state.
5873      */
check_hot_swap_state()5874     int check_hot_swap_state()
5875     {
5876 	return ipmi_entity_check_hot_swap_state(self);
5877     }
5878 
5879 }
5880 
5881 /*
5882  * A mc id object.  This object is guaranteed to be valid and
5883  * can be converted into a mc pointer later.
5884  */
5885 %extend ipmi_mcid_t {
~ipmi_mcid_t()5886     ~ipmi_mcid_t()
5887     {
5888 	free(self);
5889     }
5890 
5891     /* Compare self with other, return -1 if self<other, 0 if
5892        self==other, or 1 if self>other.  */
cmp(ipmi_mcid_t * other)5893     int cmp(ipmi_mcid_t *other)
5894     {
5895 	return ipmi_cmp_mc_id(*self, *other);
5896     }
5897 
5898     /*
5899      * Convert a mc id to a mc pointer.  The "mc_cb" method
5900      * will be called on the first parameter with the following parameters:
5901      * <self> <mc>
5902      */
to_mc(swig_cb * handler)5903     int to_mc(swig_cb *handler)
5904     {
5905 	int rv;
5906 
5907 	IPMI_SWIG_C_CB_ENTRY
5908 	if (! valid_swig_cb(handler, mc_cb))
5909 	    rv = EINVAL;
5910 	else
5911 	    rv = ipmi_mc_pointer_cb(*self, handle_mc_cb,
5912 				    get_swig_cb(handler, mc_cb));
5913 	IPMI_SWIG_C_CB_EXIT
5914 	return rv;
5915     }
5916 }
5917 
5918 /*
5919  * An MC object
5920  */
5921 %extend ipmi_mc_t {
5922     /*
5923      * Get the domain the mc belongs to.
5924      */
get_domain()5925     ipmi_domain_t *get_domain()
5926     {
5927 	return ipmi_mc_get_domain(self);
5928     }
5929 
5930     %newobject get_name;
5931     /*
5932      * Get the name of an mc.
5933      */
get_name()5934     char *get_name()
5935     {
5936 	char name[IPMI_MC_NAME_LEN];
5937 
5938 	ipmi_mc_get_name(self, name, sizeof(name));
5939 	return strdup(name);
5940     }
5941 
5942     %newobject get_id;
5943     /*
5944      * Get the id for the mc.
5945      */
get_id()5946     ipmi_mcid_t *get_id()
5947     {
5948 	ipmi_mcid_t *rv = malloc(sizeof(*rv));
5949 	if (rv)
5950 	    *rv = ipmi_mc_convert_to_id(self);
5951 	return rv;
5952     }
5953 
5954     %newobject get_guid;
5955     /*
5956      * Get the GUID for the MC.  Returns NULL if it is not supported.
5957      */
get_guid()5958     char *get_guid()
5959     {
5960 	char          *str = NULL;
5961 	unsigned char guid[16];
5962 
5963 	if (ipmi_mc_get_guid(self, guid) == 0) {
5964 	    str = malloc(16 * 3);
5965 	    if (str) {
5966 		char *s = str;
5967 		int  i;
5968 		s += sprintf(s, "%2.2x", guid[0]);
5969 		for (i=1; i<16; i++)
5970 		    s += sprintf(s, " %2.2x", guid[i]);
5971 	    }
5972 	}
5973 	return str;
5974     }
5975 
5976     /*
5977      * Get the provides_device_sdrs from the get device id response
5978      * from the MC.
5979      */
provides_device_sdrs()5980     int provides_device_sdrs()
5981     {
5982 	return ipmi_mc_provides_device_sdrs(self);
5983     }
5984 
5985     /*
5986      * Get the device_available bit from the get device id response
5987      * from the MC.
5988      */
device_available()5989     int device_available()
5990     {
5991 	return ipmi_mc_device_available(self);
5992     }
5993 
5994     /*
5995      * Get the chassis_support bit from the get device id response
5996      * from the MC.
5997      */
chassis_support()5998     int chassis_support()
5999     {
6000 	return ipmi_mc_chassis_support(self);
6001     }
6002 
6003     /*
6004      * Get the bridge_support bit from the get device id response
6005      * from the MC.
6006      */
bridge_support()6007     int bridge_support()
6008     {
6009 	return ipmi_mc_bridge_support(self);
6010     }
6011 
6012     /*
6013      * Get the ipmb_event_generator_support bit from the get device id response
6014      * from the MC.
6015      */
ipmb_event_generator_support()6016     int ipmb_event_generator_support()
6017     {
6018 	return ipmi_mc_ipmb_event_generator_support(self);
6019     }
6020 
6021     /*
6022      * Get the ipmb_event_receiver_support bit from the get device id response
6023      * from the MC.
6024      */
ipmb_event_receiver_support()6025     int ipmb_event_receiver_support()
6026     {
6027 	return ipmi_mc_ipmb_event_receiver_support(self);
6028     }
6029 
6030     /*
6031      * Get the fru_inventory_support bit from the get device id response
6032      * from the MC.
6033      */
fru_inventory_support()6034     int fru_inventory_support()
6035     {
6036 	return ipmi_mc_fru_inventory_support(self);
6037     }
6038 
6039     /*
6040      * Get the sel_device_support bit from the get device id response
6041      * from the MC.
6042      */
sel_device_support()6043     int sel_device_support()
6044     {
6045 	return ipmi_mc_sel_device_support(self);
6046     }
6047 
6048     /*
6049      * Get the sdr_repository_support bit from the get device id response
6050      * from the MC.
6051      */
sdr_repository_support()6052     int sdr_repository_support()
6053     {
6054 	return ipmi_mc_sdr_repository_support(self);
6055     }
6056 
6057     /*
6058      * Get the sensor_device_support bit from the get device id response
6059      * from the MC.
6060      */
sensor_device_support()6061     int sensor_device_support()
6062     {
6063 	return ipmi_mc_sensor_device_support(self);
6064     }
6065 
6066     /*
6067      * Get the device_id from the get device id response
6068      * from the MC.
6069      */
device_id()6070     int device_id()
6071     {
6072 	return ipmi_mc_device_id(self);
6073     }
6074 
6075     /*
6076      * Get the device_revision from the get device id response
6077      * from the MC.
6078      */
device_revision()6079     int device_revision()
6080     {
6081 	return ipmi_mc_device_revision(self);
6082     }
6083 
6084     /*
6085      * Get the major_fw_revision from the get device id response
6086      * from the MC.
6087      */
major_fw_revision()6088     int major_fw_revision()
6089     {
6090 	return ipmi_mc_major_fw_revision(self);
6091     }
6092 
6093     /*
6094      * Get the minor_fw_revision from the get device id response
6095      * from the MC.
6096      */
minor_fw_revision()6097     int minor_fw_revision()
6098     {
6099 	return ipmi_mc_minor_fw_revision(self);
6100     }
6101 
6102     /*
6103      * Get the major_version from the get device id response
6104      * from the MC.
6105      */
major_version()6106     int major_version()
6107     {
6108 	return ipmi_mc_major_version(self);
6109     }
6110 
6111     /*
6112      * Get the minor_version from the get device id response
6113      * from the MC.
6114      */
minor_version()6115     int minor_version()
6116     {
6117 	return ipmi_mc_minor_version(self);
6118     }
6119 
6120     /*
6121      * Get the manufacturer_id from the get device id response
6122      * from the MC.
6123      */
manufacturer_id()6124     int manufacturer_id()
6125     {
6126 	return ipmi_mc_manufacturer_id(self);
6127     }
6128 
6129     /*
6130      * Get the product_id from the get device id response
6131      * from the MC.
6132      */
product_id()6133     int product_id()
6134     {
6135 	return ipmi_mc_product_id(self);
6136     }
6137 
6138     /*
6139      * Get the auxiliary firmware revision.  This returns a string
6140      * with four bytes set.
6141      */
6142     %newobject aux_fw_revision;
aux_fw_revision()6143     char *aux_fw_revision()
6144     {
6145 	char *str;
6146 	unsigned char data[4];
6147 
6148 	str = malloc(28);
6149 	ipmi_mc_aux_fw_revision(self, data);
6150 	snprintf(str, 28,
6151 		 "0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x",
6152 		 data[0], data[1], data[2], data[3]);
6153 	return str;
6154     }
6155 
6156     /*
6157      * Check to see if the MC is operational in the system.  If this
6158      * is return sfalse, then the MC was referred to by an SDR, but it
6159      * doesn't really exist (at least not yet).
6160      */
is_active()6161     int is_active()
6162     {
6163 	return ipmi_mc_is_active(self);
6164     }
6165 
6166     /*
6167      * Add a handler to be called when an mc's active state
6168      * changes. When the active state changes the mc_active_cb
6169      * method on the first parameter will be called with the following
6170      * parameters: <self> <mc> <active (boolean integer)>.
6171      */
add_active_handler(swig_cb * handler)6172     int add_active_handler(swig_cb *handler)
6173     {
6174 	ipmi_mc_add_active_handler_cl
6175 	    (self, mc_active_handler_cl, NULL);
6176 	cb_add(mc, active, mc_active_cb);
6177     }
6178 
6179     /*
6180      * Remove the presence handler.
6181      */
remove_active_handler(swig_cb * handler)6182     int remove_active_handler(swig_cb *handler)
6183     {
6184 	cb_rm(mc, active, mc_active_cb);
6185     }
6186 
6187     /*
6188      * Add a handler to be called when an mc has reached fully up
6189      * status.  When this happens the mc_fully_up_cb
6190      * method on the first parameter will be called with the following
6191      * parameters: <self> <mc>.
6192      */
add_fully_up_handler(swig_cb * handler)6193     int add_fully_up_handler(swig_cb *handler)
6194     {
6195 	ipmi_mc_add_fully_up_handler_cl
6196 	    (self, mc_fully_up_handler_cl, NULL);
6197 	cb_add(mc, fully_up, mc_fully_up_cb);
6198     }
6199 
6200     /*
6201      * Remove the presence handler.
6202      */
remove_fully_up_handler(swig_cb * handler)6203     int remove_fully_up_handler(swig_cb *handler)
6204     {
6205 	cb_rm(mc, fully_up, mc_fully_up_cb);
6206     }
6207 
6208     /*
6209      * Send a command to a given MC with the given lun (parm 1), netfn
6210      * (parm 2), command (parm 3).  Parm 4 is the message data in an
6211      * array reference.  Parm 5 is the handler, it will be called with
6212      * the response.  The mc_cmd_cb method will be called on the
6213      * handler (if it is supplied); its parameters are: <mc> <netfn> <cmd>
6214      * <response data>
6215      */
6216     int send_command(int       lun,
6217 		     int       netfn,
6218 		     int       cmd,
6219 		     intarray  msg_data,
6220 		     swig_cb   *handler = NULL)
6221     {
6222 	int                        rv;
6223 	swig_cb_val                *handler_val = NULL;
6224 	ipmi_mc_response_handler_t msg_cb = NULL;
6225 	ipmi_msg_t                 msg;
6226 	unsigned char              data[MAX_IPMI_DATA_SIZE];
6227 	unsigned int               data_len;
6228 
6229 	IPMI_SWIG_C_CB_ENTRY
6230 	msg.netfn = netfn;
6231 	msg.cmd = cmd;
6232 	msg.data = data;
6233 	rv = parse_ipmi_data(msg_data, data, sizeof(data), &data_len);
6234 	msg.data_len = data_len;
6235 	if (rv)
6236 	    goto out_err;
6237 
6238 	if (!nil_swig_cb(handler)) {
6239 	    if (! valid_swig_cb(handler, mc_cmd_cb)) {
6240 		rv = EINVAL;
6241 		goto out_err;
6242 	    }
6243 	    msg_cb = mc_msg_cb;
6244 	    handler_val = ref_swig_cb(handler, mc_cmd_cb);
6245 	}
6246 	rv = ipmi_mc_send_command(self, lun, &msg, msg_cb, handler_val);
6247 	if (rv && handler_val)
6248 	    deref_swig_cb_val(handler_val);
6249     out_err:
6250 	IPMI_SWIG_C_CB_EXIT
6251 	return rv;
6252     }
6253 
6254 %constant int MC_RESET_COLD = IPMI_MC_RESET_COLD;
6255 %constant int MC_RESET_WARM = IPMI_MC_RESET_WARM;
6256     /*
6257      * Reset the MC, either a cold or warm reset depending on the
6258      * first parm.  Note that the effects of a reset are not defined
6259      * by IPMI, so this might do wierd things.  Some systems do not
6260      * support resetting the MC.  This is not a standard control
6261      * because there is no entity to hang if from and you don't want
6262      * people messing with it unless they really know what they are
6263      * doing.  When the reset is complete the mc_reset_cb will be
6264      * called on the second parameter of this call (if it is
6265      * supplied) with the following parameters: <self> <mc> <err>
6266      */
6267     int reset(int     reset_type,
6268 	      swig_cb *handler = NULL)
6269     {
6270 	swig_cb_val     *handler_val = NULL;
6271 	ipmi_mc_done_cb done = NULL;
6272 	int             rv;
6273 
6274 	IPMI_SWIG_C_CB_ENTRY
6275 	if (!nil_swig_cb(handler)) {
6276 	    if (! valid_swig_cb(handler, mc_reset_cb)) {
6277 		rv = EINVAL;
6278 		goto out_err;
6279 	    }
6280 	    handler_val = ref_swig_cb(handler, mc_reset_cb);
6281 	    done = mc_reset_handler;
6282 	}
6283 	rv = ipmi_mc_reset(self, reset_type, done, handler_val);
6284 	if (rv && handler_val)
6285 	    deref_swig_cb_val(handler_val);
6286     out_err:
6287 	IPMI_SWIG_C_CB_EXIT
6288 	return rv;
6289     }
6290 
6291     /* Get the setting to enable events for the entire MC.  The value
6292        returned by the get function is a boolean telling whether
6293        events are enabled. */
get_events_enable()6294     int get_events_enable()
6295     {
6296 	return ipmi_mc_get_events_enable(self);
6297     }
6298 
6299     /*
6300      * Set the setting to enable events for the entire MC.  The "val"
6301      * passed in as the first parameter is a boolean telling whether
6302      * to turn events on (true) or off (false).  When the operation
6303      * completes the mc_events_enable_cb will be called on the handler
6304      * (if it is supplied) with the following parameters: <self> <mc>
6305      * <err>.
6306      */
6307     int set_events_enable(int     val,
6308 			  swig_cb *handler = NULL)
6309     {
6310 	swig_cb_val     *handler_val = NULL;
6311 	ipmi_mc_done_cb done = NULL;
6312 	int             rv;
6313 
6314 	IPMI_SWIG_C_CB_ENTRY
6315 	if (!nil_swig_cb(handler)) {
6316 	    if (! valid_swig_cb(handler, mc_events_enable_cb)) {
6317 		rv = EINVAL;
6318 		goto out_err;
6319 	    }
6320 	    handler_val = ref_swig_cb(handler, mc_events_enable_cb);
6321 	    done = mc_events_enable_handler;
6322 	}
6323 	rv = ipmi_mc_set_events_enable(self, val, done, handler_val);
6324 	if (rv && handler_val)
6325 	    deref_swig_cb_val(handler_val);
6326     out_err:
6327 	IPMI_SWIG_C_CB_EXIT
6328 	return rv;
6329     }
6330 
6331     /*
6332      * Find out of the event log is enabled.  The
6333      * mc_get_event_log_enable_cb will be called on the supplied
6334      * handler with the following parms: <self> <mc> <err> <val>
6335      */
get_event_log_enable(swig_cb * handler)6336     int get_event_log_enable(swig_cb *handler)
6337     {
6338 	swig_cb_val *handler_val;
6339 	int         rv;
6340 
6341 	IPMI_SWIG_C_CB_ENTRY
6342 	if (! valid_swig_cb(handler, mc_get_event_log_enable_cb))
6343 	    rv = EINVAL;
6344 	else {
6345 	    handler_val = ref_swig_cb(handler, mc_get_event_log_enable_cb);
6346 
6347 	    rv = ipmi_mc_get_event_log_enable(self,
6348 					      mc_get_event_log_enable_handler,
6349 					      handler_val);
6350 	    if (rv)
6351 		deref_swig_cb_val(handler_val);
6352 	}
6353 	IPMI_SWIG_C_CB_EXIT
6354 	return rv;
6355     }
6356 
6357     /*
6358      * Set the MC's event log enable.  The mc_set_event_log_enable_cb
6359      * will be called on the supplied handler with the following
6360      * parms: <self> <mc> <err>
6361      */
6362     int set_event_log_enable(int val, swig_cb *handler = NULL)
6363     {
6364 	swig_cb_val     *handler_val = NULL;
6365 	ipmi_mc_done_cb done = NULL;
6366 	int             rv;
6367 
6368 	IPMI_SWIG_C_CB_ENTRY
6369 	if (!nil_swig_cb(handler)) {
6370 	    if (! valid_swig_cb(handler, mc_set_event_log_enable_cb)) {
6371 		rv = EINVAL;
6372 		goto out_err;
6373 	    }
6374 	    handler_val = ref_swig_cb(handler, mc_set_event_log_enable_cb);
6375 	    done = mc_set_event_log_enable_handler;
6376 	}
6377 	rv = ipmi_mc_set_event_log_enable(self, val, done, handler_val);
6378 	if (rv && handler_val)
6379 	    deref_swig_cb_val(handler_val);
6380     out_err:
6381 	IPMI_SWIG_C_CB_EXIT
6382 	return rv;
6383     }
6384 
6385     /*
6386      * Reread all the sensors for a given mc.  This will request the
6387      * device SDRs for that mc (And only for that MC) and change the
6388      * sensors as necessary.  When the operation completes, the
6389      * mc_reread_sensors_cb on the first parameter (if supplied) will
6390      * be called with the following parms: <self> <mc> <err>.
6391      */
6392     int reread_sensors(swig_cb *handler = NULL)
6393     {
6394 	swig_cb_val     *handler_val = NULL;
6395 	ipmi_mc_done_cb done = NULL;
6396 	int             rv;
6397 
6398 	IPMI_SWIG_C_CB_ENTRY
6399 	if (!nil_swig_cb(handler)) {
6400 	    if (! valid_swig_cb(handler, mc_reread_sensors_cb)) {
6401 		rv = EINVAL;
6402 		goto out_err;
6403 	    }
6404 	    handler_val = ref_swig_cb(handler, mc_reread_sensors_cb);
6405 	    done = mc_reread_sensors_handler;
6406 	}
6407 	rv = ipmi_mc_reread_sensors(self, done, handler_val);
6408 	if (rv && handler_val)
6409 	    deref_swig_cb_val(handler_val);
6410     out_err:
6411 	IPMI_SWIG_C_CB_EXIT
6412 	return rv;
6413     }
6414 
6415     /*
6416      * Set the time between SEL rescans for the MC (and only that MC).
6417      * Parm 1 is the time in seconds.
6418      */
set_sel_rescan_time(unsigned int seconds)6419     void set_sel_rescan_time(unsigned int seconds)
6420     {
6421 	ipmi_mc_set_sel_rescan_time(self, seconds);
6422     }
6423 
6424     /*
6425      * Return the current SEL rescan time for the MC.
6426      */
get_sel_rescan_time()6427     int get_sel_rescan_time()
6428     {
6429 	return ipmi_mc_get_sel_rescan_time(self);
6430     }
6431 
6432     /*
6433      * Reread the sel for the MC.  When the handler is called, all the
6434      * events in the SEL have been fetched into the local copy of the
6435      * SEL (with the obvious caveat that this is a distributed system
6436      * and other things may have come in after the read has finised).
6437      * When this completes, the mc_reread_sel_cb method will be called
6438      * on the handler (parm 1, if it is supplied) with the parameters:
6439      * <self> <mc> <err>.
6440      */
6441     int reread_sel(swig_cb *handler = NULL)
6442     {
6443 	swig_cb_val     *handler_val = NULL;
6444 	ipmi_mc_done_cb done = NULL;
6445 	int             rv;
6446 
6447 	IPMI_SWIG_C_CB_ENTRY
6448 	if (!nil_swig_cb(handler)) {
6449 	    if (! valid_swig_cb(handler, mc_reread_sel_cb)) {
6450 		rv = EINVAL;
6451 		goto out_err;
6452 	    }
6453 	    handler_val = ref_swig_cb(handler, mc_reread_sel_cb);
6454 	    done = mc_reread_sel_handler;
6455 	}
6456 	rv = ipmi_mc_reread_sel(self, done, handler_val);
6457 	if (rv && handler_val)
6458 	    deref_swig_cb_val(handler_val);
6459     out_err:
6460 	IPMI_SWIG_C_CB_EXIT
6461 	return rv;
6462     }
6463 
6464     /*
6465      * Fetch the current time from the SEL.  When the operation
6466      * completes, the mc_get_sel_time_cb method will be called on the
6467      * first parameter (if it is supplied) with the following
6468      * values: <self> <mc> <err> <time>
6469      */
get_current_sel_time(swig_cb * handler)6470     int get_current_sel_time(swig_cb *handler)
6471     {
6472 	swig_cb_val     *handler_val = NULL;
6473 	sel_get_time_cb done = NULL;
6474 	int             rv;
6475 
6476 	IPMI_SWIG_C_CB_ENTRY
6477 	if (!nil_swig_cb(handler)) {
6478 	    if (! valid_swig_cb(handler, mc_get_sel_time_cb)) {
6479 		rv = EINVAL;
6480 		goto out_err;
6481 	    }
6482 	    handler_val = ref_swig_cb(handler, mc_get_sel_time_cb);
6483 	    done = mc_sel_get_time_cb;
6484 	}
6485 	rv = ipmi_mc_get_current_sel_time(self, done, handler_val);
6486 	if (rv && handler_val)
6487 	    deref_swig_cb_val(handler_val);
6488     out_err:
6489 	IPMI_SWIG_C_CB_EXIT
6490 	return rv;
6491     }
6492 
6493     %newobject first_event;
6494     /*
6495      * Retrieve the first event from the MC.  Return NULL (undef)
6496      * if the event does not exist.
6497      */
first_event()6498     ipmi_event_t *first_event()
6499     {
6500 	return ipmi_mc_first_event(self);
6501     }
6502 
6503     %newobject last_event;
6504     /*
6505      * Retrieve the last event from the MC.
6506      */
last_event()6507     ipmi_event_t *last_event()
6508     {
6509 	return ipmi_mc_last_event(self);
6510     }
6511 
6512     %newobject next_event;
6513     /*
6514      * Retrieve the next event from the MC.
6515      */
next_event(ipmi_event_t * event)6516     ipmi_event_t *next_event(ipmi_event_t *event)
6517     {
6518 	return ipmi_mc_next_event(self, event);
6519     }
6520 
6521     %newobject prev_event;
6522     /*
6523      * Retrieve the previous event from the MC.
6524      */
prev_event(ipmi_event_t * event)6525     ipmi_event_t *prev_event(ipmi_event_t *event)
6526     {
6527 	return ipmi_mc_prev_event(self, event);
6528     }
6529 
6530     %newobject event_by_recid;
6531     /*
6532      * Retrieve the event with the given record id from the MC.
6533      */
event_by_recid(int record_id)6534     ipmi_event_t *event_by_recid(int record_id)
6535     {
6536 	return ipmi_mc_event_by_recid(self, record_id);
6537     }
6538 
6539     /*
6540      * The number of live items in the local copy of the MC's SEL.
6541      */
sel_count()6542     int sel_count()
6543     {
6544 	return ipmi_mc_sel_count(self);
6545     }
6546 
6547     /*
6548      * Number of entries in the the remote SEL.  If an entry has been
6549      * deleted in the local copy of the SEL but has not yet finished
6550      * being deleted in the remote copy, it will be counted here.
6551      */
sel_entries_used()6552     int sel_entries_used()
6553     {
6554 	return ipmi_mc_sel_entries_used(self);
6555     }
6556 
6557     /*
6558      * The major version of the MC's SEL.
6559      */
sel_get_major_version()6560     int sel_get_major_version()
6561     {
6562 	return ipmi_mc_sel_get_major_version(self);
6563     }
6564 
6565     /*
6566      * The minor version of the MC's SEL.
6567      */
sel_get_minor_version()6568     int sel_get_minor_version()
6569     {
6570 	return ipmi_mc_sel_get_minor_version(self);
6571     }
6572 
6573     /*
6574      * The number of entries available in the MC's SEL.
6575      */
sel_get_num_entries()6576     int sel_get_num_entries()
6577     {
6578 	return ipmi_mc_sel_get_num_entries(self);
6579     }
6580 
6581     /*
6582      * The number of free bytes available in the MC's SEL.
6583      */
sel_get_free_bytes()6584     int sel_get_free_bytes()
6585     {
6586 	return ipmi_mc_sel_get_free_bytes(self);
6587     }
6588 
6589     /*
6590      * Has an overflow occurred since the last SEL operation?
6591      */
sel_get_overflow()6592     int sel_get_overflow()
6593     {
6594 	return ipmi_mc_sel_get_overflow(self);
6595     }
6596 
6597     /*
6598      * Does the SEL support individual deletes of entries?
6599      */
sel_get_supports_delete_sel()6600     int sel_get_supports_delete_sel()
6601     {
6602 	return ipmi_mc_sel_get_supports_delete_sel(self);
6603     }
6604 
6605     /*
6606      * Does the SEL support partial adds of entries?
6607      */
sel_get_supports_partial_add_sel()6608     int sel_get_supports_partial_add_sel()
6609     {
6610 	return ipmi_mc_sel_get_supports_partial_add_sel(self);
6611     }
6612 
6613     /*
6614      * Does the SEL support the reserve protocol?
6615      */
sel_get_supports_reserve_sel()6616     int sel_get_supports_reserve_sel()
6617     {
6618 	return ipmi_mc_sel_get_supports_reserve_sel(self);
6619     }
6620 
6621     /*
6622      * Does the SEL support getting the SEL allocastion?
6623      */
sel_get_supports_get_sel_allocation()6624     int sel_get_supports_get_sel_allocation()
6625     {
6626 	return ipmi_mc_sel_get_supports_get_sel_allocation(self);
6627     }
6628 
6629     /*
6630      * The timestamp of the last time something was added to the SEL.
6631      */
sel_get_last_addition_timestamp()6632     int sel_get_last_addition_timestamp()
6633     {
6634 	return ipmi_mc_sel_get_last_addition_timestamp(self);
6635     }
6636 
6637 %constant int MAX_USED_CHANNELS = MAX_IPMI_USED_CHANNELS;
6638     /*
6639      * Get the info for a channel on the MC.  The first parm is the
6640      * integer channel number.  The second is the handler object,
6641      * the mc_channel_got_info_cb method will be called on it with the
6642      * following parameters: <self> <mc> <err> <chan_info>
6643      * where chan_info is ipmi_channel_info_t.
6644      */
channel_get_info(int channel,swig_cb * handler)6645     int channel_get_info(int channel, swig_cb *handler)
6646     {
6647 	int         rv;
6648 	swig_cb_val *handler_val = NULL;
6649 
6650 	IPMI_SWIG_C_CB_ENTRY
6651 	if (!valid_swig_cb(handler, mc_channel_got_info_cb))
6652 	    rv = EINVAL;
6653 	else {
6654 	    handler_val = ref_swig_cb(handler, mc_channel_got_info_cb);
6655 	    rv = ipmi_mc_channel_get_info(self, channel,
6656 					  mc_channel_get_info, handler_val);
6657 	    if (rv)
6658 		deref_swig_cb_val(handler_val);
6659 	}
6660 	IPMI_SWIG_C_CB_EXIT
6661 	return rv;
6662     }
6663 
6664     /*
6665      * Get the access info for a channel on the MC.  The first parm is
6666      * the integer channel number.  The second parm is the type to
6667      * set, either "volatile" or "nonvolatile".  The third is the
6668      * handler object, the mc_channel_got_access_cb method will be
6669      * called on it with the following parameters: <self> <mc> <err>
6670      * <access_info> where access_info is ipmi_channel_access_t.
6671      */
channel_get_access(int channel,char * type,swig_cb * handler)6672     int channel_get_access(int channel, char *type, swig_cb *handler)
6673     {
6674 	int                  rv;
6675 	swig_cb_val          *handler_val = NULL;
6676 	enum ipmi_set_dest_e dest;
6677 
6678 	IPMI_SWIG_C_CB_ENTRY
6679 	if (strcmp(type, "nonvolatile") == 0)
6680 	    dest = IPMI_SET_DEST_NON_VOLATILE;
6681 	else if (strcmp(type, "volatile") == 0)
6682 	    dest = IPMI_SET_DEST_VOLATILE;
6683 	else {
6684 	    rv = EINVAL;
6685 	    goto out_err;
6686 	}
6687 
6688 	if (!valid_swig_cb(handler, mc_channel_got_access_cb)) {
6689 	    rv = EINVAL;
6690 	    goto out_err;
6691 	}
6692 	handler_val = ref_swig_cb(handler, mc_channel_got_access_cb);
6693 	rv = ipmi_mc_channel_get_access(self, channel, dest,
6694 					mc_channel_get_access, handler_val);
6695 	if (rv)
6696 	    deref_swig_cb_val(handler_val);
6697     out_err:
6698 	IPMI_SWIG_C_CB_EXIT
6699 	return rv;
6700     }
6701 
6702     /*
6703      * Set the access info for a channel on the MC, generally from one
6704      * that you have previously fetched.  The first parameter is the
6705      * access object you with to set the channel to.  The second parm
6706      * is the integer channel number.  The third parm is the type to
6707      * set, either "volatile" or "nonvolatile".  The forth is the
6708      * handler object, the mc_channel_set_access_cb method will be
6709      * called on it with the following parameters: <self> <mc> <err>.
6710      */
6711     int channel_set_access(ipmi_channel_access_t *access,
6712 			   int                   channel,
6713 			   char                  *type,
6714 			   swig_cb               *handler = NULL)
6715     {
6716 	int                  rv;
6717 	swig_cb_val          *handler_val = NULL;
6718 	ipmi_mc_done_cb      done = NULL;
6719 	enum ipmi_set_dest_e dest;
6720 
6721 	IPMI_SWIG_C_CB_ENTRY
6722 	if (strcmp(type, "nonvolatile") == 0)
6723 	    dest = IPMI_SET_DEST_NON_VOLATILE;
6724 	else if (strcmp(type, "volatile") == 0)
6725 	    dest = IPMI_SET_DEST_VOLATILE;
6726 	else {
6727 	    rv = EINVAL;
6728 	    goto out_err;
6729 	}
6730 
6731 	if (!nil_swig_cb(handler)) {
6732 	    if (!valid_swig_cb(handler, mc_channel_set_access_cb)) {
6733 		rv = EINVAL;
6734 		goto out_err;
6735 	    }
6736 	    handler_val = ref_swig_cb(handler, mc_channel_set_access_cb);
6737 	    done = mc_channel_set_access;
6738 	}
6739 	rv = ipmi_mc_channel_set_access(self, channel, dest, access,
6740 					done, handler_val);
6741 	if (rv)
6742 	    deref_swig_cb_val(handler_val);
6743     out_err:
6744 	IPMI_SWIG_C_CB_EXIT
6745 	return rv;
6746     }
6747 
6748     /*
6749      * Get the user info for a channel on the MC.  The first parameter
6750      * is the channel.  The second is the user number; if a valid user
6751      * number is passed in, then that user is the only one fetched.
6752      * If 0 is passed for the user number, then all users are
6753      * fetched.  The third is the handler object, the
6754      * mc_channel_got_users_cb method will be called on it with the
6755      * following parameters: <self> <mc> <err> <max users>
6756      * <enabled users> <fixed users> <user1> [<user2> ...]
6757      * where the users are ipmi_user_t objects.
6758      */
get_users(int channel,int user,swig_cb * handler)6759     int get_users(int channel, int user, swig_cb *handler)
6760     {
6761 	int         rv;
6762 	swig_cb_val *handler_val;
6763 
6764 	IPMI_SWIG_C_CB_ENTRY
6765 	if (!valid_swig_cb(handler, mc_channel_got_users_cb))
6766 	    rv = EINVAL;
6767 	else {
6768 	    handler_val = ref_swig_cb(handler, mc_channel_got_users_cb);
6769 	    rv = ipmi_mc_get_users(self, channel, user,
6770 				   mc_channel_got_users, handler_val);
6771 	    if (rv)
6772 		deref_swig_cb_val(handler_val);
6773 	}
6774 	IPMI_SWIG_C_CB_EXIT
6775 	return rv;
6776     }
6777 
6778     /*
6779      * Set the user info for a channel on the MC.  The first parameter
6780      * is the ipmi_user_t object.  The second parameter is the
6781      * channel.  The third is the user number; if a valid user number
6782      * is passed in, then that user is the only one fetched.  The
6783      * fourth is the handler object, the mc_channel_set_user_cb
6784      * method will be called on it with the following parameters:
6785      * <self> <mc> <err>.  Note that some info is channel-specific.
6786      * Just the name and password and enable are global to the MC.
6787      */
6788     int set_user(ipmi_user_t *userinfo,
6789 		 int         channel,
6790 		 int         usernum,
6791 		 swig_cb     *handler = NULL)
6792     {
6793 	int             rv;
6794 	swig_cb_val     *handler_val = NULL;
6795 	ipmi_mc_done_cb done = NULL;
6796 
6797 	IPMI_SWIG_C_CB_ENTRY
6798 	if (!nil_swig_cb(handler)) {
6799 	    if (! valid_swig_cb(handler, mc_channel_set_user_cb)) {
6800 		rv = EINVAL;
6801 		goto out_err;
6802 	    }
6803 	    handler_val = ref_swig_cb(handler, mc_channel_set_user_cb);
6804 	    done = mc_channel_set_user;
6805 	}
6806 	rv = ipmi_mc_set_user(self, channel, usernum, userinfo,
6807 			      done, handler_val);
6808 	if (rv && handler_val)
6809 	    deref_swig_cb_val(handler_val);
6810     out_err:
6811 	IPMI_SWIG_C_CB_EXIT
6812 	return rv;
6813     }
6814 
6815     /*
6816      * Allocate a lanparm object for the MC.  The channel is the first
6817      * parameter, the lanparm is returned.
6818      */
6819     %newobject get_lanparm;
get_lanparm(int channel)6820     ipmi_lanparm_t *get_lanparm(int channel)
6821     {
6822 	int            rv;
6823 	ipmi_lanparm_t *lp;
6824 
6825 	rv = ipmi_lanparm_alloc(self, channel, &lp);
6826 	if (rv)
6827 	    return NULL;
6828 	return lp;
6829     }
6830 
6831     /*
6832      * Allocate a pef object for the MC.  The pef object is returned.
6833      * The first parameter is an optional callback object, the
6834      * got_pef_cb method will be called on it when the PEF fetch is
6835      * complete.  It will have the following parameters: <self> <pef>
6836      * <err>.  Note that you cannot use the PEF until the fetch is
6837      * complete.
6838      */
6839     %newobject get_pef;
6840     ipmi_pef_t *get_pef(swig_cb *handler = NULL)
6841     {
6842 	int              rv;
6843 	ipmi_pef_t       *pef = NULL;
6844 	swig_cb_val      *handler_val = NULL;
6845 	ipmi_pef_done_cb done = NULL;
6846 
6847 	IPMI_SWIG_C_CB_ENTRY
6848 	if (!nil_swig_cb(handler)) {
6849 	    if (!valid_swig_cb(handler, got_pef_cb))
6850 		goto out_err;
6851 	    handler_val = ref_swig_cb(handler, got_pef_cb);
6852 	    done = get_pef;
6853 	}
6854 	rv = ipmi_pef_alloc(self, done, handler_val, &pef);
6855 	if (rv && handler_val)
6856 	    deref_swig_cb_val(handler_val);
6857     out_err:
6858 	IPMI_SWIG_C_CB_EXIT
6859 	return pef;
6860     }
6861 
6862     /*
6863      * Allocate a pet object for the MC.  The pet is returned.  The
6864      * eighth parameter is an optional callback object, the got_pet_cb
6865      * method will be called on it when the PET fetch is complete.  It
6866      * will have the following parameters: <self> <pet> <err>.
6867      * The parameters are:
6868      *   int channel: the channel number to set the PET for
6869      *   char ip_addr: the address to send the traps to
6870      *   char mac_addr: the mac address to send the traps to
6871      * The rest are the selectors in the various tables, you have to
6872      * read the spec and know your system to know how to set them.
6873      *   int eft_sel:
6874      *   int policy_num:
6875      *   int apt_sel:
6876      *   int lan_dest_sel:
6877      *
6878      * Note that you must keep a reference to the pet around, or it will
6879      * be automatically destroyed by the garbage collector.
6880      */
6881     %newobject get_pet;
6882     ipmi_pet_t *get_pet(int     channel,
6883 			char    *ip_addr,
6884 			char    *mac_addr,
6885 			int     eft_sel,
6886 			int     policy_num,
6887 			int     apt_sel,
6888 			int     lan_dest_sel,
6889 			swig_cb *handler = NULL)
6890     {
6891 	int              rv;
6892 	ipmi_pet_t       *pet = NULL;
6893 	swig_cb_val      *handler_val = NULL;
6894 	struct in_addr   ip;
6895 	unsigned char    mac[6];
6896 	ipmi_pet_done_cb done = NULL;
6897 
6898 	IPMI_SWIG_C_CB_ENTRY
6899         rv = parse_ip_addr(ip_addr, &ip);
6900 	if (rv)
6901 	    goto out_err;
6902 
6903         rv = parse_mac_addr(mac_addr, mac);
6904 	if (rv)
6905 	    goto out_err;
6906 
6907 	if (!nil_swig_cb(handler)) {
6908 	    if (!valid_swig_cb(handler, got_pet_cb))
6909 		goto out_err;
6910 	    handler_val = ref_swig_cb(handler, got_pet_cb);
6911 	    done = get_pet;
6912 	}
6913 	rv = ipmi_pet_create_mc(self, channel, ip, mac, eft_sel, policy_num,
6914 				apt_sel, lan_dest_sel, done, handler_val,
6915 				&pet);
6916 	if (rv && handler_val)
6917 	    deref_swig_cb_val(handler_val);
6918     out_err:
6919 	IPMI_SWIG_C_CB_EXIT
6920 	return pet;
6921     }
6922 
6923     /*
6924      * Allocate a solparm object for the MC.  The channel is the first
6925      * parameter, the solparm is returned.
6926      */
6927     %newobject get_solparm;
get_solparm(int channel)6928     ipmi_solparm_t *get_solparm(int channel)
6929     {
6930 	int            rv;
6931 	ipmi_solparm_t *lp;
6932 
6933 	rv = ipmi_solparm_alloc(self, channel, &lp);
6934 	if (rv)
6935 	    return NULL;
6936 	return lp;
6937     }
6938 }
6939 
6940 %extend ipmi_channel_info_t {
~ipmi_channel_info_t()6941     ~ipmi_channel_info_t()
6942     {
6943 	ipmi_channel_info_free(self);
6944     }
6945 
6946     %newobject copy;
copy()6947     ipmi_channel_info_t *copy()
6948     {
6949 	return ipmi_channel_info_copy(self);
6950     }
6951 
get_channel(int * channel)6952     int get_channel(int *channel)
6953     {
6954 	unsigned int val;
6955 	int rv = ipmi_channel_info_get_channel(self, &val);
6956 	*channel = val;
6957 	return rv;
6958     }
6959 
6960 %constant int CHANNEL_MEDIUM_IPMB = IPMI_CHANNEL_MEDIUM_IPMB;
6961 %constant int CHANNEL_MEDIUM_ICMB_V10 = IPMI_CHANNEL_MEDIUM_ICMB_V10;
6962 %constant int CHANNEL_MEDIUM_ICMB_V09 = IPMI_CHANNEL_MEDIUM_ICMB_V09;
6963 %constant int CHANNEL_MEDIUM_8023_LAN = IPMI_CHANNEL_MEDIUM_8023_LAN;
6964 %constant int CHANNEL_MEDIUM_RS232 = IPMI_CHANNEL_MEDIUM_RS232;
6965 %constant int CHANNEL_MEDIUM_OTHER_LAN = IPMI_CHANNEL_MEDIUM_OTHER_LAN;
6966     %constant int CHANNEL_MEDIUM_PCI_SMBUS = IPMI_CHANNEL_MEDIUM_PCI_SMBUS;
6967 %constant int CHANNEL_MEDIUM_SMBUS_v1 = IPMI_CHANNEL_MEDIUM_SMBUS_v1;
6968 %constant int CHANNEL_MEDIUM_SMBUS_v2 = IPMI_CHANNEL_MEDIUM_SMBUS_v2;
6969 %constant int CHANNEL_MEDIUM_USB_v1 = IPMI_CHANNEL_MEDIUM_USB_v1;
6970 %constant int CHANNEL_MEDIUM_USB_v2 = IPMI_CHANNEL_MEDIUM_USB_v2;
6971 %constant int CHANNEL_MEDIUM_SYS_INTF = IPMI_CHANNEL_MEDIUM_SYS_INTF;
get_medium(int * medium)6972     int get_medium(int *medium)
6973     {
6974 	unsigned int val;
6975 	int rv = ipmi_channel_info_get_medium(self, &val);
6976 	*medium = val;
6977 	return rv;
6978     }
6979 
6980 %constant int CHANNEL_PROTOCOL_IPMB = IPMI_CHANNEL_PROTOCOL_IPMB;
6981 %constant int CHANNEL_PROTOCOL_ICMB = IPMI_CHANNEL_PROTOCOL_ICMB;
6982 %constant int CHANNEL_PROTOCOL_SMBus = IPMI_CHANNEL_PROTOCOL_SMBus;
6983 %constant int CHANNEL_PROTOCOL_KCS = IPMI_CHANNEL_PROTOCOL_KCS;
6984 %constant int CHANNEL_PROTOCOL_SMIC = IPMI_CHANNEL_PROTOCOL_SMIC;
6985 %constant int CHANNEL_PROTOCOL_BT_v10 = IPMI_CHANNEL_PROTOCOL_BT_v10;
6986 %constant int CHANNEL_PROTOCOL_BT_v15 = IPMI_CHANNEL_PROTOCOL_BT_v15;
6987 %constant int CHANNEL_PROTOCOL_TMODE = IPMI_CHANNEL_PROTOCOL_TMODE;
get_protocol_type(int * prot_type)6988     int get_protocol_type(int *prot_type)
6989     {
6990 	unsigned int val;
6991 	int rv = ipmi_channel_info_get_protocol_type(self, &val);
6992 	*prot_type = val;
6993 	return rv;
6994     }
6995 
6996 
6997 %constant int CHANNEL_SESSION_LESS = IPMI_CHANNEL_SESSION_LESS;
6998 %constant int CHANNEL_SINGLE_SESSION = IPMI_CHANNEL_SINGLE_SESSION;
6999 %constant int CHANNEL_MULTI_SESSION = IPMI_CHANNEL_MULTI_SESSION;
7000 %constant int CHANNEL_SESSION_BASED = IPMI_CHANNEL_SESSION_BASED;
get_session_support(int * sup)7001     int get_session_support(int *sup)
7002     {
7003 	unsigned int val;
7004 	int rv = ipmi_channel_info_get_session_support(self, &val);
7005 	*sup = val;
7006 	return rv;
7007     }
7008 
7009     /* Data is 3 bytes long */
7010     %newobject get_vendor_id;
get_vendor_id()7011     char *get_vendor_id()
7012     {
7013 	unsigned char data[3];
7014 	int           rv;
7015 	char          *rdata = malloc(15);
7016 
7017 	if (!rdata)
7018 	    return NULL;
7019 	rv = ipmi_channel_info_get_vendor_id(self, data);
7020 	if (rv)
7021 	    return NULL;
7022 	sprintf(rdata, "0x%2.2x 0x%2.2x 0x%2.2x", data[0], data[1], data[2]);
7023 	return rdata;
7024     }
7025 
7026     /* Data is 2 bytes long */
7027     %newobject get_aux_info;
get_aux_info()7028     char *get_aux_info()
7029     {
7030 	unsigned char data[2];
7031 	int           rv;
7032 	char          *rdata = malloc(10);
7033 
7034 	if (!rdata)
7035 	    return NULL;
7036 	rv = ipmi_channel_info_get_aux_info(self, data);
7037 	if (rv)
7038 	    return NULL;
7039 	sprintf(rdata, "0x%2.2x 0x%2.2x", data[0], data[1]);
7040 	return rdata;
7041     }
7042 }
7043 
7044 %extend ipmi_channel_access_t {
~ipmi_channel_access_t()7045     ~ipmi_channel_access_t()
7046     {
7047 	ipmi_channel_access_free(self);
7048     }
7049 
7050     %newobject copy;
copy()7051     ipmi_channel_access_t *copy()
7052     {
7053 	return ipmi_channel_access_copy(self);
7054     }
7055 
get_channel(int * channel)7056     int get_channel(int *channel)
7057     {
7058 	unsigned int val;
7059 	int rv = ipmi_channel_access_get_channel(self, &val);
7060 	*channel = val;
7061 	return rv;
7062     }
7063 
get_alerting_enabled(int * enab)7064     int get_alerting_enabled(int *enab)
7065     {
7066 	unsigned int val;
7067 	int rv = ipmi_channel_access_get_alerting_enabled(self, &val);
7068 	*enab = val;
7069 	return rv;
7070     }
7071 
set_alerting_enabled(int enab)7072     int set_alerting_enabled(int enab)
7073     {
7074 	return ipmi_channel_access_set_alerting_enabled(self, enab);
7075     }
7076 
get_per_msg_auth(int * msg_auth)7077     int get_per_msg_auth(int *msg_auth)
7078     {
7079 	unsigned int val;
7080 	int rv = ipmi_channel_access_get_per_msg_auth(self, &val);
7081 	*msg_auth = val;
7082 	return rv;
7083     }
7084 
set_per_msg_auth(int msg_auth)7085     int set_per_msg_auth(int msg_auth)
7086     {
7087 	return ipmi_channel_access_set_per_msg_auth(self, msg_auth);
7088     }
7089 
get_user_auth(int * user_auth)7090     int get_user_auth(int *user_auth)
7091     {
7092 	unsigned int val;
7093 	int rv = ipmi_channel_access_get_user_auth(self, &val);
7094 	*user_auth = val;
7095 	return rv;
7096     }
7097 
set_user_auth(int user_auth)7098     int set_user_auth(int user_auth)
7099     {
7100 	return ipmi_channel_access_set_user_auth(self, user_auth);
7101     }
7102 
7103 %constant int CHANNEL_ACCESS_MODE_DISABLED = IPMI_CHANNEL_ACCESS_MODE_DISABLED;
7104 %constant int CHANNEL_ACCESS_MODE_PRE_BOOT = IPMI_CHANNEL_ACCESS_MODE_PRE_BOOT;
7105 %constant int CHANNEL_ACCESS_MODE_ALWAYS = IPMI_CHANNEL_ACCESS_MODE_ALWAYS;
7106 %constant int CHANNEL_ACCESS_MODE_SHARED = IPMI_CHANNEL_ACCESS_MODE_SHARED;
get_access_mode(int * access_mode)7107     int get_access_mode(int *access_mode)
7108     {
7109 	unsigned int val;
7110 	int rv = ipmi_channel_access_get_access_mode(self, &val);
7111 	*access_mode = val;
7112 	return rv;
7113     }
7114 
set_access_mode(int access_mode)7115     int set_access_mode(int access_mode)
7116     {
7117 	return ipmi_channel_access_set_access_mode(self, access_mode);
7118     }
7119 
7120 %constant int PRIVILEGE_CALLBACK = IPMI_PRIVILEGE_CALLBACK;
7121 %constant int PRIVILEGE_USER = IPMI_PRIVILEGE_USER;
7122 %constant int PRIVILEGE_OPERATOR = IPMI_PRIVILEGE_OPERATOR;
7123 %constant int PRIVILEGE_ADMIN = IPMI_PRIVILEGE_ADMIN;
7124 %constant int PRIVILEGE_OEM = IPMI_PRIVILEGE_OEM;
get_privilege_limit(int * priv_limit)7125     int get_privilege_limit(int *priv_limit)
7126     {
7127 	unsigned int val;
7128 	int rv = ipmi_channel_access_get_priv_limit(self, &val);
7129 	*priv_limit = val;
7130 	return rv;
7131     }
7132 
set_privilege_limit(int priv_limit)7133     int set_privilege_limit(int priv_limit)
7134     {
7135 	return ipmi_channel_access_set_priv_limit(self, priv_limit);
7136     }
7137 
7138     /* Normally setting will only set the values you have changed.  This
7139        forces all the values to be set. */
setall()7140     int setall() {
7141 	return ipmi_channel_access_setall(self);
7142     }
7143 }
7144 
7145 %extend ipmi_user_t {
~ipmi_user_t()7146     ~ipmi_user_t()
7147     {
7148 	ipmi_user_free(self);
7149     }
7150 
7151     %newobject copy;
copy()7152     ipmi_user_t *copy()
7153     {
7154 	return ipmi_user_copy(self);
7155     }
7156 
get_channel(int * channel)7157     int get_channel(int *channel)
7158     {
7159 	unsigned int val;
7160 	int rv = ipmi_user_get_channel(self, &val);
7161 	*channel = val;
7162 	return rv;
7163     }
7164 
get_num(int * num)7165     int get_num(int *num)
7166     {
7167 	unsigned int val;
7168 	int rv = ipmi_user_get_num(self, &val);
7169 	*num = val;
7170 	return rv;
7171     }
7172 
set_num(int num)7173     int set_num(int num)
7174     {
7175 	return ipmi_user_set_num(self, num);
7176     }
7177 
get_name()7178     char *get_name()
7179     {
7180 	unsigned int len;
7181 	int rv;
7182 	char *name;
7183 
7184 	rv = ipmi_user_get_name_len(self, &len);
7185 	if (rv)
7186 	    return NULL;
7187 	name = malloc(len+1);
7188 	if (!name)
7189 	    return NULL;
7190 	rv = ipmi_user_get_name(self, name, &len);
7191 	if (rv) {
7192 	    free(name);
7193 	    return NULL;
7194 	}
7195 	return name;
7196     }
7197 
set_name(char * name)7198     int set_name(char *name)
7199     {
7200 	return ipmi_user_set_name(self, name, strlen(name));
7201     }
7202 
set_password(char * pw)7203     int set_password(char *pw)
7204     {
7205 	return ipmi_user_set_password(self, pw, strlen(pw));
7206     }
7207 
set_password2(char * pw)7208     int set_password2(char *pw)
7209     {
7210 	return ipmi_user_set_password2(self, pw, strlen(pw));
7211     }
7212 
7213     /* Set the password, using either set_password or set_password2,
7214        depending on the length of the password. */
set_password_auto(char * pw)7215     int set_password_auto(char *pw)
7216     {
7217 	if (strlen(pw) > 16)
7218 	    return ipmi_user_set_password2(self, pw, strlen(pw));
7219 	else
7220 	    return ipmi_user_set_password(self, pw, strlen(pw));
7221     }
7222 
get_enable(int * enable)7223     int get_enable(int *enable)
7224     {
7225 	unsigned int val;
7226 	int rv = ipmi_user_get_enable(self, &val);
7227 	*enable = val;
7228 	return rv;
7229     }
7230 
set_enable(int val)7231     int set_enable(int val)
7232     {
7233 	return ipmi_user_set_enable(self, val);
7234     }
7235 
get_link_auth_enabled(int * enable)7236     int get_link_auth_enabled(int *enable)
7237     {
7238 	unsigned int val;
7239 	int rv = ipmi_user_get_link_auth_enabled(self, &val);
7240 	*enable = val;
7241 	return rv;
7242     }
7243 
set_link_auth_enabled(int val)7244     int set_link_auth_enabled(int val)
7245     {
7246 	return ipmi_user_set_link_auth_enabled(self, val);
7247     }
7248 
get_msg_auth_enabled(int * enable)7249     int get_msg_auth_enabled(int *enable)
7250     {
7251 	unsigned int val;
7252 	int rv = ipmi_user_get_msg_auth_enabled(self, &val);
7253 	*enable = val;
7254 	return rv;
7255     }
7256 
set_msg_auth_enabled(int val)7257     int set_msg_auth_enabled(int val)
7258     {
7259 	return ipmi_user_set_msg_auth_enabled(self, val);
7260     }
7261 
get_access_cb_only(int * cb)7262     int get_access_cb_only(int *cb)
7263     {
7264 	unsigned int val;
7265 	int rv = ipmi_user_get_access_cb_only(self, &val);
7266 	*cb = val;
7267 	return rv;
7268     }
7269 
set_access_cb_only(int val)7270     int set_access_cb_only(int val)
7271     {
7272 	return ipmi_user_set_access_cb_only(self, val);
7273     }
7274 
get_privilege_limit(int * limit)7275     int get_privilege_limit(int *limit)
7276     {
7277 	unsigned int val;
7278 	int rv = ipmi_user_get_privilege_limit(self, &val);
7279 	*limit = val;
7280 	return rv;
7281     }
7282 
set_privilege_limit(int val)7283     int set_privilege_limit(int val)
7284     {
7285 	return ipmi_user_set_privilege_limit(self, val);
7286     }
7287 
get_session_limit(int * limit)7288     int get_session_limit(int *limit)
7289     {
7290 	unsigned int val;
7291 	int rv = ipmi_user_get_session_limit(self, &val);
7292 	*limit = val;
7293 	return rv;
7294     }
7295 
set_session_limit(int val)7296     int set_session_limit(int val)
7297     {
7298 	return ipmi_user_set_session_limit(self, val);
7299     }
7300 
set_all()7301     int set_all()
7302     {
7303 	return ipmi_user_set_all(self);
7304     }
7305 }
7306 
7307 /*
7308  * A sensor id object.  This object is guaranteed to be valid and
7309  * can be converted into a mc pointer later.
7310  */
7311 %extend ipmi_sensor_id_t {
~ipmi_sensor_id_t()7312     ~ipmi_sensor_id_t()
7313     {
7314 	free(self);
7315     }
7316 
7317     /* Compare self with other, return -1 if self<other, 0 if
7318        self==other, or 1 if self>other.  */
cmp(ipmi_sensor_id_t * other)7319     int cmp(ipmi_sensor_id_t *other)
7320     {
7321 	return ipmi_cmp_sensor_id(*self, *other);
7322     }
7323 
7324     /*
7325      * Convert a sensor id to a sensor pointer.  The "sensor_cb" method
7326      * will be called on the first parameter with the following parameters:
7327      * <self> <sensor>
7328      */
to_sensor(swig_cb * handler)7329     int to_sensor(swig_cb *handler)
7330     {
7331 	int rv;
7332 
7333 	IPMI_SWIG_C_CB_ENTRY
7334 	if (! valid_swig_cb(handler, sensor_cb))
7335 	    rv = EINVAL;
7336 	else
7337 	    rv = ipmi_sensor_pointer_cb(*self, handle_sensor_cb,
7338 					get_swig_cb(handler, sensor_cb));
7339 	IPMI_SWIG_C_CB_EXIT
7340 	return rv;
7341     }
7342 }
7343 
7344 /*
7345  * An sensor object.  Sensor operations take several different types
7346  * of objects.  These are mostly strings that are a list of values.
7347  *
7348  * Event states are represented as a string with value separated by
7349  * spaces.  These value are settings and the events.  The strings
7350  * "events", "scanning", and "busy" are settings for the full sensor
7351  * event states.  For threshold sensor, the other values in the string
7352  * are 4 characters with: 1st character: u for upper or l for lower.
7353  * 2nd character: n for non-critical, c for critical, and r for
7354  * non-recoverable.  3rd character: h for going high and l for going
7355  * low.  4th character: a for assertion and d for deassertion.  For
7356  * discrete sensors, the other values are a 1 or 2-digit number
7357  * representing the offset and then a for assertion and d for
7358  * deassertion.
7359  *
7360  * A states structure is similar to event status, but does not have
7361  * the last two characters (direction and assertion) for thresholds
7362  * and last chararacter (assertion) for discrete values.
7363  */
7364 %extend ipmi_sensor_t {
7365     %newobject get_name;
7366     /*
7367      * Get the name of an sensor.
7368      */
get_name()7369     char *get_name()
7370     {
7371 	char name[IPMI_SENSOR_NAME_LEN];
7372 
7373 	ipmi_sensor_get_name(self, name, sizeof(name));
7374 	return strdup(name);
7375     }
7376 
7377     %newobject get_id;
7378     /*
7379      * Get the id for the sensor.
7380      */
get_id()7381     ipmi_sensor_id_t *get_id()
7382     {
7383 	ipmi_sensor_id_t *rv = malloc(sizeof(*rv));
7384 	if (rv)
7385 	    *rv = ipmi_sensor_convert_to_id(self);
7386 	return rv;
7387     }
7388 
7389     /*
7390      * Register a handler to be called when an event comes from the
7391      * sensor.  If the sensor is a threshold sensor, the
7392      * threshold_event_cb method will be called on the sensor.
7393      * Otherwise, the sensor is discrete and the discrete_event_cb
7394      * will be called.  The threshold_event_cb method takes the
7395      * following parameters:
7396      * <self> <sensor> <event spec> <raw_set> <raw> <value_set> <value> <event>
7397      * The discrete_event_cb method takes the following parameters:
7398      * <self> <sensor> <event spec> <severity> <old_severity> <event>
7399      */
add_event_handler(swig_cb * handler)7400     int add_event_handler(swig_cb *handler)
7401     {
7402 	if (ipmi_sensor_get_event_reading_type(self)
7403 	    == IPMI_EVENT_READING_TYPE_THRESHOLD)
7404 	{
7405 	    ipmi_sensor_add_threshold_event_handler_cl
7406 		(self, sensor_threshold_event_handler_cl, NULL);
7407 	    cb_add(sensor, threshold_event, threshold_event_cb);
7408 	} else {
7409 	    ipmi_sensor_add_discrete_event_handler_cl
7410 		(self, sensor_discrete_event_handler_cl, NULL);
7411 	    cb_add(sensor, discrete_event, discrete_event_cb);
7412 	}
7413     }
7414 
7415     /*
7416      * Remove the event handler from the sensor
7417      */
remove_event_handler(swig_cb * handler)7418     int remove_event_handler(swig_cb *handler)
7419     {
7420 	if (ipmi_sensor_get_event_reading_type(self)
7421 	    == IPMI_EVENT_READING_TYPE_THRESHOLD)
7422 	{
7423 	    cb_rm(sensor, threshold_event, threshold_event_cb);
7424 	} else {
7425 	    cb_rm(sensor, discrete_event, discrete_event_cb);
7426 	}
7427     }
7428 
7429     /* Set the event enables for the given sensor to exactly the event
7430      * states given in the first parameter.  This will first enable
7431      * the events/thresholds that are set, then disable the
7432      * events/thresholds that are not set.  When the operation is
7433      * done, the sensor_event_enable_cb method on the second parm (if
7434      * it is supplied) will be called with the following parameters:
7435      * <self> <sensor> <err>
7436      */
7437     int set_event_enables(char *states, swig_cb *handler = NULL)
7438     {
7439 	int                 rv;
7440 	swig_cb_val         *handler_val = NULL;
7441 	ipmi_sensor_done_cb sensor_cb = NULL;
7442 	ipmi_event_state_t  *st;
7443 
7444 	IPMI_SWIG_C_CB_ENTRY
7445 	if (ipmi_sensor_get_event_reading_type(self)
7446 	    == IPMI_EVENT_READING_TYPE_THRESHOLD)
7447 	{
7448 	    rv = str_to_threshold_event_state(states, &st);
7449 	} else {
7450 	    rv = str_to_discrete_event_state(states, &st);
7451 	}
7452 	if (rv)
7453 	    goto out_err;
7454 	if (!nil_swig_cb(handler)) {
7455 	    if (! valid_swig_cb(handler, sensor_event_enable_cb)) {
7456 		rv = EINVAL;
7457 		goto out_err;
7458 	    }
7459 	    sensor_cb = sensor_event_enable_handler;
7460 	    handler_val = ref_swig_cb(handler, sensor_event_enable_cb);
7461 	}
7462 	rv = ipmi_sensor_set_event_enables(self, st, sensor_cb, handler_val);
7463 	if (rv && handler_val)
7464 	    deref_swig_cb_val(handler_val);
7465 	free(st);
7466     out_err:
7467 	IPMI_SWIG_C_CB_EXIT
7468 	return rv;
7469     }
7470 
7471     /*
7472      * Enable the event states that are set in the first parameter.
7473      * This will *only* enable those states, it will not disable any
7474      * states.  It will, however, set the "events" flag and the
7475      * "scanning" flag for the sensor to the value in the states
7476      * parameter.  When the operation is done, the
7477      * sensor_event_enable_cb method on the second parm (if it is
7478      * supplied) will be called with the following parameters: <self>
7479      * <sensor> <err>
7480      */
7481     int enable_events(char *states, swig_cb *handler = NULL)
7482     {
7483 	int                 rv;
7484 	swig_cb_val         *handler_val = NULL;
7485 	ipmi_sensor_done_cb sensor_cb = NULL;
7486 	ipmi_event_state_t  *st;
7487 
7488 	IPMI_SWIG_C_CB_ENTRY
7489 	if (ipmi_sensor_get_event_reading_type(self)
7490 	    == IPMI_EVENT_READING_TYPE_THRESHOLD)
7491 	{
7492 	    rv = str_to_threshold_event_state(states, &st);
7493 	} else {
7494 	    rv = str_to_discrete_event_state(states, &st);
7495 	}
7496 	if (rv)
7497 	    goto out_err;
7498 	if (!nil_swig_cb(handler)) {
7499 	    if (! valid_swig_cb(handler, sensor_event_enable_cb)) {
7500 		rv = EINVAL;
7501 		goto out_err;
7502 	    }
7503 	    sensor_cb = sensor_event_enable_handler;
7504 	    handler_val = ref_swig_cb(handler, sensor_event_enable_cb);
7505 	}
7506 	rv = ipmi_sensor_enable_events(self, st, sensor_cb, handler_val);
7507 	if (rv && handler_val)
7508 	    deref_swig_cb_val(handler_val);
7509 	free(st);
7510     out_err:
7511 	IPMI_SWIG_C_CB_EXIT
7512 	return rv;
7513     }
7514 
7515     /*
7516      * Disable the event states that are set in the first parameter.
7517      * This will *only* disable those states, it will not enable any
7518      * states.  It will, however, set the "events" flag and the
7519      * "scanning" flag for the sensor to the value in the states
7520      * parameter.  When the operation is done, the
7521      * sensor_event_enable_cb method on the second parm (if it is
7522      * supplied) will be called with the following parameters: <self>
7523      * <sensor> <err>
7524      */
7525     int disable_events(char *states, swig_cb *handler = NULL)
7526     {
7527 	int                 rv;
7528 	swig_cb_val         *handler_val = NULL;
7529 	ipmi_sensor_done_cb sensor_cb = NULL;
7530 	ipmi_event_state_t  *st;
7531 
7532 	IPMI_SWIG_C_CB_ENTRY
7533 	if (ipmi_sensor_get_event_reading_type(self)
7534 	    == IPMI_EVENT_READING_TYPE_THRESHOLD)
7535 	{
7536 	    rv = str_to_threshold_event_state(states, &st);
7537 	} else {
7538 	    rv = str_to_discrete_event_state(states, &st);
7539 	}
7540 	if (rv)
7541 	    goto out_err;
7542 	if (!nil_swig_cb(handler)) {
7543 	    if (! valid_swig_cb(handler, sensor_event_enable_cb)) {
7544 		free(st);
7545 		rv = EINVAL;
7546 		goto out_err;
7547 	    }
7548 	    sensor_cb = sensor_event_enable_handler;
7549 	    handler_val = ref_swig_cb(handler, sensor_event_enable_cb);
7550 	}
7551 	rv = ipmi_sensor_disable_events(self, st, sensor_cb, handler_val);
7552 	if (rv && handler_val)
7553 	    deref_swig_cb_val(handler_val);
7554 	free(st);
7555     out_err:
7556 	IPMI_SWIG_C_CB_EXIT
7557 	return rv;
7558     }
7559 
7560     /*
7561      * Get the event enables for the given sensor.  When done, the
7562      * sensor_get_event_enable_cb method on the first parameter will
7563      * be called with the following parameters: <self> <sensor> <err>
7564      * <event states>
7565      */
get_event_enables(swig_cb * handler)7566     int get_event_enables(swig_cb *handler)
7567     {
7568 	int                          rv;
7569 	swig_cb_val                  *handler_val = NULL;
7570 	ipmi_sensor_event_enables_cb sensor_cb = NULL;
7571 
7572 	IPMI_SWIG_C_CB_ENTRY
7573 	if (!valid_swig_cb(handler, sensor_get_event_enable_cb))
7574 	    rv = EINVAL;
7575 	else {
7576 	    sensor_cb = sensor_get_event_enables_handler;
7577 	    handler_val = ref_swig_cb(handler, sensor_get_event_enable_cb);
7578 	    rv = ipmi_sensor_get_event_enables(self, sensor_cb, handler_val);
7579 	    if (rv && handler_val)
7580 		deref_swig_cb_val(handler_val);
7581 	}
7582 	IPMI_SWIG_C_CB_EXIT
7583 	return rv;
7584     }
7585 
7586     /*
7587      * Rearm the current sensor.  This will cause the sensor to resend
7588      * it's current event state if it is out of range.  If
7589      * get_supports_auto_rearm() returns false and you receive an
7590      * event, you have to rearm a sensor manually to get another event
7591      * from it.  If global_enable (parm 1) is set, all events are
7592      * enabled and the state is ignored (and may be NULL).  Otherwise,
7593      * the events set in the event state (parm 2) are enabled.  When
7594      * the operation is complete, the sensor_rearm_cb method of the
7595      * third parameter (if it is supplied) will be called with the
7596      * following parameters: <self> <sensor> <err>
7597      */
7598     int rearm(int     global_enable,
7599 	      char    *states,
7600 	      swig_cb *handler = NULL)
7601     {
7602 	int                 rv;
7603 	swig_cb_val         *handler_val = NULL;
7604 	ipmi_sensor_done_cb sensor_cb = NULL;
7605 	ipmi_event_state_t  *st = NULL;
7606 
7607 	IPMI_SWIG_C_CB_ENTRY
7608 	if (!global_enable) {
7609 	    if (!states) {
7610 		rv = EINVAL;
7611 		goto out_err;
7612 	    }
7613 	    if (ipmi_sensor_get_event_reading_type(self)
7614 		== IPMI_EVENT_READING_TYPE_THRESHOLD)
7615 	    {
7616 		rv = str_to_threshold_event_state(states, &st);
7617 	    } else {
7618 		rv = str_to_discrete_event_state(states, &st);
7619 	    }
7620 	    if (rv)
7621 		goto out_err;
7622 	}
7623 	if (!nil_swig_cb(handler)) {
7624 	    if (! valid_swig_cb(handler, sensor_rearm_cb)) {
7625 		rv = EINVAL;
7626 		goto out_err;
7627 	    }
7628 	    sensor_cb = sensor_rearm_handler;
7629 	    handler_val = ref_swig_cb(handler, sensor_rearm_cb);
7630 	}
7631 	rv = ipmi_sensor_rearm(self, global_enable, st,
7632 			       sensor_cb, handler_val);
7633 	if (rv && handler_val)
7634 	    deref_swig_cb_val(handler_val);
7635     out_err:
7636 	if (st)
7637 	    free(st);
7638 	IPMI_SWIG_C_CB_EXIT
7639 	return rv;
7640     }
7641 
7642     /*
7643      * Get the hysteresis values for the given sensor.  These are the
7644      * raw values, there doesn't seem to be an easy way to calculate
7645      * the cooked values.  The sensor_get_hysteresis_cb method on the
7646      * first parameter will be called with the values.  It's
7647      * parameters are: <self> <sensor> <err> <positive hysteresis>
7648      * <negative hysteresis>
7649      */
get_hysteresis(swig_cb * handler)7650     int get_hysteresis(swig_cb *handler)
7651     {
7652 	int                       rv;
7653 	swig_cb_val               *handler_val = NULL;
7654 	ipmi_sensor_hysteresis_cb sensor_cb = NULL;
7655 
7656 	IPMI_SWIG_C_CB_ENTRY
7657 	if (!valid_swig_cb(handler, sensor_get_hysteresis_cb))
7658 	    rv = EINVAL;
7659 	else {
7660 	    sensor_cb = sensor_get_hysteresis_handler;
7661 	    handler_val = ref_swig_cb(handler, sensor_get_hysteresis_cb);
7662 	    rv = ipmi_sensor_get_hysteresis(self, sensor_cb, handler_val);
7663 	    if (rv)
7664 		deref_swig_cb_val(handler_val);
7665 	}
7666 	IPMI_SWIG_C_CB_EXIT
7667 	return rv;
7668     }
7669 
7670     /*
7671      * Set the hysteresis values for the given sensor.  These are the
7672      * raw values, there doesn't seem to be an easy way to calculate
7673      * the cooked values.  The positive hysteresis is the first
7674      * parameter, the negative hystersis is the second.  When the
7675      * operation completes, the sensor_set_hysteresis_cb will be
7676      * called on the third parameter (if it is supplied) with the
7677      * following parms: <self> <sensor> <err>
7678      */
7679     int set_hysteresis(unsigned int positive_hysteresis,
7680 		       unsigned int negative_hysteresis,
7681 		       swig_cb      *handler = NULL)
7682     {
7683 	int                 rv;
7684 	swig_cb_val         *handler_val = NULL;
7685 	ipmi_sensor_done_cb sensor_cb = NULL;
7686 
7687 	IPMI_SWIG_C_CB_ENTRY
7688 	if (!nil_swig_cb(handler)) {
7689 	    if (! valid_swig_cb(handler, sensor_set_hysteresis_cb)) {
7690 		rv = EINVAL;
7691 		goto out_err;
7692 	    }
7693 	    sensor_cb = sensor_set_hysteresis_handler;
7694 	    handler_val = ref_swig_cb(handler, sensor_set_hysteresis_cb);
7695 	}
7696 	rv = ipmi_sensor_set_hysteresis(self, positive_hysteresis,
7697 					negative_hysteresis,
7698 					sensor_cb, handler_val);
7699 	if (rv && handler_val)
7700 	    deref_swig_cb_val(handler_val);
7701     out_err:
7702 	IPMI_SWIG_C_CB_EXIT
7703 	return rv;
7704     }
7705 
7706     %newobject get_default_thresholds;
7707     /*
7708      * Return the default threshold settings for a sensor.
7709      */
get_default_thresholds()7710     char *get_default_thresholds()
7711     {
7712 	ipmi_thresholds_t *th = malloc(ipmi_thresholds_size());
7713 	char              *str = NULL;
7714 	int               rv;
7715 
7716 	rv = ipmi_get_default_sensor_thresholds(self, th);
7717 	if (!rv) {
7718 	    str = thresholds_to_str(th);
7719 	}
7720 	free(th);
7721 	return str;
7722     }
7723 
7724     /*
7725      * Set the thresholds for the given sensor to the threshold values
7726      * specified in the first parameter.  When the thresholds are set,
7727      * the sensor_set_thresholds_cb method on the second parm (if it
7728      * is supplied) will be called with the following parameters:
7729      * <self> <sensor> <err>
7730      */
7731     int set_thresholds(char    *thresholds,
7732 		       swig_cb *handler = NULL)
7733     {
7734 	ipmi_thresholds_t   *th = NULL;
7735 	int                 rv;
7736 	swig_cb_val         *handler_val = NULL;
7737 	ipmi_sensor_done_cb sensor_cb = NULL;
7738 
7739 	IPMI_SWIG_C_CB_ENTRY
7740 	rv = str_to_thresholds(thresholds, self, &th);
7741 	if (rv)
7742 	    goto out_err;
7743 
7744 	if (!nil_swig_cb(handler)) {
7745 	    if (! valid_swig_cb(handler, sensor_set_thresholds_cb)) {
7746 		rv = EINVAL;
7747 		goto out_err_free;
7748 	    }
7749 	    sensor_cb = sensor_set_thresholds_handler;
7750 	    handler_val = ref_swig_cb(handler, sensor_set_thresholds_cb);
7751 	}
7752 	rv = ipmi_sensor_set_thresholds(self, th, sensor_cb, handler_val);
7753 	if (rv && handler_val)
7754 	    deref_swig_cb_val(handler_val);
7755     out_err_free:
7756 	free(th);
7757     out_err:
7758 	IPMI_SWIG_C_CB_EXIT
7759 	return rv;
7760     }
7761 
7762     /*
7763      * Fetch the thresholds for the given sensor.  When the thresholds
7764      * are received, the sensor_get_thresholds_cb method on the second
7765      * parm will be called with the following parameters: <self>
7766      * <sensor> <err> <thresholds>
7767      */
get_thresholds(swig_cb * handler)7768     int get_thresholds(swig_cb *handler)
7769     {
7770 	int                       rv;
7771 	swig_cb_val               *handler_val = NULL;
7772 	ipmi_sensor_thresholds_cb sensor_cb = NULL;
7773 
7774 	IPMI_SWIG_C_CB_ENTRY
7775 	if (!valid_swig_cb(handler, sensor_get_thresholds_cb))
7776 	    rv = EINVAL;
7777 	else {
7778 	    sensor_cb = sensor_get_thresholds_handler;
7779 	    handler_val = ref_swig_cb(handler, sensor_get_thresholds_cb);
7780 	    rv = ipmi_sensor_get_thresholds(self, sensor_cb, handler_val);
7781 	    if (rv)
7782 		deref_swig_cb_val(handler_val);
7783 	}
7784 	IPMI_SWIG_C_CB_EXIT
7785 	return rv;
7786     }
7787 
7788     /* Read the current value of the given sensor.  If this is a
7789        discrete sensor, the discrete_states_cb method of the first
7790        parameter will be called with the following parameters: <self>
7791        <sensor> <err> <states>.  If this is a threshold sensor, the
7792        threshold_reading_cb method of the first parameter will be
7793        called with the following parameters: <self> <sensor> <err>
7794        <raw_set> <raw> <value_set> <value> <states>. */
get_value(swig_cb * handler)7795     int get_value(swig_cb *handler)
7796     {
7797 	int                    rv;
7798 	swig_cb_val            *handler_val = NULL;
7799 
7800 	IPMI_SWIG_C_CB_ENTRY
7801 	if (!valid_swig_cb(handler, threshold_reading_cb))
7802 	    rv = EINVAL;
7803 	else {
7804 	    handler_val = ref_swig_cb(handler, threshold_reading_cb);
7805 	    if (ipmi_sensor_get_event_reading_type(self)
7806 		== IPMI_EVENT_READING_TYPE_THRESHOLD)
7807 	    {
7808 		ipmi_sensor_reading_cb sensor_cb;
7809 
7810 		sensor_cb = sensor_get_reading_handler;
7811 		rv = ipmi_sensor_get_reading(self, sensor_cb, handler_val);
7812 	    } else {
7813 		ipmi_sensor_states_cb sensor_cb;
7814 
7815 		sensor_cb = sensor_get_states_handler;
7816 		rv = ipmi_sensor_get_states(self, sensor_cb, handler_val);
7817 	    }
7818 	    if (rv)
7819 		deref_swig_cb_val(handler_val);
7820 	}
7821 	IPMI_SWIG_C_CB_EXIT
7822 	return rv;
7823     }
7824 
7825     /*
7826      * Return the LUN for the sensor (with respect to the MC).
7827      */
get_lun()7828     int get_lun()
7829     {
7830 	int lun = 0;
7831 	ipmi_sensor_get_num(self, &lun, NULL);
7832 	return lun;
7833     }
7834 
7835     /*
7836      * Return the number for the sensor (The number in the MC/LUN).
7837      */
get_num()7838     int get_num()
7839     {
7840 	int num = 0;
7841 	ipmi_sensor_get_num(self, NULL, &num);
7842 	return num;
7843     }
7844 
7845     /*
7846      * The sensor type.  This return sa string representing the sensor
7847      * type.
7848      */
get_sensor_type_string()7849     const char *get_sensor_type_string()
7850     {
7851 	return ipmi_sensor_get_sensor_type_string(self);
7852     }
7853 
7854 %constant int SENSOR_TYPE_TEMPERATURE = IPMI_SENSOR_TYPE_TEMPERATURE;
7855 %constant int SENSOR_TYPE_VOLTAGE = IPMI_SENSOR_TYPE_VOLTAGE;
7856 %constant int SENSOR_TYPE_CURRENT = IPMI_SENSOR_TYPE_CURRENT;
7857 %constant int SENSOR_TYPE_FAN = IPMI_SENSOR_TYPE_FAN;
7858 %constant int SENSOR_TYPE_PHYSICAL_SECURITY = IPMI_SENSOR_TYPE_PHYSICAL_SECURITY;
7859 %constant int SENSOR_TYPE_PLATFORM_SECURITY = IPMI_SENSOR_TYPE_PLATFORM_SECURITY;
7860 %constant int SENSOR_TYPE_PROCESSOR = IPMI_SENSOR_TYPE_PROCESSOR;
7861 %constant int SENSOR_TYPE_POWER_SUPPLY = IPMI_SENSOR_TYPE_POWER_SUPPLY;
7862 %constant int SENSOR_TYPE_POWER_UNIT = IPMI_SENSOR_TYPE_POWER_UNIT;
7863 %constant int SENSOR_TYPE_COOLING_DEVICE = IPMI_SENSOR_TYPE_COOLING_DEVICE;
7864 %constant int SENSOR_TYPE_OTHER_UNITS_BASED_SENSOR = IPMI_SENSOR_TYPE_OTHER_UNITS_BASED_SENSOR;
7865 %constant int SENSOR_TYPE_MEMORY = IPMI_SENSOR_TYPE_MEMORY;
7866 %constant int SENSOR_TYPE_DRIVE_SLOT = IPMI_SENSOR_TYPE_DRIVE_SLOT;
7867 %constant int SENSOR_TYPE_POWER_MEMORY_RESIZE = IPMI_SENSOR_TYPE_POWER_MEMORY_RESIZE;
7868 %constant int SENSOR_TYPE_SYSTEM_FIRMWARE_PROGRESS = IPMI_SENSOR_TYPE_SYSTEM_FIRMWARE_PROGRESS;
7869 %constant int SENSOR_TYPE_EVENT_LOGGING_DISABLED = IPMI_SENSOR_TYPE_EVENT_LOGGING_DISABLED;
7870 %constant int SENSOR_TYPE_WATCHDOG_1 = IPMI_SENSOR_TYPE_WATCHDOG_1;
7871 %constant int SENSOR_TYPE_SYSTEM_EVENT = IPMI_SENSOR_TYPE_SYSTEM_EVENT;
7872 %constant int SENSOR_TYPE_CRITICAL_INTERRUPT = IPMI_SENSOR_TYPE_CRITICAL_INTERRUPT;
7873 %constant int SENSOR_TYPE_BUTTON = IPMI_SENSOR_TYPE_BUTTON;
7874 %constant int SENSOR_TYPE_MODULE_BOARD = IPMI_SENSOR_TYPE_MODULE_BOARD;
7875 %constant int SENSOR_TYPE_MICROCONTROLLER_COPROCESSOR = IPMI_SENSOR_TYPE_MICROCONTROLLER_COPROCESSOR;
7876 %constant int SENSOR_TYPE_ADD_IN_CARD = IPMI_SENSOR_TYPE_ADD_IN_CARD;
7877 %constant int SENSOR_TYPE_CHASSIS = IPMI_SENSOR_TYPE_CHASSIS;
7878 %constant int SENSOR_TYPE_CHIP_SET = IPMI_SENSOR_TYPE_CHIP_SET;
7879 %constant int SENSOR_TYPE_OTHER_FRU = IPMI_SENSOR_TYPE_OTHER_FRU;
7880 %constant int SENSOR_TYPE_CABLE_INTERCONNECT = IPMI_SENSOR_TYPE_CABLE_INTERCONNECT;
7881 %constant int SENSOR_TYPE_TERMINATOR = IPMI_SENSOR_TYPE_TERMINATOR;
7882 %constant int SENSOR_TYPE_SYSTEM_BOOT_INITIATED = IPMI_SENSOR_TYPE_SYSTEM_BOOT_INITIATED;
7883 %constant int SENSOR_TYPE_BOOT_ERROR = IPMI_SENSOR_TYPE_BOOT_ERROR;
7884 %constant int SENSOR_TYPE_OS_BOOT = IPMI_SENSOR_TYPE_OS_BOOT;
7885 %constant int SENSOR_TYPE_OS_CRITICAL_STOP = IPMI_SENSOR_TYPE_OS_CRITICAL_STOP;
7886 %constant int SENSOR_TYPE_SLOT_CONNECTOR = IPMI_SENSOR_TYPE_SLOT_CONNECTOR;
7887 %constant int SENSOR_TYPE_SYSTEM_ACPI_POWER_STATE = IPMI_SENSOR_TYPE_SYSTEM_ACPI_POWER_STATE;
7888 %constant int SENSOR_TYPE_WATCHDOG_2 = IPMI_SENSOR_TYPE_WATCHDOG_2;
7889 %constant int SENSOR_TYPE_PLATFORM_ALERT = IPMI_SENSOR_TYPE_PLATFORM_ALERT;
7890 %constant int SENSOR_TYPE_ENTITY_PRESENCE = IPMI_SENSOR_TYPE_ENTITY_PRESENCE;
7891 %constant int SENSOR_TYPE_MONITOR_ASIC_IC = IPMI_SENSOR_TYPE_MONITOR_ASIC_IC;
7892 %constant int SENSOR_TYPE_LAN = IPMI_SENSOR_TYPE_LAN;
7893 %constant int SENSOR_TYPE_MANAGEMENT_SUBSYSTEM_HEALTH = IPMI_SENSOR_TYPE_MANAGEMENT_SUBSYSTEM_HEALTH;
7894 %constant int SENSOR_TYPE_BATTERY = IPMI_SENSOR_TYPE_BATTERY;
7895     /*
7896      * Return the numeric sensor type.
7897      */
get_sensor_type()7898     int get_sensor_type()
7899     {
7900 	return ipmi_sensor_get_sensor_type(self);
7901     }
7902 
7903     /*
7904      * Return the event reading type string.  If this returns
7905      * "threshold", then this is a threshold sensor.  Otherwise it is
7906      * a discrete sensor.
7907      */
get_event_reading_type_string()7908     const char *get_event_reading_type_string()
7909     {
7910 	return ipmi_sensor_get_event_reading_type_string(self);
7911     }
7912 
7913 %constant int EVENT_READING_TYPE_THRESHOLD = IPMI_EVENT_READING_TYPE_THRESHOLD;
7914 %constant int EVENT_READING_TYPE_DISCRETE_USAGE = IPMI_EVENT_READING_TYPE_DISCRETE_USAGE;
7915 %constant int EVENT_READING_TYPE_DISCRETE_STATE = IPMI_EVENT_READING_TYPE_DISCRETE_STATE;
7916 %constant int EVENT_READING_TYPE_DISCRETE_PREDICTIVE_FAILURE = IPMI_EVENT_READING_TYPE_DISCRETE_PREDICTIVE_FAILURE;
7917 %constant int EVENT_READING_TYPE_DISCRETE_LIMIT_EXCEEDED = IPMI_EVENT_READING_TYPE_DISCRETE_LIMIT_EXCEEDED;
7918 %constant int EVENT_READING_TYPE_DISCRETE_PERFORMANCE_MET = IPMI_EVENT_READING_TYPE_DISCRETE_PERFORMANCE_MET;
7919 %constant int EVENT_READING_TYPE_DISCRETE_SEVERITY = IPMI_EVENT_READING_TYPE_DISCRETE_SEVERITY;
7920 %constant int EVENT_READING_TYPE_DISCRETE_DEVICE_PRESENCE = IPMI_EVENT_READING_TYPE_DISCRETE_DEVICE_PRESENCE;
7921 %constant int EVENT_READING_TYPE_DISCRETE_DEVICE_ENABLE = IPMI_EVENT_READING_TYPE_DISCRETE_DEVICE_ENABLE;
7922 %constant int EVENT_READING_TYPE_DISCRETE_AVAILABILITY = IPMI_EVENT_READING_TYPE_DISCRETE_AVAILABILITY;
7923 %constant int EVENT_READING_TYPE_DISCRETE_REDUNDANCY = IPMI_EVENT_READING_TYPE_DISCRETE_REDUNDANCY;
7924 %constant int EVENT_READING_TYPE_DISCRETE_ACPI_POWER = IPMI_EVENT_READING_TYPE_DISCRETE_ACPI_POWER;
7925 %constant int EVENT_READING_TYPE_SENSOR_SPECIFIC = IPMI_EVENT_READING_TYPE_SENSOR_SPECIFIC;
7926     /*
7927      * Return the numeric event reading type.  This will return
7928      * EVENT_READING_TYPE_THRESHOLD for threshold sensors; everthing
7929      * else is a discrete sensor.
7930      */
get_event_reading_type()7931     int get_event_reading_type()
7932     {
7933 	return ipmi_sensor_get_event_reading_type(self);
7934     }
7935 
7936     /*
7937      * Get the string for the sensor's rate unit.  This will be blank
7938      * if there is not a rate unit for this sensor.
7939      */
get_rate_unit_string()7940     const char *get_rate_unit_string()
7941     {
7942 	return ipmi_sensor_get_rate_unit_string(self);
7943     }
7944 
7945 %constant int RATE_UNIT_NONE = IPMI_RATE_UNIT_NONE;
7946 %constant int RATE_UNIT_PER_US = IPMI_RATE_UNIT_PER_US;
7947 %constant int RATE_UNIT_PER_MS = IPMI_RATE_UNIT_PER_MS;
7948 %constant int RATE_UNIT_PER_SEC = IPMI_RATE_UNIT_PER_SEC;
7949 %constant int RATE_UNIT_MIN = IPMI_RATE_UNIT_MIN;
7950 %constant int RATE_UNIT_HOUR = IPMI_RATE_UNIT_HOUR;
7951 %constant int RATE_UNIT_DAY = IPMI_RATE_UNIT_DAY;
7952 
7953     /*
7954      * Get the rate unit for this sensor.
7955      */
get_rate_unit()7956     int get_rate_unit()
7957     {
7958 	return ipmi_sensor_get_rate_unit(self);
7959     }
7960 
7961     /*
7962      * Get the string for the sensor's base unit.
7963      */
get_base_unit_string()7964     const char *get_base_unit_string()
7965     {
7966 	return ipmi_sensor_get_base_unit_string(self);
7967     }
7968 
7969 %constant int UNIT_TYPE_UNSPECIFIED = IPMI_UNIT_TYPE_UNSPECIFIED;
7970 %constant int UNIT_TYPE_DEGREES_C = IPMI_UNIT_TYPE_DEGREES_C;
7971 %constant int UNIT_TYPE_DEGREES_F = IPMI_UNIT_TYPE_DEGREES_F;
7972 %constant int UNIT_TYPE_DEGREES_K = IPMI_UNIT_TYPE_DEGREES_K;
7973 %constant int UNIT_TYPE_VOLTS = IPMI_UNIT_TYPE_VOLTS;
7974 %constant int UNIT_TYPE_AMPS = IPMI_UNIT_TYPE_AMPS;
7975 %constant int UNIT_TYPE_WATTS = IPMI_UNIT_TYPE_WATTS;
7976 %constant int UNIT_TYPE_JOULES = IPMI_UNIT_TYPE_JOULES;
7977 %constant int UNIT_TYPE_COULOMBS = IPMI_UNIT_TYPE_COULOMBS;
7978 %constant int UNIT_TYPE_VA = IPMI_UNIT_TYPE_VA;
7979 %constant int UNIT_TYPE_NITS = IPMI_UNIT_TYPE_NITS;
7980 %constant int UNIT_TYPE_LUMENS = IPMI_UNIT_TYPE_LUMENS;
7981 %constant int UNIT_TYPE_LUX = IPMI_UNIT_TYPE_LUX;
7982 %constant int UNIT_TYPE_CANDELA = IPMI_UNIT_TYPE_CANDELA;
7983 %constant int UNIT_TYPE_KPA = IPMI_UNIT_TYPE_KPA;
7984 %constant int UNIT_TYPE_PSI = IPMI_UNIT_TYPE_PSI;
7985 %constant int UNIT_TYPE_NEWTONS = IPMI_UNIT_TYPE_NEWTONS;
7986 %constant int UNIT_TYPE_CFM = IPMI_UNIT_TYPE_CFM;
7987 %constant int UNIT_TYPE_RPM = IPMI_UNIT_TYPE_RPM;
7988 %constant int UNIT_TYPE_HZ = IPMI_UNIT_TYPE_HZ;
7989 %constant int UNIT_TYPE_USECONDS = IPMI_UNIT_TYPE_USECONDS;
7990 %constant int UNIT_TYPE_MSECONDS = IPMI_UNIT_TYPE_MSECONDS;
7991 %constant int UNIT_TYPE_SECONDS = IPMI_UNIT_TYPE_SECONDS;
7992 %constant int UNIT_TYPE_MINUTE = IPMI_UNIT_TYPE_MINUTE;
7993 %constant int UNIT_TYPE_HOUR = IPMI_UNIT_TYPE_HOUR;
7994 %constant int UNIT_TYPE_DAY = IPMI_UNIT_TYPE_DAY;
7995 %constant int UNIT_TYPE_WEEK = IPMI_UNIT_TYPE_WEEK;
7996 %constant int UNIT_TYPE_MIL = IPMI_UNIT_TYPE_MIL;
7997 %constant int UNIT_TYPE_INCHES = IPMI_UNIT_TYPE_INCHES;
7998 %constant int UNIT_TYPE_FEET = IPMI_UNIT_TYPE_FEET;
7999 %constant int UNIT_TYPE_CUBIC_INCHS = IPMI_UNIT_TYPE_CUBIC_INCHS;
8000 %constant int UNIT_TYPE_CUBIC_FEET = IPMI_UNIT_TYPE_CUBIC_FEET;
8001 %constant int UNIT_TYPE_MILLIMETERS = IPMI_UNIT_TYPE_MILLIMETERS;
8002 %constant int UNIT_TYPE_CENTIMETERS = IPMI_UNIT_TYPE_CENTIMETERS;
8003 %constant int UNIT_TYPE_METERS = IPMI_UNIT_TYPE_METERS;
8004 %constant int UNIT_TYPE_CUBIC_CENTIMETERS = IPMI_UNIT_TYPE_CUBIC_CENTIMETERS;
8005 %constant int UNIT_TYPE_CUBIC_METERS = IPMI_UNIT_TYPE_CUBIC_METERS;
8006 %constant int UNIT_TYPE_LITERS = IPMI_UNIT_TYPE_LITERS;
8007 %constant int UNIT_TYPE_FL_OZ = IPMI_UNIT_TYPE_FL_OZ;
8008 %constant int UNIT_TYPE_RADIANS = IPMI_UNIT_TYPE_RADIANS;
8009 %constant int UNIT_TYPE_SERADIANS = IPMI_UNIT_TYPE_SERADIANS;
8010 %constant int UNIT_TYPE_REVOLUTIONS = IPMI_UNIT_TYPE_REVOLUTIONS;
8011 %constant int UNIT_TYPE_CYCLES = IPMI_UNIT_TYPE_CYCLES;
8012 %constant int UNIT_TYPE_GRAVITIES = IPMI_UNIT_TYPE_GRAVITIES;
8013 %constant int UNIT_TYPE_OUNCES = IPMI_UNIT_TYPE_OUNCES;
8014 %constant int UNIT_TYPE_POUNDS = IPMI_UNIT_TYPE_POUNDS;
8015 %constant int UNIT_TYPE_FOOT_POUNDS = IPMI_UNIT_TYPE_FOOT_POUNDS;
8016 %constant int UNIT_TYPE_OUNCE_INCHES = IPMI_UNIT_TYPE_OUNCE_INCHES;
8017 %constant int UNIT_TYPE_GAUSS = IPMI_UNIT_TYPE_GAUSS;
8018 %constant int UNIT_TYPE_GILBERTS = IPMI_UNIT_TYPE_GILBERTS;
8019 %constant int UNIT_TYPE_HENRIES = IPMI_UNIT_TYPE_HENRIES;
8020 %constant int UNIT_TYPE_MHENRIES = IPMI_UNIT_TYPE_MHENRIES;
8021 %constant int UNIT_TYPE_FARADS = IPMI_UNIT_TYPE_FARADS;
8022 %constant int UNIT_TYPE_UFARADS = IPMI_UNIT_TYPE_UFARADS;
8023 %constant int UNIT_TYPE_OHMS = IPMI_UNIT_TYPE_OHMS;
8024 %constant int UNIT_TYPE_SIEMENS = IPMI_UNIT_TYPE_SIEMENS;
8025 %constant int UNIT_TYPE_MOLES = IPMI_UNIT_TYPE_MOLES;
8026 %constant int UNIT_TYPE_BECQUERELS = IPMI_UNIT_TYPE_BECQUERELS;
8027 %constant int UNIT_TYPE_PPM = IPMI_UNIT_TYPE_PPM;
8028 %constant int UNIT_TYPE_reserved1 = IPMI_UNIT_TYPE_reserved1;
8029 %constant int UNIT_TYPE_DECIBELS = IPMI_UNIT_TYPE_DECIBELS;
8030 %constant int UNIT_TYPE_DbA = IPMI_UNIT_TYPE_DbA;
8031 %constant int UNIT_TYPE_DbC = IPMI_UNIT_TYPE_DbC;
8032 %constant int UNIT_TYPE_GRAYS = IPMI_UNIT_TYPE_GRAYS;
8033 %constant int UNIT_TYPE_SIEVERTS = IPMI_UNIT_TYPE_SIEVERTS;
8034 %constant int UNIT_TYPE_COLOR_TEMP_DEG_K = IPMI_UNIT_TYPE_COLOR_TEMP_DEG_K;
8035 %constant int UNIT_TYPE_BITS = IPMI_UNIT_TYPE_BITS;
8036 %constant int UNIT_TYPE_KBITS = IPMI_UNIT_TYPE_KBITS;
8037 %constant int UNIT_TYPE_MBITS = IPMI_UNIT_TYPE_MBITS;
8038 %constant int UNIT_TYPE_GBITS = IPMI_UNIT_TYPE_GBITS;
8039 %constant int UNIT_TYPE_BYTES = IPMI_UNIT_TYPE_BYTES;
8040 %constant int UNIT_TYPE_KBYTES = IPMI_UNIT_TYPE_KBYTES;
8041 %constant int UNIT_TYPE_MBYTES = IPMI_UNIT_TYPE_MBYTES;
8042 %constant int UNIT_TYPE_GBYTES = IPMI_UNIT_TYPE_GBYTES;
8043 %constant int UNIT_TYPE_WORDS = IPMI_UNIT_TYPE_WORDS;
8044 %constant int UNIT_TYPE_DWORDS = IPMI_UNIT_TYPE_DWORDS;
8045 %constant int UNIT_TYPE_QWORDS = IPMI_UNIT_TYPE_QWORDS;
8046 %constant int UNIT_TYPE_LINES = IPMI_UNIT_TYPE_LINES;
8047 %constant int UNIT_TYPE_HITS = IPMI_UNIT_TYPE_HITS;
8048 %constant int UNIT_TYPE_MISSES = IPMI_UNIT_TYPE_MISSES;
8049 %constant int UNIT_TYPE_RETRIES = IPMI_UNIT_TYPE_RETRIES;
8050 %constant int UNIT_TYPE_RESETS = IPMI_UNIT_TYPE_RESETS;
8051 %constant int UNIT_TYPE_OVERRUNS = IPMI_UNIT_TYPE_OVERRUNS;
8052 %constant int UNIT_TYPE_UNDERRUNS = IPMI_UNIT_TYPE_UNDERRUNS;
8053 %constant int UNIT_TYPE_COLLISIONS = IPMI_UNIT_TYPE_COLLISIONS;
8054 %constant int UNIT_TYPE_PACKETS = IPMI_UNIT_TYPE_PACKETS;
8055 %constant int UNIT_TYPE_MESSAGES = IPMI_UNIT_TYPE_MESSAGES;
8056 %constant int UNIT_TYPE_CHARACTERS = IPMI_UNIT_TYPE_CHARACTERS;
8057 %constant int UNIT_TYPE_ERRORS = IPMI_UNIT_TYPE_ERRORS;
8058 %constant int UNIT_TYPE_CORRECTABLE_ERRORS = IPMI_UNIT_TYPE_CORRECTABLE_ERRORS;
8059 %constant int UNIT_TYPE_UNCORRECTABLE_ERRORS = IPMI_UNIT_TYPE_UNCORRECTABLE_ERRORS;
8060 %constant int UNIT_TYPE_FATAL_ERRORS = IPMI_UNIT_TYPE_FATAL_ERRORS;
8061 %constant int UNIT_TYPE_GRAMS = IPMI_UNIT_TYPE_GRAMS;
8062 
8063     /*
8064      * Get the sensor's base unit.
8065      */
get_base_unit()8066     int get_base_unit()
8067     {
8068 	return ipmi_sensor_get_base_unit(self);
8069     }
8070 
8071     /*
8072      * Get the modifier unit string for the sensor, this will be an empty
8073      * string if there is none.
8074      */
get_modifier_unit_string()8075     const char *get_modifier_unit_string()
8076     {
8077 	return ipmi_sensor_get_modifier_unit_string(self);
8078     }
8079 
8080     /*
8081      * Get the sensor's modifier unit.
8082      */
get_modifier_unit()8083     int get_modifier_unit()
8084     {
8085 	return ipmi_sensor_get_modifier_unit(self);
8086     }
8087 
8088 %constant int MODIFIER_UNIT_NONE = IPMI_MODIFIER_UNIT_NONE;
8089 %constant int MODIFIER_UNIT_BASE_DIV_MOD = IPMI_MODIFIER_UNIT_BASE_DIV_MOD;
8090 %constant int MODIFIER_UNIT_BASE_MULT_MOD = IPMI_MODIFIER_UNIT_BASE_MULT_MOD;
8091 
8092     /*
8093      * Return the how the modifier unit should be used.  If this
8094      * returns MODIFIER_UNIT_NONE, then the modifier unit is not
8095      * used.  If it returns MODIFIER_UNIT_BASE_DIV_MOD, the modifier
8096      * unit is dividied by the base unit (eg per hour, per second,
8097      * etc.).  If it returns MODIFIER_UNIT_BASE_MULT_MOD, the modifier
8098      * unit is multiplied by the base unit.
8099      */
get_modifier_unit_use()8100     int get_modifier_unit_use()
8101     {
8102 	return ipmi_sensor_get_modifier_unit_use(self);
8103     }
8104 
8105     /*
8106      * Returns if the value is a percentage.
8107      */
get_percentage()8108     int get_percentage()
8109     {
8110 	return ipmi_sensor_get_percentage(self);
8111     }
8112 
8113 
8114     /*
8115      * This call is a little different from the other string calls.
8116      * For a discrete sensor, you can pass the offset into this call
8117      * and it will return the string associated with the reading.
8118      * This way, OEM sensors can supply their own strings as necessary
8119      * for the various offsets.  This is only for discrete sensors.
8120      */
reading_name_string(int offset)8121     const char *reading_name_string(int offset)
8122     {
8123 	return ipmi_sensor_reading_name_string(self, offset);
8124     }
8125 
8126     /*
8127      * Get the entity id of the entity the sensor is hooked to.
8128      */
get_entity_id()8129     int get_entity_id()
8130     {
8131 	return ipmi_sensor_get_entity_id(self);
8132     }
8133 
8134     /*
8135      * Get the entity instance of the entity the sensor is hooked to.
8136      */
get_entity_instance()8137     int get_entity_instance()
8138     {
8139 	return ipmi_sensor_get_entity_instance(self);
8140     }
8141 
8142     /*
8143      * Get the entity the sensor is hooked to.
8144      */
get_entity()8145     ipmi_entity_t *get_entity()
8146     {
8147 	return ipmi_sensor_get_entity(self);
8148     }
8149 
8150 
8151     /*
8152      * Initialization information about a sensor from it's SDR.
8153      */
get_sensor_init_scanning()8154     int get_sensor_init_scanning()
8155     {
8156 	return ipmi_sensor_get_sensor_init_scanning(self);
8157     }
8158 
8159     /*
8160      * Initialization information about a sensor from it's SDR.
8161      */
get_sensor_init_events()8162     int get_sensor_init_events()
8163     {
8164 	return ipmi_sensor_get_sensor_init_events(self);
8165     }
8166 
8167     /*
8168      * Initialization information about a sensor from it's SDR.
8169      */
get_sensor_init_thresholds()8170     int get_sensor_init_thresholds()
8171     {
8172 	return ipmi_sensor_get_sensor_init_thresholds(self);
8173     }
8174 
8175     /*
8176      * Initialization information about a sensor from it's SDR.
8177      */
get_sensor_init_hysteresis()8178     int get_sensor_init_hysteresis()
8179     {
8180 	return ipmi_sensor_get_sensor_init_hysteresis(self);
8181     }
8182 
8183     /*
8184      * Initialization information about a sensor from it's SDR.
8185      */
get_sensor_init_type()8186     int get_sensor_init_type()
8187     {
8188 	return ipmi_sensor_get_sensor_init_type(self);
8189     }
8190 
8191     /*
8192      * Initialization information about a sensor from it's SDR.
8193      */
get_sensor_init_pu_events()8194     int get_sensor_init_pu_events()
8195     {
8196 	return ipmi_sensor_get_sensor_init_pu_events(self);
8197     }
8198 
8199     /*
8200      * Initialization information about a sensor from it's SDR.
8201      */
get_sensor_init_pu_scanning()8202     int get_sensor_init_pu_scanning()
8203     {
8204 	return ipmi_sensor_get_sensor_init_pu_scanning(self);
8205     }
8206 
8207     /*
8208      * Ignore the sensor if the entity it is attached to is not
8209      * present.
8210      */
get_ignore_if_no_entity()8211     int get_ignore_if_no_entity()
8212     {
8213 	return ipmi_sensor_get_ignore_if_no_entity(self);
8214     }
8215 
8216     /*
8217      * If this is false, the user must manually re-arm the sensor to get
8218      * any more events from it.
8219      */
get_supports_auto_rearm()8220     int get_supports_auto_rearm()
8221     {
8222 	return ipmi_sensor_get_supports_auto_rearm(self);
8223     }
8224 
8225 
8226 %constant int THRESHOLD_ACCESS_SUPPORT_NONE = IPMI_THRESHOLD_ACCESS_SUPPORT_NONE;
8227 %constant int THRESHOLD_ACCESS_SUPPORT_READABLE = IPMI_THRESHOLD_ACCESS_SUPPORT_READABLE;
8228 %constant int THRESHOLD_ACCESS_SUPPORT_SETTABLE = IPMI_THRESHOLD_ACCESS_SUPPORT_SETTABLE;
8229 %constant int THRESHOLD_ACCESS_SUPPORT_FIXED = IPMI_THRESHOLD_ACCESS_SUPPORT_FIXED;
8230 
8231     /*
8232      * Get how the thresholds of the sensor may be accessed.
8233      */
get_threshold_access()8234     int get_threshold_access()
8235     {
8236 	return ipmi_sensor_get_threshold_access(self);
8237     }
8238 
8239 %constant int HYSTERESIS_SUPPORT_NONE = IPMI_HYSTERESIS_SUPPORT_NONE;
8240 %constant int HYSTERESIS_SUPPORT_READABLE = IPMI_HYSTERESIS_SUPPORT_READABLE;
8241 %constant int HYSTERESIS_SUPPORT_SETTABLE = IPMI_HYSTERESIS_SUPPORT_SETTABLE;
8242 %constant int HYSTERESIS_SUPPORT_FIXED = IPMI_HYSTERESIS_SUPPORT_FIXED;
8243 
8244     /*
8245      * Get how the hysteresis of the sensor may be accessed.
8246      */
get_hysteresis_support()8247     int get_hysteresis_support()
8248     {
8249 	return ipmi_sensor_get_hysteresis_support(self);
8250     }
8251 
8252 %constant int EVENT_SUPPORT_PER_STATE = IPMI_EVENT_SUPPORT_PER_STATE;
8253 %constant int EVENT_SUPPORT_ENTIRE_SENSOR = IPMI_EVENT_SUPPORT_ENTIRE_SENSOR;
8254 %constant int EVENT_SUPPORT_GLOBAL_ENABLE = IPMI_EVENT_SUPPORT_GLOBAL_ENABLE;
8255 %constant int EVENT_SUPPORT_NONE = IPMI_EVENT_SUPPORT_NONE;
8256 
8257     /*
8258      * Get how the events in the sensor may be enabled and disabled.
8259      */
get_event_support()8260     int get_event_support()
8261     {
8262 	return ipmi_sensor_get_event_support(self);
8263     }
8264 
8265 %constant int SENSOR_DIRECTION_UNSPECIFIED = IPMI_SENSOR_DIRECTION_UNSPECIFIED;
8266 %constant int SENSOR_DIRECTION_INPUT = IPMI_SENSOR_DIRECTION_INPUT;
8267 %constant int SENSOR_DIRECTION_OUTPUT = IPMI_SENSOR_DIRECTION_OUTPUT;
8268 
8269     /*
8270      * Get whether the sensor is monitoring an input or an output.
8271      * For instance, the +5V sensor on the output of a power supply
8272      * would be the output, the +5V sensor measuring the voltage
8273      * coming into a card would be an input.
8274      */
get_sensor_direction()8275     int get_sensor_direction()
8276     {
8277 	return ipmi_sensor_get_sensor_direction(self);
8278     }
8279 
8280     /*
8281      * Get whether the sensor's value can be read or not (with
8282      * get_value()).  Sensors with system software owners and
8283      * event-only sensors cannot be read.
8284      */
is_readable()8285     int is_readable()
8286     {
8287 	return ipmi_sensor_get_is_readable(self);
8288     }
8289 
8290     /*
8291      * Sets the second parameter to if an event is supported for this
8292      * particular threshold event on the sensor. The first parameter
8293      * is the event specifier string.  This will return 0 on success
8294      * or EINVAL on an invalid event.
8295      */
threshold_event_supported(char * event,int * val)8296     int threshold_event_supported(char *event, int *val)
8297     {
8298 	enum ipmi_thresh_e          thresh;
8299 	enum ipmi_event_value_dir_e value_dir;
8300 	enum ipmi_event_dir_e       dir;
8301 	char                        *s;
8302 
8303 	s = threshold_event_from_str(event, strlen(event), &thresh,
8304 				     &value_dir, &dir);
8305 	if (!s)
8306 	    return EINVAL;
8307 	return ipmi_sensor_threshold_event_supported(self,
8308 						     thresh,
8309 						     value_dir,
8310 						     dir,
8311 						     val);
8312     }
8313 
8314     /*
8315      * Sets the second parameter to if a specific threshold can be
8316      * set.  The first parameter is the threshold.  Returns EINVAL
8317      * if the threshold is invalid, otherwise returns zero.
8318      */
threshold_settable(char * threshold,int * val)8319     int threshold_settable(char *threshold, int *val)
8320     {
8321 	enum ipmi_thresh_e thresh;
8322 	char               *s;
8323 
8324 	s = threshold_from_str(threshold, strlen(threshold), &thresh);
8325 	if (!s)
8326 	    return EINVAL;
8327 	return ipmi_sensor_threshold_settable(self, thresh, val);
8328     }
8329 
8330     /*
8331      * Sets the second parameter to if a specific threshold can be
8332      * read.  The first parameter is the threshold.  Returns EINVAL
8333      * if the threshold is invalid, otherwise returns zero.
8334      */
threshold_readable(char * threshold,int * val)8335     int threshold_readable(char *threshold, int *val)
8336     {
8337 	enum ipmi_thresh_e thresh;
8338 	char               *s;
8339 
8340 	s = threshold_from_str(threshold, strlen(threshold), &thresh);
8341 	if (!s)
8342 	    return EINVAL;
8343 	return ipmi_sensor_threshold_readable(self, thresh, val);
8344     }
8345 
8346     /*
8347      * Sets the second parameter to if a specific threshold has its
8348      * reading returned when reading the value of the sensor.  The
8349      * first parameter is the threshold.  Returns EINVAL if the
8350      * threshold is invalid, otherwise returns zero.
8351      */
threshold_reading_supported(char * threshold,int * val)8352     int threshold_reading_supported(char *threshold, int *val)
8353     {
8354 	enum ipmi_thresh_e thresh;
8355 	char               *s;
8356 
8357 	s = threshold_from_str(threshold, strlen(threshold), &thresh);
8358 	if (!s)
8359 	    return EINVAL;
8360 	return ipmi_sensor_threshold_reading_supported(self, thresh, val);
8361     }
8362 
8363     /*
8364      * Sets the second parameter to if an offset will generate an
8365      * event for the given event specifier for this particular
8366      * sensor. The first parameter is the event specifier string.
8367      * This will return 0 on success or EINVAL on an invalid event.
8368      */
discrete_event_supported(char * event,int * val)8369     int discrete_event_supported(char *event, int *val)
8370     {
8371 	int                   offset;
8372 	enum ipmi_event_dir_e dir;
8373 	char                  *s;
8374 
8375 	s = discrete_event_from_str(event, strlen(event), &offset, &dir);
8376 	if (!s)
8377 	    return EINVAL;
8378 	return ipmi_sensor_discrete_event_supported(self, offset, dir, val);
8379     }
8380 
8381     /*
8382      * Sets the second parameter to if a specific offset is set by the
8383      * sensor.  The first parameter is the offset.  Returns EINVAL if
8384      * the threshold is invalid, otherwise returns zero.
8385      */
discrete_event_readable(int offset,int * val)8386     int discrete_event_readable(int offset, int *val)
8387     {
8388 	return ipmi_sensor_discrete_event_readable(self, offset, val);
8389     }
8390 
8391     /*
8392      * Returns the tolerance for the sensor at the given raw value
8393      * (first parameter).  The tolerance is returned as a double in
8394      * the second parameter.  Returns an error value.
8395      */
get_tolerance(int val,double * tolerance)8396     int get_tolerance(int val, double *tolerance)
8397     {
8398 	return ipmi_sensor_get_tolerance(self, val, tolerance);
8399     }
8400 
8401     /*
8402      * Returns the accuracy for the sensor at the given raw value
8403      * (first parameter).  The accuracy is returned as a double in the
8404      * second parameter.  Returns an error value.
8405      */
get_accuracy(int val,double * accuracy)8406     int get_accuracy(int val, double *accuracy)
8407     {
8408 	return ipmi_sensor_get_accuracy(self, val, accuracy);
8409     }
8410 
8411     /*
8412      * Is the normal minimum for the sensor specified?
8413      */
get_normal_min_specified()8414     int get_normal_min_specified()
8415     {
8416 	return ipmi_sensor_get_normal_min_specified(self);
8417     }
8418 
8419     /*
8420      * Get the normal minimum for the sensor into the first parameter.
8421      * Returns an error value.
8422      */
get_normal_min(double * normal_min)8423     int get_normal_min(double *normal_min)
8424     {
8425 	return ipmi_sensor_get_normal_min(self, normal_min);
8426     }
8427 
8428     /*
8429      * Is the normal maximum for the sensor specified?
8430      */
get_normal_max_specified()8431     int get_normal_max_specified()
8432     {
8433 	return ipmi_sensor_get_normal_max_specified(self);
8434     }
8435 
8436     /*
8437      * Get the normal maximum for the sensor into the first parameter.
8438      * Returns an error value.
8439      */
get_normal_max(double * normal_max)8440     int get_normal_max(double *normal_max)
8441     {
8442 	return ipmi_sensor_get_normal_max(self, normal_max);
8443     }
8444 
8445     /*
8446      * Returns if the nominal reading for the sensor is specified.
8447      */
get_nominal_reading_specified()8448     int get_nominal_reading_specified()
8449     {
8450 	return ipmi_sensor_get_nominal_reading_specified(self);
8451     }
8452 
8453     /*
8454      * Get the nominal value for the sensor into the first parameter.
8455      * Returns an error value.
8456      */
get_nominal_reading(double * nominal_reading)8457     int get_nominal_reading(double *nominal_reading)
8458     {
8459 	return ipmi_sensor_get_nominal_reading(self, nominal_reading);
8460     }
8461 
8462     /*
8463      * Get the sensor maximum for the sensor into the first parameter.
8464      * Returns an error value.
8465      */
get_sensor_max(double * sensor_max)8466     int get_sensor_max(double *sensor_max)
8467     {
8468 	return ipmi_sensor_get_sensor_max(self, sensor_max);
8469     }
8470 
8471     /*
8472      * Get the sensor minimum for the sensor into the first parameter.
8473      * Returns an error value.
8474      */
get_sensor_min(double * sensor_min)8475     int get_sensor_min(double *sensor_min)
8476     {
8477 	return ipmi_sensor_get_sensor_min(self, sensor_min);
8478     }
8479 
8480     /*
8481      * Get the OEM value from the sensor's SDR.
8482      */
get_oem1()8483     int get_oem1()
8484     {
8485 	return ipmi_sensor_get_oem1(self);
8486     }
8487 
8488     %newobject get_sensor_id;
8489     /*
8490      * Get the ID string from the sensor's SDR.
8491      */
get_sensor_id()8492     char *get_sensor_id()
8493     {
8494 	/* FIXME - no unicode handling. */
8495 	int len = ipmi_sensor_get_id_length(self) + 1;
8496 	char *id = malloc(len);
8497 	ipmi_sensor_get_id(self, id, len);
8498 	return id;
8499     }
8500 
8501     /*
8502      * Return the MC that owns the sensor.
8503      */
get_mc()8504     ipmi_mc_t *get_mc()
8505     {
8506 	return ipmi_sensor_get_mc(self);
8507     }
8508 }
8509 
8510 /*
8511  * A control id object.  This object is guaranteed to be valid and
8512  * can be converted into a mc pointer later.
8513  */
8514 %extend ipmi_control_id_t {
~ipmi_control_id_t()8515     ~ipmi_control_id_t()
8516     {
8517 	free(self);
8518     }
8519 
8520     /* Compare self with other, return -1 if self<other, 0 if
8521        self==other, or 1 if self>other.  */
cmp(ipmi_control_id_t * other)8522     int cmp(ipmi_control_id_t *other)
8523     {
8524 	return ipmi_cmp_control_id(*self, *other);
8525     }
8526 
8527     /*
8528      * Convert a control id to a control pointer.  The "control_cb" method
8529      * will be called on the first parameter with the following parameters:
8530      * <self> <control>
8531      */
to_control(swig_cb * handler)8532     int to_control(swig_cb *handler)
8533     {
8534 	int rv;
8535 	IPMI_SWIG_C_CB_ENTRY
8536 	if (! valid_swig_cb(handler, control_cb))
8537 	    rv = EINVAL;
8538 	else
8539 	    rv = ipmi_control_pointer_cb(*self, handle_control_cb,
8540 					 get_swig_cb(handler, control_cb));
8541 	IPMI_SWIG_C_CB_EXIT
8542 	return rv;
8543     }
8544 }
8545 
8546 /*
8547  * An control object
8548  */
8549 %extend ipmi_control_t {
8550 
8551     %newobject get_name;
8552     /*
8553      * Get the name of an control.
8554      */
get_name()8555     char *get_name()
8556     {
8557 	char name[IPMI_CONTROL_NAME_LEN];
8558 
8559 	ipmi_control_get_name(self, name, sizeof(name));
8560 	return strdup(name);
8561     }
8562 
8563     %newobject get_id;
8564     /*
8565      * Get the id for the control.
8566      */
get_id()8567     ipmi_control_id_t *get_id()
8568     {
8569 	ipmi_control_id_t *rv = malloc(sizeof(*rv));
8570 	if (rv)
8571 	    *rv = ipmi_control_convert_to_id(self);
8572 	return rv;
8573     }
8574 
8575     /*
8576      * Get the string type of control.
8577      */
get_type_string()8578     const char *get_type_string()
8579     {
8580 	return ipmi_control_get_type_string(self);
8581     }
8582 
8583 %constant int CONTROL_LIGHT = IPMI_CONTROL_LIGHT;
8584 %constant int CONTROL_RELAY = IPMI_CONTROL_RELAY;
8585 %constant int CONTROL_DISPLAY = IPMI_CONTROL_DISPLAY;
8586 %constant int CONTROL_ALARM = IPMI_CONTROL_ALARM;
8587 %constant int CONTROL_RESET = IPMI_CONTROL_RESET;
8588 %constant int CONTROL_POWER = IPMI_CONTROL_POWER;
8589 %constant int CONTROL_FAN_SPEED = IPMI_CONTROL_FAN_SPEED;
8590 %constant int CONTROL_IDENTIFIER = IPMI_CONTROL_IDENTIFIER;
8591 %constant int CONTROL_ONE_SHOT_RESET = IPMI_CONTROL_ONE_SHOT_RESET;
8592 %constant int CONTROL_OUTPUT = IPMI_CONTROL_OUTPUT;
8593 %constant int CONTROL_ONE_SHOT_OUTPUT = IPMI_CONTROL_ONE_SHOT_OUTPUT;
8594 
8595     /*
8596      * Get the numeric type of control.
8597      */
get_type()8598     int get_type()
8599     {
8600 	return ipmi_control_get_type(self);
8601     }
8602 
8603     /*
8604      * Get the entity id for the control's entity.
8605      */
get_entity_id()8606     int get_entity_id()
8607     {
8608 	return ipmi_control_get_entity_id(self);
8609     }
8610 
8611     /*
8612      * Get the entity instance for the control's entity.
8613      */
get_entity_instance()8614     int get_entity_instance()
8615     {
8616 	return ipmi_control_get_entity_instance(self);
8617     }
8618 
8619     /*
8620      * Get the entity for the control.
8621      */
get_entity()8622     ipmi_entity_t *get_entity()
8623     {
8624 	return ipmi_control_get_entity(self);
8625     }
8626 
8627     /*
8628      * Can the control's value be set?
8629      */
is_settable()8630     int is_settable()
8631     {
8632 	return ipmi_control_is_settable(self);
8633     }
8634 
8635     /*
8636      * Can the control's value be read?
8637      */
is_readable()8638     int is_readable()
8639     {
8640 	return ipmi_control_is_readable(self);
8641     }
8642 
8643     /*
8644      * Should the control be ignored if its entity is not present?
8645      */
get_ignore_if_no_entity()8646     int get_ignore_if_no_entity()
8647     {
8648 	return ipmi_control_get_ignore_if_no_entity(self);
8649     }
8650 
8651     %newobject get_control_id;
8652     /*
8653      * Get the ID string from the control's SDR.
8654      */
get_control_id()8655     char *get_control_id()
8656     {
8657 	/* FIXME - no unicode handling. */
8658 	int len = ipmi_control_get_id_length(self) + 1;
8659 	char *id = malloc(len);
8660 	ipmi_control_get_id(self, id, len);
8661 	return id;
8662     }
8663 
8664     /*
8665      * Returns true if the control can generate events upon change,
8666      * and false if not.
8667      */
has_events()8668     int has_events()
8669     {
8670 	return ipmi_control_has_events(self);
8671     }
8672 
8673     /*
8674      * Get the number of values the control supports.
8675      */
get_num_vals()8676     int get_num_vals()
8677     {
8678 	return ipmi_control_get_num_vals(self);
8679     }
8680 
8681 
8682     /*
8683      * Set the value of a control.  Note that an control may support
8684      * more than one element, the array reference passed in as the
8685      * first parameter must match the number of elements the control
8686      * supports.  All the elements will be set simultaneously.  The
8687      * control_set_val_cb method on the second parameter (if it is
8688      * supplied) will be called after the operation completes with.
8689      * It will be called with the following parameters: <self>
8690      * <control> <err>
8691      */
8692     int set_val(intarray val, swig_cb *handler = NULL)
8693     {
8694 	swig_cb_val        *handler_val = NULL;
8695 	ipmi_control_op_cb done = NULL;
8696 	int                rv;
8697 
8698 	IPMI_SWIG_C_CB_ENTRY
8699 	if (val.len != ipmi_control_get_num_vals(self)) {
8700 	    rv = EINVAL;
8701 	    goto out_err;
8702 	}
8703 
8704 	if (!nil_swig_cb(handler)) {
8705 	    if (! valid_swig_cb(handler, control_set_val_cb)) {
8706 		rv = EINVAL;
8707 		goto out_err;
8708 	    }
8709 	    handler_val = ref_swig_cb(handler, control_set_val_cb);
8710 	    done = control_val_set_handler;
8711 	}
8712 	rv = ipmi_control_set_val(self, val.val, done, handler_val);
8713 	if (rv && handler_val)
8714 	    deref_swig_cb_val(handler_val);
8715     out_err:
8716 	IPMI_SWIG_C_CB_EXIT
8717 	return rv;
8718     }
8719 
8720     /*
8721      * Get the setting of an control.  The control_get_val_cb method
8722      * on the first parameter will be called with the following
8723      * parameters: <self> <control> <err> <val1> [<val2> ...]. The
8724      * number of values passed to the handler will be the number of
8725      * values the control supports.
8726      */
get_val(swig_cb * handler)8727     int get_val(swig_cb *handler)
8728     {
8729 	swig_cb_val         *handler_val = NULL;
8730 	ipmi_control_val_cb done = NULL;
8731 	int                 rv;
8732 
8733 	IPMI_SWIG_C_CB_ENTRY
8734 	if (!valid_swig_cb(handler, control_get_val_cb))
8735 	    rv = EINVAL;
8736 	else {
8737 	    handler_val = ref_swig_cb(handler, control_get_val_cb);
8738 	    done = control_val_get_handler;
8739 
8740 	    rv = ipmi_control_get_val(self, done, handler_val);
8741 	    if (rv && handler_val)
8742 		deref_swig_cb_val(handler_val);
8743 	}
8744 	IPMI_SWIG_C_CB_EXIT
8745 	return rv;
8746     }
8747 
8748     /*
8749      * Register a handler that will be called when the control changes
8750      * value.  Note that if the control does not support this
8751      * operation, it will return ENOSYS.  When a control event comes
8752      * in, the control_event_val_cb method on the first parameter will
8753      * be called with the following parameters: <self> <control>
8754      * <valid1> [<valid2> ...] val1 [<val2> ...].  The valid fields
8755      * tell if a particular value is corrected, the number of these
8756      * is the same as what get_num_vals() returns for this control.
8757      * the val fields are the actual values, the value is valid only
8758      * if the valid field corresponding to it is true.
8759      */
add_event_handler(swig_cb * handler)8760     int add_event_handler(swig_cb *handler)
8761     {
8762 	ipmi_control_add_val_event_handler_cl
8763 	    (self, control_val_event_handler_cl, NULL);
8764 	cb_add(control, val_event, control_event_val_cb);
8765     }
8766 
8767     /*
8768      * Remove a control event handler.
8769      */
remove_event_handler(swig_cb * handler)8770     int remove_event_handler(swig_cb *handler)
8771     {
8772 	cb_rm(control, val_event, control_event_val_cb);
8773     }
8774 
8775 %constant int CONTROL_COLOR_BLACK = IPMI_CONTROL_COLOR_BLACK;
8776 %constant int CONTROL_COLOR_WHITE = IPMI_CONTROL_COLOR_WHITE;
8777 %constant int CONTROL_COLOR_RED = IPMI_CONTROL_COLOR_RED;
8778 %constant int CONTROL_COLOR_GREEN = IPMI_CONTROL_COLOR_GREEN;
8779 %constant int CONTROL_COLOR_BLUE = IPMI_CONTROL_COLOR_BLUE;
8780 %constant int CONTROL_COLOR_YELLOW = IPMI_CONTROL_COLOR_YELLOW;
8781 %constant int CONTROL_COLOR_ORANGE = IPMI_CONTROL_COLOR_ORANGE;
8782 %constant int CONTROL_NUM_COLORS = IPMI_CONTROL_COLOR_ORANGE+1;
8783 
8784     /*
8785      * This describes a setting for a light.  There are two types of
8786      * lights.  One type has a general ability to be set to a color, on
8787      * time, and off time.  The other has a pre-defined set of
8788      * transitions.  For transition-based lights, each light is defined to
8789      * go through a number of transitions.  Each transition is described
8790      * by a color, a time (in milliseconds) that the color is present.
8791      * For non-blinking lights, there will only be one transition.  For
8792      * blinking lights, there will be one or more transitions.
8793      */
8794 
8795     /*
8796      * If this returns true, then you set the light with the
8797      * set_light() function and get the values with the get_light()
8798      * function.  Otherwise you get/set it with the normal
8799      * get_val/set_valfunctions and use the transitions functions to
8800      * get what the LED can do.
8801      */
light_set_with_setting()8802     int light_set_with_setting()
8803     {
8804 	return ipmi_control_light_set_with_setting(self);
8805     }
8806 
8807     /*
8808      * Allows detecting if a setting light supports a specific
8809      * color.
8810      */
light_is_color_supported(int light_num,int color)8811     int light_is_color_supported(int light_num, int color)
8812     {
8813 	return ipmi_control_light_is_color_sup(self, light_num, color);
8814     }
8815 
8816     /*
8817      * Returns true if the light has a local control mode, false if
8818      * not.
8819      */
light_has_local_control(int light_num)8820     int light_has_local_control(int light_num)
8821     {
8822 	return ipmi_control_light_has_loc_ctrl(self, light_num);
8823     }
8824 
8825     /*
8826      * Set a setting style light's settings.  The first parm is a
8827      * string in the form:
8828      * "[lc] <color> <on_time> <off time>[:[lc] <color>...]".  The
8829      * second parm turns on or off local control of the light.  When
8830      * the operation is complete the control_set_val_cb method on the
8831      * second parameter (if it is supplied) will be called with the
8832      * following parameters: <self> <control> <err>.
8833      */
8834     int set_light(char *settings, swig_cb *handler = NULL)
8835     {
8836 	ipmi_light_setting_t *s;
8837 	int                  rv;
8838 	swig_cb_val          *handler_val = NULL;
8839 	ipmi_control_op_cb   done = NULL;
8840 
8841 	IPMI_SWIG_C_CB_ENTRY
8842 	rv = str_to_light_setting(settings, &s);
8843 	if (rv)
8844 	    goto out_err;
8845 
8846 	if (ipmi_light_setting_get_count(s)
8847 	    != ipmi_control_get_num_vals(self))
8848 	{
8849 	    free(s);
8850 	    rv = EINVAL;
8851 	    goto out_err;
8852 	}
8853 
8854 	if (!nil_swig_cb(handler)) {
8855 	    if (! valid_swig_cb(handler, control_set_val_cb)) {
8856 		rv = EINVAL;
8857 		goto out_err;
8858 	    }
8859 	    handler_val = ref_swig_cb(handler, control_set_val_cb);
8860 	    done = control_val_set_handler;
8861 	}
8862 	rv = ipmi_control_set_light(self, s, done, handler_val);
8863 	if (rv && handler_val)
8864 	    deref_swig_cb_val(handler_val);
8865 	ipmi_free_light_settings(s);
8866     out_err:
8867 	IPMI_SWIG_C_CB_EXIT
8868 	return rv;
8869     }
8870 
8871     /*
8872      * Get the current values of the light.  The control_get_light_cb
8873      * method on the first parm will be called with the following
8874      * parameters: <self> <control> <err> <light settings>
8875      * The light settings is a string with each light separated by
8876      * colons with the (optional) local control (lc), color, on, and
8877      * off time like this:
8878      * "[lc] <color> <on_time> <off time>[:[lc] <color>...]"
8879      */
get_light(swig_cb * handler)8880     int get_light(swig_cb *handler)
8881     {
8882 	swig_cb_val            *handler_val = NULL;
8883 	ipmi_light_settings_cb done = NULL;
8884 	int                    rv;
8885 
8886 	IPMI_SWIG_C_CB_ENTRY
8887 	if (! valid_swig_cb(handler, control_get_light_cb))
8888 	    rv = EINVAL;
8889 	else {
8890 	    handler_val = ref_swig_cb(handler, control_get_light_cb);
8891 	    done = control_val_get_light_handler;
8892 
8893 	    rv = ipmi_control_get_light(self, done, handler_val);
8894 	    if (rv && handler_val)
8895 		deref_swig_cb_val(handler_val);
8896 	}
8897 	IPMI_SWIG_C_CB_EXIT
8898 	return rv;
8899     }
8900 
8901     /*
8902      * For lights that are transition based, this returns the number
8903      * of values for a specific light.  So if you put a 2 in the first
8904      * parm, this will return the number of possible settings for the
8905      * 3rd light.
8906      */
get_num_light_values(int light)8907     int get_num_light_values(int light)
8908     {
8909 	return ipmi_control_get_num_light_values(self, light);
8910     }
8911 
8912     /*
8913      * For lights that are transition based, return the number of
8914      * transitions for the given light and value setting.  So if you
8915      * put a 1 and a 3, this returns the number of transitions that
8916      * the second light will go through if you set it's value to 3.
8917      * Each transition will have a color and duration time and can be
8918      * fetched with other values.  Returns -1 if the inputs are
8919      * invalid.
8920      */
get_num_light_transitions(int light,int value)8921     int get_num_light_transitions(int light, int value)
8922     {
8923 	return ipmi_control_get_num_light_transitions(self, light, value);
8924     }
8925 
8926     /*
8927      * For lights that are transition based, return the color of the
8928      * given transition.  Returns -1 if the inputs are invalid.
8929      */
get_light_color(int light,int value,int transition)8930     int get_light_color(int light, int value, int transition)
8931     {
8932 	return ipmi_control_get_light_color(self, light, value, transition);
8933     }
8934 
8935     /*
8936      * For lights that are transition based, return the duration of
8937      * the given transition.  Returns -1 if the inputs are invalid.
8938      */
get_light_color_time(int light,int value,int transition)8939     int get_light_color_time(int light, int value, int transition)
8940     {
8941 	return ipmi_control_get_light_color_time(self, light, value,
8942 						 transition);
8943     }
8944 
8945     /*
8946      * Set the value of the identifier.  The first parameter is a
8947      * reference to an array of byte values to se the identifier to.
8948      * When the setting is complete, the control_set_val_cb method on
8949      * the second parameter (if it is supplied) will be called with
8950      * the following parameters: <self> <control> <err>.
8951      */
8952     int identifier_set_val(intarray val, swig_cb *handler = NULL)
8953     {
8954 	swig_cb_val        *handler_val = NULL;
8955 	ipmi_control_op_cb done = NULL;
8956 	int                rv;
8957 	unsigned char      *data;
8958 	int                i;
8959 
8960 	IPMI_SWIG_C_CB_ENTRY
8961 	data = malloc(val.len);
8962 	if (!data) {
8963 	    rv = ENOMEM;
8964 	    goto out_err;
8965 	}
8966 	for (i=0; i<val.len; i++)
8967 	    data[i] = val.val[i];
8968 
8969 	if (!nil_swig_cb(handler)) {
8970 	    if (! valid_swig_cb(handler, control_set_val_cb)) {
8971 		free(data);
8972 		rv = EINVAL;
8973 		goto out_err;
8974 	    }
8975 	    handler_val = ref_swig_cb(handler, control_set_val_cb);
8976 	    done = control_val_set_handler;
8977 	}
8978 	rv = ipmi_control_identifier_set_val(self, data, val.len,
8979 					     done, handler_val);
8980 	if (rv && handler_val)
8981 	    deref_swig_cb_val(handler_val);
8982 	free(data);
8983     out_err:
8984 	IPMI_SWIG_C_CB_EXIT
8985 	return rv;
8986     }
8987 
8988     /*
8989      * Get the value of the identifier control.  The control_get_id_cb
8990      * method on the first parameter will be called when the operation
8991      * completes.  The values passed to that method will be:
8992      * <self> <control> <err> byte1 [<byte2> ...].
8993      * The id value is all the bytes after the error value.
8994      */
identifier_get_val(swig_cb * handler)8995     int identifier_get_val(swig_cb *handler)
8996     {
8997 	swig_cb_val                    *handler_val = NULL;
8998 	ipmi_control_identifier_val_cb done = NULL;
8999 	int                            rv;
9000 
9001 	IPMI_SWIG_C_CB_ENTRY
9002 	if (! valid_swig_cb(handler, control_get_id_cb))
9003 	    rv = EINVAL;
9004 	else {
9005 	    handler_val = ref_swig_cb(handler, control_get_id_cb);
9006 	    done = control_val_get_id_handler;
9007 
9008 	    rv = ipmi_control_identifier_get_val(self, done, handler_val);
9009 	    if (rv && handler_val)
9010 		deref_swig_cb_val(handler_val);
9011 	}
9012 	IPMI_SWIG_C_CB_EXIT
9013 	return rv;
9014     }
9015 
9016     /*
9017      * Return the maximum possible length of the identifier control's
9018      * value.
9019      */
identifier_get_max_length()9020     int identifier_get_max_length()
9021     {
9022 	return ipmi_control_identifier_get_max_length(self);
9023     }
9024 }
9025 
9026 /*
9027  * Convert the FRU index to a string.  Returns undefined if the
9028  * index is out of range.
9029  */
9030 %rename(fru_index_to_str) ipmi_fru_index_to_str;
9031 extern char *ipmi_fru_index_to_str(int idx);
9032 
9033 /*
9034  * Convert a name to an index.  Returns -1 if the name is not valid.
9035  */
9036 %rename(fru_str_to_index) ipmi_fru_str_to_index;
9037 extern int ipmi_fru_str_to_index(char *name);
9038 
9039 /*
9040  * A FRU object
9041  */
9042 %extend ipmi_fru_t {
9043 
~ipmi_fru_t()9044     ~ipmi_fru_t()
9045     {
9046 	ipmi_fru_deref(self);
9047     }
9048 
9049 /* Area numbers */
9050 %constant int FRU_INTERNAL_USE_AREA = IPMI_FRU_FTR_INTERNAL_USE_AREA;
9051 %constant int FRU_CHASSIS_INFO_AREA = IPMI_FRU_FTR_CHASSIS_INFO_AREA;
9052 %constant int FRU_BOARD_INFO_AREA = IPMI_FRU_FTR_BOARD_INFO_AREA;
9053 %constant int FRU_PRODUCT_INFO_AREA = IPMI_FRU_FTR_PRODUCT_INFO_AREA;
9054 %constant int FRU_MULTI_RECORD_AREA = IPMI_FRU_FTR_MULTI_RECORD_AREA;
9055 
9056     %newobject get_domain_id;
9057     /*
9058      * Get the domain the FRU belongs to.
9059      */
get_domain_id()9060     ipmi_domain_id_t *get_domain_id()
9061     {
9062 	ipmi_domain_id_t *rv = malloc(sizeof(*rv));
9063 	if (rv)
9064 	    *rv = ipmi_fru_get_domain_id(self);
9065 	return rv;
9066     }
9067 
9068     /*
9069      * Convert the string to a FRU index.  Use this if you have a specfiic
9070      * fru data object you are after.  Returns -1 if the name is not valid.
9071      */
str_to_index(char * name)9072     int str_to_index(char *name)
9073     {
9074 	return ipmi_fru_str_to_index(name);
9075     }
9076 
9077     /*
9078      * Get a FRU data item.  The first parameter is an index to get,
9079      * the second is an integer reference to an item number.  This
9080      * returns a string of the particular object with the following:
9081      * "<name> <type> <data>".  If the index or number are invalid,
9082      * then an undefined value will be returned (NULL, undef, etc).
9083      * If the FRU item is not supported for this FRU, only the name
9084      * will be filled out and there will be no type or value.
9085      *
9086      * If the type is integer, a single integer number will follow.
9087      * If the type is ascii, an ascii string will follow starting one
9088      * space after the type.  If the type is unicode or binary, then
9089      * a set of ascii-encoded binary bytes will follow "0x01 0x03 ..."
9090      *
9091      * The second parameter (the number) is zero based and should be
9092      * set to zero when fetching an index for the first time.  It will
9093      * be unchanged if the data item does not support multiple items.
9094      * If it does support multiple items, then the number will be
9095      * changed to the next supported value, or to -1 if this is the
9096      * last item.
9097      */
9098     %newobject get;
get(int index,int * num)9099     char *get(int index, int *num)
9100     {
9101 	const char                *name;
9102 	enum ipmi_fru_data_type_e dtype;
9103 	int                       intval;
9104 	time_t                    time;
9105 	char                      *data;
9106 	unsigned int              data_len;
9107 	int                       rv;
9108 	char                      dummy[1];
9109 	char                      *str = NULL, *s;
9110 	int                       len;
9111 	int                       i;
9112 
9113 	data = NULL;
9114 	rv = ipmi_fru_get(self, index, &name, num, &dtype, &intval,
9115 			  &time, &data, &data_len);
9116 	if ((rv == ENOSYS) || (rv == E2BIG))
9117 	    return strdup(name);
9118 	else if (rv)
9119 	    return NULL;
9120 
9121 	switch(dtype) {
9122 	case IPMI_FRU_DATA_INT:
9123 	    len = snprintf(dummy, 1, "%s integer %d", name, intval);
9124 	    str = malloc(len + 1);
9125 	    sprintf(str, "%s integer %d", name, intval);
9126 	    break;
9127 
9128 	case IPMI_FRU_DATA_TIME:
9129 	    len = snprintf(dummy, 1, "%s time %ld", name, (long) time);
9130 	    str = malloc(len + 1);
9131 	    sprintf(str, "%s time %ld", name, (long) time);
9132 	    break;
9133 
9134 	case IPMI_FRU_DATA_BINARY:
9135 	    len = snprintf(dummy, 1, "%s binary", name);
9136 	    len += data_len * 5;
9137 	    str = malloc(len + 1);
9138 	    s = str;
9139 	    s += sprintf(s, "%s binary", name);
9140 	    for (i=0; i<data_len; i++)
9141 		s += sprintf(s, " 0x%2.2x", (unsigned char) data[i]);
9142 	    break;
9143 
9144 	case IPMI_FRU_DATA_UNICODE:
9145 	    len = snprintf(dummy, 1, "%s unicode", name);
9146 	    len += data_len * 5;
9147 	    str = malloc(len + 1);
9148 	    s = str;
9149 	    s += sprintf(s, "%s unicode", name);
9150 	    for (i=0; i<data_len; i++)
9151 		s += sprintf(s, " 0x%2.2x", (unsigned char) data[i]);
9152 	    break;
9153 
9154 	case IPMI_FRU_DATA_ASCII:
9155 	    len = snprintf(dummy, 1, "%s ascii %s", name, data);
9156 	    str = malloc(len + 1);
9157 	    sprintf(str, "%s ascii %s", name, data);
9158 	    break;
9159 
9160 	default:
9161 	    str = NULL;
9162 	}
9163 
9164 	if (data)
9165 	    ipmi_fru_data_free(data);
9166 
9167 	return str;
9168     }
9169 
9170     /*
9171      * Return the number of multi-records the FRU has.
9172      */
get_num_multi_records()9173     int get_num_multi_records()
9174     {
9175 	return ipmi_fru_get_num_multi_records(self);
9176     }
9177 
9178     /*
9179      * Fetch a multi record from the FRU.  The data comes out in a
9180      * string with the format:
9181      *    "<type num> <version num> [data1 [data2 ...]]"
9182      * It returns an undefined value if the num is invalid.  The data
9183      * items will not be present if the length is zero.
9184      */
9185     %newobject get_multirecord;
get_multirecord(int num)9186     char *get_multirecord(int num)
9187     {
9188 	unsigned char type;
9189 	unsigned char version;
9190 	unsigned int length;
9191 	unsigned char *data;
9192 	int           rv;
9193 	char          dummy[1];
9194 	char          *str, *s;
9195 	int           str_len;
9196 	int           i;
9197 
9198 	rv = ipmi_fru_get_multi_record_type(self, num, &type);
9199 	if (rv)
9200 	    return NULL;
9201 	rv = ipmi_fru_get_multi_record_format_version(self, num, &version);
9202 	if (rv)
9203 	    return NULL;
9204 	rv = ipmi_fru_get_multi_record_data_len(self, num, &length);
9205 	if (rv)
9206 	    return NULL;
9207 	if (length == 0)
9208 	    data = malloc(1);
9209 	else
9210 	    data = malloc(length);
9211 	if (!data)
9212 	    return NULL;
9213 	rv = ipmi_fru_get_multi_record_data(self, num, data, &length);
9214 	if (rv) {
9215 	    free(data);
9216 	    return NULL;
9217 	}
9218 
9219 	str_len = snprintf(dummy, 1, "%d %d", type, version);
9220 	str_len += length * 5;
9221 	str = malloc(str_len + 1);
9222 	if (!str) {
9223 	    free(data);
9224 	    return NULL;
9225 	}
9226 
9227 	s = str;
9228 	s += sprintf(s, "%d %d", type, version);
9229 	for (i=0; i<length; i++)
9230 	    s += sprintf(s, " 0x%2.2x", data[i]);
9231 	free(data);
9232 	return str;
9233     }
9234 
9235     /*
9236      * Set a specific data item by index (see the get function for more
9237      * info on what index and num mean).  Note that the "num "field is
9238      * not updated by this call, unlike the get function.
9239      *
9240      * The type passed in tells the kind of data being passed in.  It is
9241      * either:
9242      *  "integer" - An integer value passed in.
9243      *  "time" - An integer value passed in.
9244      *  "binary" - A string of 8-bit values is passed in, like
9245      *    "0x10 0x20 0x99".
9246      *  "unicode" - A string of 8-bit values is passed in, like
9247      *    "0x10 0x20 0x99".
9248      *  "ascii" - The string passed in is used.
9249      * Passing an undefined value for binary, unicode, and ascii
9250      * will result in the field being cleared or (for custom fields)
9251      * deleted.  NULL values are not allowed for integer or time.
9252      */
9253     int set(int index, int num, char *type, char *value = NULL)
9254     {
9255 	if (!type)
9256 	    return EINVAL;
9257 	if (strcmp(type, "integer") == 0) {
9258 	    unsigned int val;
9259 	    char         *endstr;
9260 	    if (!value)
9261 		return EINVAL;
9262 	    if (*value == '\0')
9263 		return EINVAL;
9264 	    val = strtol(value, &endstr, 0);
9265 	    if (*endstr != '\0')
9266 		return EINVAL;
9267 	    return ipmi_fru_set_int_val(self, index, num, val);
9268 	} else if (strcmp(type, "time") == 0) {
9269 	    unsigned int val;
9270 	    char         *endstr;
9271 	    if (!value)
9272 		return EINVAL;
9273 	    if (*value == '\0')
9274 		return EINVAL;
9275 	    val = strtol(value, &endstr, 0);
9276 	    if (*endstr != '\0')
9277 		return EINVAL;
9278 	    return ipmi_fru_set_time_val(self, index, num, val);
9279 	} else if (strcmp(type, "binary") == 0) {
9280 	    unsigned int length = 0;
9281 	    unsigned char *data;
9282 	    int rv;
9283 	    if (!value) {
9284 		data = NULL;
9285 	    } else {
9286 		data = parse_raw_str_data(value, &length);
9287 		if (!data)
9288 		    return ENOMEM;
9289 	    }
9290 	    rv = ipmi_fru_set_data_val(self, index, num, IPMI_FRU_DATA_BINARY,
9291 				       (char *) data, length);
9292 	    if (data)
9293 		free(data);
9294 	    return rv;
9295 	} else if (strcmp(type, "unicode") == 0) {
9296 	    unsigned int length = 0;
9297 	    unsigned char *data;
9298 	    int rv;
9299 	    if (!value) {
9300 		data = NULL;
9301 	    } else {
9302 		data = parse_raw_str_data(value, &length);
9303 		if (!data)
9304 		    return ENOMEM;
9305 	    }
9306 	    rv = ipmi_fru_set_data_val(self, index, num, IPMI_FRU_DATA_UNICODE,
9307 				       (char *) data, length);
9308 	    if (data)
9309 		free(data);
9310 	    return rv;
9311 	} else if (strcmp(type, "ascii") == 0) {
9312 	    int length = 0;
9313 	    if (value)
9314 		length = strlen(value);
9315 	    return ipmi_fru_set_data_val(self, index, num, IPMI_FRU_DATA_ASCII,
9316 					 value, length);
9317 	} else {
9318 	    return EINVAL;
9319 	}
9320     }
9321 
9322     /*
9323      * Set a specific data item by index (see the get function for more
9324      * info on what index and num mean).  Note that the "num" field is
9325      * not updated by this call, unlike the get function.
9326      *
9327      * The type passed in tells the kind of data being passed in.  It is
9328      * either:
9329      *  "integer" - The first element of the integer array is used.
9330      *  "time" - The first element of the integer array is used.
9331      *  "binary" - An array of 8-bit values is taken, like
9332      *    [ 0x10, 0x20, 0x99 ].
9333      *  "unicode" - An array of 8-bit values is passed in, like
9334      *    [ 0x10, 0x20, 0x99 ].
9335      *  "ascii" - An array of 8-bit values is passed in, like
9336      *    [ 0x10, 0x20, 0x99 ].
9337      * Undefined values are not allowed here, but that shouldn't
9338      * matter because the above function should be used for those.
9339      */
set_array(int index,int num,char * type,intarray value)9340     int set_array(int index, int num, char *type, intarray value)
9341     {
9342 	if (value.len < 0)
9343 	    return EINVAL;
9344 	if (!type)
9345 	    return EINVAL;
9346 
9347 	if (strcmp(type, "integer") == 0) {
9348 	    /* Only take the first value. */
9349 	    if (value.len <= 0)
9350 		return EINVAL;
9351 	    return ipmi_fru_set_int_val(self, index, num, value.val[0]);
9352 	} else if (strcmp(type, "time") == 0) {
9353 	    /* Only take the first value. */
9354 	    if (value.len <= 0)
9355 		return EINVAL;
9356 	    return ipmi_fru_set_time_val(self, index, num, value.val[0]);
9357 	} else if (strcmp(type, "binary") == 0) {
9358 	    unsigned int length = value.len;
9359 	    unsigned char *data;
9360 	    int rv;
9361 
9362 	    if (length == 0)
9363 		data = malloc(1);
9364 	    else
9365 		data = malloc(length);
9366 	    if (!data)
9367 		return ENOMEM;
9368 	    parse_ipmi_data(value, data, length, &length);
9369 	    rv = ipmi_fru_set_data_val(self, index, num, IPMI_FRU_DATA_BINARY,
9370 				       (char *) data, length);
9371 	    free(data);
9372 	    return rv;
9373 	} else if (strcmp(type, "unicode") == 0) {
9374 	    unsigned int length = value.len;
9375 	    unsigned char *data = malloc(length);
9376 	    int rv;
9377 	    if (!data)
9378 		return EINVAL;
9379 	    parse_ipmi_data(value, data, length, &length);
9380 	    rv = ipmi_fru_set_data_val(self, index, num, IPMI_FRU_DATA_UNICODE,
9381 				       (char *) data, length);
9382 	    free(data);
9383 	    return rv;
9384 	} else if (strcmp(type, "ascii") == 0) {
9385 	    unsigned int length = value.len;
9386 	    unsigned char *data;
9387 	    int rv;
9388 	    if (length == 0)
9389 		data = malloc(1);
9390 	    else
9391 		data = malloc(length);
9392 	    if (!data)
9393 		return ENOMEM;
9394 	    parse_ipmi_data(value, data, length, &length);
9395 	    rv = ipmi_fru_set_data_val(self, index, num, IPMI_FRU_DATA_ASCII,
9396 				       (char *) data, length);
9397 	    free(data);
9398 	    return rv;
9399 	} else {
9400 	    return EINVAL;
9401 	}
9402     }
9403 
9404     /*
9405      * Set multi-record fields from a string of the form:
9406      *  "0x10 0x20 0x99"
9407      *
9408      * It take a number (which multi-record), type, version, and a
9409      * string value.  Passing in an undefined value will delete the
9410      * specific multi-record.  Note that if the number is less than
9411      * the number of fields in the record, then the record will be
9412      * replaced.  If it is larger than or equal to the number of
9413      * fields, a new record will be appended in the next location, not
9414      * in the number supplied.
9415      */
9416     int set_multirecord(unsigned int num,
9417 			unsigned int type,
9418 			unsigned int version,
9419 			char         *value = NULL)
9420     {
9421 	unsigned int length = 0;
9422 	unsigned char *data;
9423 	int rv;
9424 
9425 	if (!value) {
9426 	    data = NULL;
9427 	} else {
9428 	    data = parse_raw_str_data(value, &length);
9429 	    if (!data)
9430 		return ENOMEM;
9431 	}
9432 	rv = ipmi_fru_set_multi_record(self, num, type, version,
9433 				       data, length);
9434 	if (data)
9435 	    free(data);
9436 	return rv;
9437     }
9438 
9439     /*
9440      * Set multi-record fields from a string of the form:
9441      *  "0x10 0x20 0x99"
9442      *
9443      * It take a number (which multi-record), type, version, and an
9444      * integer array.  Undefined values are not allowed here, use
9445      * the previous call to delete records.  Note that if the number
9446      * is less than the number of fields in the record, then the
9447      * record will be replaced.  If it is larger than or equal to the
9448      * number of fields, a new record will be appended in the next
9449      * location, not in the number supplied.
9450      */
set_multirecord_array(unsigned int num,unsigned int type,unsigned int version,intarray value)9451     int set_multirecord_array(unsigned int num,
9452 			      unsigned int type,
9453 			      unsigned int version,
9454 			      intarray     value)
9455     {
9456 	unsigned int length = value.len;
9457 	unsigned char *data;
9458 	int rv;
9459 
9460 	if (length == 0)
9461 	    data = malloc(1);
9462 	else
9463 	    data = malloc(length);
9464 	if (!data)
9465 	    return ENOMEM;
9466 	parse_ipmi_data(value, data, length, &length);
9467 	rv = ipmi_fru_set_multi_record(self, num, type, version,
9468 				       data, length);
9469 	free(data);
9470 	return rv;
9471     }
9472 
9473     /*
9474      * Add a new area to the FRU.  You must pass in the area number, the
9475      * start offset and length of the area.  The offset must be a multiple
9476      * of 8 and the length will be truncated to a multiple of 8.
9477      */
add_area(unsigned int area,unsigned int offset,unsigned int length)9478     int add_area(unsigned int area,
9479 		 unsigned int offset,
9480 		 unsigned int length)
9481     {
9482 	return ipmi_fru_add_area(self, area, offset, length);
9483     }
9484 
9485     /*
9486      * Delete the given area from the FRU.
9487      */
delete_area(int area)9488     int delete_area(int area)
9489     {
9490 	return ipmi_fru_delete_area(self, area);
9491     }
9492 
9493     /*
9494      * Get the offset of the given area into the offset pointer.
9495      */
area_get_offset(unsigned int area,unsigned int * offset)9496     int area_get_offset(unsigned int area,
9497 			unsigned int *offset)
9498     {
9499 	return ipmi_fru_area_get_offset(self, area, offset);
9500     }
9501 
9502     /*
9503      * Get the length of the given area into the length pointer.
9504      */
area_get_length(unsigned int area,unsigned int * length)9505     int area_get_length(unsigned int area,
9506 			unsigned int *length)
9507     {
9508 	return ipmi_fru_area_get_length(self, area, length);
9509     }
9510 
9511     /*
9512      * Set the offset of the given area.
9513      */
area_set_offset(unsigned int area,unsigned int offset)9514     int area_set_offset(unsigned int area,
9515 			unsigned int offset)
9516     {
9517 	return ipmi_fru_area_set_offset(self, area, offset);
9518     }
9519 
9520     /*
9521      * Set the length of the given area.
9522      */
area_set_length(unsigned int area,unsigned int length)9523     int area_set_length(unsigned int area,
9524 			unsigned int length)
9525     {
9526 	return ipmi_fru_area_set_length(self, area, length);
9527     }
9528 
9529     /*
9530      * Get the number of bytes currently used in the given area into
9531      * the used_length pointer.
9532      */
area_get_used_length(unsigned int area,unsigned int * used_length)9533     int area_get_used_length(unsigned int area,
9534 			     unsigned int *used_length)
9535     {
9536 	return ipmi_fru_area_get_used_length(self, area, used_length);
9537     }
9538 
9539     /*
9540      * Write the contents of the fru back into the FRU device.  If the
9541      * handler (first parm) is non-null, the "fru_written" method on
9542      * that object will be called with the domain as the first
9543      * parameter, the FRU as the second parameter and the error value
9544      * for the write as the third parameter.
9545      */
9546     int write(swig_cb *handler = NULL)
9547     {
9548 	int         rv;
9549 	swig_cb_val *handler_val = NULL;
9550 	ipmi_fru_cb cb_handler = NULL;
9551 
9552 	IPMI_SWIG_C_CB_ENTRY
9553 	if (!nil_swig_cb(handler)) {
9554 	    if (! valid_swig_cb(handler, fru_written)) {
9555 		rv = EINVAL;
9556 		goto out_err;
9557 	    }
9558 	    cb_handler = fru_written_done;
9559 	    handler_val = ref_swig_cb(handler, fru_written);
9560 	    ipmi_fru_ref(self);
9561 	}
9562 
9563 	rv = ipmi_fru_write(self, cb_handler, handler_val);
9564 	if (rv) {
9565 	    if (handler_val)
9566 		deref_swig_cb_val(handler_val);
9567 	}
9568     out_err:
9569 	IPMI_SWIG_C_CB_EXIT
9570 	return rv;
9571     }
9572 
multi_record_get_root_node(unsigned int record_num,const char ** name,ipmi_fru_node_t ** sub_node)9573     int multi_record_get_root_node(unsigned int    record_num,
9574 				   const char      **name,
9575 				   ipmi_fru_node_t **sub_node)
9576     {
9577 	int rv;
9578 	rv = ipmi_fru_multi_record_get_root_node(self, record_num,
9579 						 name, sub_node);
9580 	return rv;
9581     }
9582 
get_root_node(const char ** type,ipmi_fru_node_t ** sub_node)9583     int get_root_node(const char **type, ipmi_fru_node_t **sub_node)
9584     {
9585 	return ipmi_fru_get_root_node(self, type, sub_node);
9586     }
9587 }
9588 
9589 /*
9590  * A FRU node object
9591  */
9592 %extend ipmi_fru_node_t {
~ipmi_fru_node_t()9593     ~ipmi_fru_node_t()
9594     {
9595 	ipmi_fru_put_node(self);
9596     }
9597 
get_field(unsigned int index,const char ** name,const char ** type,char ** value,ipmi_fru_node_t ** sub_node)9598     int get_field(unsigned int    index,
9599 		  const char      **name,
9600 		  const char      **type,
9601 		  char            **value,
9602 		  ipmi_fru_node_t **sub_node)
9603     {
9604 	int                       rv;
9605 	enum ipmi_fru_data_type_e dtype;
9606 	int                       intval;
9607 	double                    floatval;
9608 	time_t                    time;
9609 	char                      *data = NULL;
9610 	unsigned int              data_len;
9611 	int                       len;
9612 	char                      dummy[1];
9613 	char                      *str, *s;
9614 	int                       i;
9615 
9616 	rv = ipmi_fru_node_get_field(self,
9617 				     index,
9618 				     name,
9619 				     &dtype,
9620 				     &intval,
9621 				     &time,
9622 				     &floatval,
9623 				     &data,
9624 				     &data_len,
9625 				     sub_node);
9626 	if (rv)
9627 	    return rv;
9628 
9629 	switch(dtype) {
9630 	case IPMI_FRU_DATA_INT:
9631 	    len = snprintf(dummy, 1, "%d", intval);
9632 	    str = malloc(len + 1);
9633 	    sprintf(str, "%d", intval);
9634 	    *type = "integer";
9635 	    break;
9636 
9637 	case IPMI_FRU_DATA_BOOLEAN:
9638 	    len = snprintf(dummy, 1, "%d", intval);
9639 	    str = malloc(len + 1);
9640 	    sprintf(str, "%d", intval);
9641 	    *type = "boolean";
9642 	    break;
9643 
9644 	case IPMI_FRU_DATA_TIME:
9645 	    len = snprintf(dummy, 1, "%ld", (long) time);
9646 	    str = malloc(len + 1);
9647 	    sprintf(str, "%ld", (long) time);
9648 	    *type = "time";
9649 	    break;
9650 
9651 	case IPMI_FRU_DATA_FLOAT:
9652 	    len = snprintf(dummy, 1, "%lf", floatval);
9653 	    str = malloc(len + 1);
9654 	    sprintf(str, "%lf", floatval);
9655 	    *type = "float";
9656 	    break;
9657 
9658 	case IPMI_FRU_DATA_BINARY:
9659 	    len = data_len * 5;
9660 	    str = malloc(len + 1);
9661 	    s = str;
9662 	    if (data_len > 0)
9663 		s += sprintf(s, "0x%2.2x", (unsigned char) data[0]);
9664 	    else
9665 		*s = '\0';
9666 	    for (i=1; i<data_len; i++)
9667 		s += sprintf(s, " 0x%2.2x", (unsigned char) data[i]);
9668 	    *type = "binary";
9669 	    break;
9670 
9671 	case IPMI_FRU_DATA_UNICODE:
9672 	    len = data_len * 5;
9673 	    str = malloc(len + 1);
9674 	    s = str;
9675 	    if (data_len > 0)
9676 		s += sprintf(s, "0x%2.2x", (unsigned char) data[0]);
9677 	    else
9678 		*s = '\0';
9679 	    for (i=1; i<data_len; i++)
9680 		s += sprintf(s, " 0x%2.2x", (unsigned char) data[i]);
9681 	    *type = "unicode";
9682 	    break;
9683 
9684 	case IPMI_FRU_DATA_ASCII:
9685 	    str = strdup(data);
9686 	    *type = "ascii";
9687 	    break;
9688 
9689 	case IPMI_FRU_DATA_SUB_NODE:
9690 	    str = NULL;
9691 	    *type = "subnode";
9692 
9693 	    /* Put the array length (or the -1) in the value */
9694 	    len = snprintf(dummy, 1, "%d", intval);
9695 	    str = malloc(len + 1);
9696 	    sprintf(str, "%d", intval);
9697 	    break;
9698 
9699 	default:
9700 	    str = NULL;
9701 	}
9702 
9703 	if (data)
9704 	    ipmi_fru_data_free(data);
9705 
9706 	*value = str;
9707 
9708 	return 0;
9709     }
9710 
get_enum_val(unsigned int index,int * pos,int * nextpos,const char ** data)9711     int get_enum_val(unsigned int index,
9712 		     int          *pos,
9713 		     int          *nextpos,
9714 		     const char   **data)
9715     {
9716 	return ipmi_fru_node_get_enum_val(self, index, pos, nextpos, data);
9717     }
9718 
set_field(unsigned int index,const char * type,char * value)9719     int set_field(unsigned int    index,
9720 		  const char      *type,
9721 		  char            *value)
9722     {
9723 	int                       rv;
9724 	enum ipmi_fru_data_type_e dtype;
9725 	int                       intval = 0;
9726 	double                    floatval = 0.0;
9727 	time_t                    time = 0;
9728 	char                      *data = NULL;
9729 	unsigned int              data_len = 0;
9730 	char                      *s;
9731 
9732 	if (!type)
9733 	    return EINVAL;
9734 
9735 	if (strcmp(type, "subnode") == 0) {
9736 	    dtype = IPMI_FRU_DATA_SUB_NODE;
9737 	    if (value) {
9738 		data = (char *) parse_raw_str_data(value, &data_len);
9739 		if (!data)
9740 		    return ENOMEM;
9741 	    }
9742 	    goto ready_to_set;
9743 	} else if (strcmp(type, "binary") == 0) {
9744 	    dtype = IPMI_FRU_DATA_BINARY;
9745 	    if (value) {
9746 		data = (char *) parse_raw_str_data(value, &data_len);
9747 		if (!data)
9748 		    return ENOMEM;
9749 	    }
9750 	    goto ready_to_set;
9751 	} else if (strcmp(type, "unicode") == 0) {
9752 	    dtype = IPMI_FRU_DATA_UNICODE;
9753 	    if (value) {
9754 		data = (char *) parse_raw_str_data(value, &data_len);
9755 		if (!data)
9756 		    return ENOMEM;
9757 	    }
9758 	    goto ready_to_set;
9759 	} else if (strcmp(type, "ascii") == 0) {
9760 	    dtype = IPMI_FRU_DATA_ASCII;
9761 	    if (value) {
9762 		data = strdup(value);
9763 		if (!data)
9764 		    return ENOMEM;
9765 		data_len = strlen(value);
9766 	    }
9767 	    goto ready_to_set;
9768 	}
9769 
9770 	if (!value || !(*value))
9771 	    return EINVAL;
9772 
9773 	if (strcmp(type, "integer") == 0) {
9774 	    dtype = IPMI_FRU_DATA_INT;
9775 	    intval = strtol(value, &s, 0);
9776 	    if (*s != '\0')
9777 		return EINVAL;
9778 	} else if (strcmp(type, "boolean") == 0) {
9779 	    dtype = IPMI_FRU_DATA_BOOLEAN;
9780 	    intval = strtol(value, &s, 0);
9781 	    if (*s == '\0')
9782 		intval = !!intval;
9783 	    else if (strcasecmp(value, "true") == 0)
9784 		intval = 1;
9785 	    else if (strcasecmp(value, "false") == 0)
9786 		intval = 0;
9787 	    else
9788 		return EINVAL;
9789 	} else if (strcmp(type, "time") == 0) {
9790 	    dtype = IPMI_FRU_DATA_TIME;
9791 	    time = strtol(value, &s, 0);
9792 	    if (*s != '\0')
9793 		return EINVAL;
9794 	} else if (strcmp(type, "float") == 0) {
9795 	    dtype = IPMI_FRU_DATA_FLOAT;
9796 	    floatval = strtod(value, &s);
9797 	    if (*s != '\0')
9798 		return EINVAL;
9799 	} else
9800 	    return EINVAL;
9801 
9802     ready_to_set:
9803 	rv = ipmi_fru_node_set_field(self, index, dtype, intval, time,
9804 				     floatval, data, data_len);
9805 
9806 	if (data)
9807 	    free(data);
9808 	return rv;
9809     }
9810 
settable(unsigned int index)9811     int settable(unsigned int index)
9812     {
9813 	return ipmi_fru_node_settable(self, index);
9814     }
9815 
get_subtype()9816     char *get_subtype()
9817     {
9818 	enum ipmi_fru_data_type_e dtype;
9819 	char                      *type;
9820 	int                       rv;
9821 
9822 	rv = ipmi_fru_node_get_subtype(self, &dtype);
9823 	if (rv)
9824 	    return NULL;
9825 	switch (dtype) {
9826 	case IPMI_FRU_DATA_INT:
9827 	    type = "integer";
9828 	    break;
9829 
9830 	case IPMI_FRU_DATA_BOOLEAN:
9831 	    type = "boolean";
9832 	    break;
9833 
9834 	case IPMI_FRU_DATA_TIME:
9835 	    type = "time";
9836 	    break;
9837 
9838 	case IPMI_FRU_DATA_FLOAT:
9839 	    type = "float";
9840 	    break;
9841 
9842 	case IPMI_FRU_DATA_BINARY:
9843 	    type = "binary";
9844 	    break;
9845 
9846 	case IPMI_FRU_DATA_UNICODE:
9847 	    type = "unicode";
9848 	    break;
9849 
9850 	case IPMI_FRU_DATA_ASCII:
9851 	    type = "ascii";
9852 	    break;
9853 
9854 	case IPMI_FRU_DATA_SUB_NODE:
9855 	    type = "subnode";
9856 	    break;
9857 
9858 	default:
9859 	    return NULL;
9860 	}
9861 
9862 	return type;
9863     }
9864 }
9865 
9866 /*
9867  * An event object
9868  */
9869 %extend ipmi_event_t {
~ipmi_event_t()9870     ~ipmi_event_t()
9871     {
9872 	ipmi_event_free(self);
9873     }
9874 
9875     /* When you are done with an event, you should delete it.  This
9876        removes the event from the local event queue and removes it
9877        from the external system event log. */
9878     int delete(swig_cb *handler = NULL)
9879     {
9880 	swig_cb_val    *handler_val = NULL;
9881 	ipmi_domain_cb done = NULL;
9882 	int            rv;
9883 
9884 	IPMI_SWIG_C_CB_ENTRY
9885 	if (!nil_swig_cb(handler)) {
9886 	    if (! valid_swig_cb(handler, event_delete_cb)) {
9887 		rv = EINVAL;
9888 		goto out_err;
9889 	    }
9890 	    handler_val = ref_swig_cb(handler, event_delete_cb);
9891 	    done = event_deleted_handler;
9892 	}
9893 	rv = ipmi_event_delete(self, done, handler_val);
9894 	if (rv && handler_val)
9895 	    deref_swig_cb_val(handler_val);
9896     out_err:
9897 	IPMI_SWIG_C_CB_EXIT
9898 	return rv;
9899     }
9900 
9901 
9902     %newobject get_mc_id;
9903     /*
9904      * Get the MC id the event came from.  Note that the MC may not exist
9905      * any more.
9906      */
get_mc_id()9907     ipmi_mcid_t *get_mc_id()
9908     {
9909 	ipmi_mcid_t *rv = malloc(sizeof(*rv));
9910 	if (rv)
9911 	    *rv = ipmi_event_get_mcid(self);
9912 	return rv;
9913     }
9914 
9915     /*
9916      * Get the event's record id
9917      */
get_record_id()9918     int get_record_id()
9919     {
9920 	return ipmi_event_get_record_id(self);
9921     }
9922 
9923     /*
9924      * Get the event's type.
9925      */
get_type()9926     int get_type()
9927     {
9928 	return ipmi_event_get_type(self);
9929     }
9930 
9931     /*
9932      * Get the event's timestamp.  This is in seconds.
9933      */
get_timestamp()9934     double get_timestamp()
9935     {
9936 	return ((double) ipmi_event_get_timestamp(self)) / 1000000000.0;
9937     }
9938 
9939     /*
9940      * Get the data from the event.  This returns a reference to an
9941      * array, so you have to reference it like @$val.
9942      */
get_data()9943     intarray get_data()
9944     {
9945 	intarray      rv;
9946 	int           i;
9947 	unsigned char *data;
9948 	int           data_len;
9949 
9950 	data_len = ipmi_event_get_data_len(self);
9951 	data = malloc(data_len);
9952 	data_len = ipmi_event_get_data(self, data, 0, data_len);
9953 	rv.val = malloc(sizeof(int) * data_len);
9954 	for (i=0; i<data_len; i++)
9955 	    rv.val[i] = data[i];
9956 	free(data);
9957 	rv.len = data_len;
9958 	return rv;
9959     }
9960 
9961     /* Call the sensor callback for the event.  If the sensor is a
9962      * threshold sensor, the threshold_event_cb method will be called
9963      * on the sensor. Otherwise, the sensor is discrete and the
9964      * discrete_event_cb will be called.  The threshold_event_cb
9965      * method takes the following parameters:
9966      * <self> <sensor> <event spec> <raw_set> <raw> <value_set> <value> <event>
9967      * The discrete_event_cb method takes the following parameters:
9968      * <self> <sensor> <event spec> <severity> <old_severity> <event>
9969      *
9970      * Note: In the future, this may take control callbacks, too.
9971      */
call_handler(swig_cb * handler)9972     int call_handler(swig_cb *handler)
9973     {
9974 	event_call_handler_data_t info;
9975 	int                       rv;
9976 
9977 	if (! valid_swig_2cb(handler, threshold_event_cb, discrete_event_cb))
9978 	    return EINVAL;
9979 
9980 	info.handlers = ipmi_event_handlers_alloc();
9981 	if (! info.handlers)
9982 	    return ENOMEM;
9983 
9984 	ipmi_event_handlers_set_threshold(info.handlers,
9985 					  sensor_threshold_event_handler);
9986 	ipmi_event_handlers_set_discrete(info.handlers,
9987 					 sensor_discrete_event_handler);
9988 
9989 	info.handlers_val = ref_swig_2cb(handler, threshold_event_cb,
9990 					 discrete_event_cb);
9991 
9992 	info.event = self;
9993 	info.rv = 0;
9994 	rv = ipmi_mc_pointer_cb(ipmi_event_get_mcid(self),
9995 				event_call_handler_mc_cb,
9996 				&info);
9997 	if (rv == 0)
9998 	    rv = info.rv;
9999 
10000 	ipmi_event_handlers_free(info.handlers);
10001 	deref_swig_cb_val(handler);
10002 
10003 	return rv;
10004     }
10005 }
10006 
10007 %extend ipmi_lanparm_t {
~ipmi_lanparm_t()10008     ~ipmi_lanparm_t()
10009     {
10010 	ipmi_lanparm_deref(self);
10011     }
10012 
10013     %newobject get_mc_id;
get_mc_id()10014     ipmi_mcid_t *get_mc_id()
10015     {
10016 	ipmi_mcid_t *rv = malloc(sizeof(*rv));
10017 	if (rv)
10018 	    *rv = ipmi_lanparm_get_mc_id(self);
10019 	return rv;
10020     }
10021 
get_channel()10022     int get_channel()
10023     {
10024 	return ipmi_lanparm_get_channel(self);
10025     }
10026 
10027 %constant int LANPARM_SET_IN_PROGRESS = IPMI_LANPARM_SET_IN_PROGRESS;
10028 %constant int LANPARM_AUTH_TYPE_SUPPORT = IPMI_LANPARM_AUTH_TYPE_SUPPORT;
10029 %constant int LANPARM_AUTH_TYPE_ENABLES = IPMI_LANPARM_AUTH_TYPE_ENABLES;
10030 %constant int LANPARM_IP_ADDRESS = IPMI_LANPARM_IP_ADDRESS;
10031 %constant int LANPARM_IP_ADDRESS_SRC = IPMI_LANPARM_IP_ADDRESS_SRC;
10032 %constant int LANPARM_MAC_ADDRESS = IPMI_LANPARM_MAC_ADDRESS;
10033 %constant int LANPARM_SUBNET_MASK = IPMI_LANPARM_SUBNET_MASK;
10034 %constant int LANPARM_IPV4_HDR_PARMS = IPMI_LANPARM_IPV4_HDR_PARMS;
10035 %constant int LANPARM_PRIMARY_RMCP_PORT = IPMI_LANPARM_PRIMARY_RMCP_PORT;
10036 %constant int LANPARM_SECONDARY_RMCP_PORT = IPMI_LANPARM_SECONDARY_RMCP_PORT;
10037 %constant int LANPARM_BMC_GENERATED_ARP_CNTL = IPMI_LANPARM_BMC_GENERATED_ARP_CNTL;
10038 %constant int LANPARM_GRATUIDOUS_ARP_INTERVAL = IPMI_LANPARM_GRATUIDOUS_ARP_INTERVAL;
10039 %constant int LANPARM_DEFAULT_GATEWAY_ADDR = IPMI_LANPARM_DEFAULT_GATEWAY_ADDR;
10040 %constant int LANPARM_DEFAULT_GATEWAY_MAC_ADDR = IPMI_LANPARM_DEFAULT_GATEWAY_MAC_ADDR;
10041 %constant int LANPARM_BACKUP_GATEWAY_ADDR = IPMI_LANPARM_BACKUP_GATEWAY_ADDR;
10042 %constant int LANPARM_BACKUP_GATEWAY_MAC_ADDR = IPMI_LANPARM_BACKUP_GATEWAY_MAC_ADDR;
10043 %constant int LANPARM_COMMUNITY_STRING = IPMI_LANPARM_COMMUNITY_STRING;
10044 %constant int LANPARM_NUM_DESTINATIONS = IPMI_LANPARM_NUM_DESTINATIONS;
10045 %constant int LANPARM_DEST_TYPE = IPMI_LANPARM_DEST_TYPE;
10046 %constant int LANPARM_DEST_ADDR = IPMI_LANPARM_DEST_ADDR;
10047 %constant int LANPARM_VLAN_ID = IPMI_LANPARM_VLAN_ID;
10048 %constant int LANPARM_VLAN_PRIORITY = IPMI_LANPARM_VLAN_PRIORITY;
10049 %constant int LANPARM_NUM_CIPHER_SUITE_ENTRIES = IPMI_LANPARM_NUM_CIPHER_SUITE_ENTRIES;
10050 %constant int LANPARM_CIPHER_SUITE_ENTRY_SUPPORT = IPMI_LANPARM_CIPHER_SUITE_ENTRY_SUPPORT;
10051 %constant int LANPARM_CIPHER_SUITE_ENTRY_PRIV = IPMI_LANPARM_CIPHER_SUITE_ENTRY_PRIV;
10052 %constant int LANPARM_DEST_VLAN_TAG = IPMI_LANPARM_DEST_VLAN_TAG;
10053 
10054     /*
10055      * Fetch an individual parm from the MC.  The parameter (parm1) ,
10056      * and set (parm2) and block (parm3) are specified, along with a
10057      * handler (parm4).  The lanparm_got_parm_cb method on the handler
10058      * will be called when the the operation completes with the
10059      * following parms: <self> <lanparm> <err> <parm_rev> <data1> [<data2> ...]
10060      */
get_parm(int parm,int set,int block,swig_cb * handler)10061     int get_parm(int parm, int set, int block, swig_cb *handler)
10062     {
10063 	int         rv;
10064 	swig_cb_val *handler_val;
10065 
10066 	IPMI_SWIG_C_CB_ENTRY
10067 	if (!valid_swig_cb(handler, lanparm_got_parm_cb))
10068 	    rv = EINVAL;
10069 	else {
10070 	    handler_val = ref_swig_cb(handler, lanparm_got_parm_cb);
10071 	    ipmi_lanparm_ref(self);
10072 	    rv = ipmi_lanparm_get_parm(self, parm, set, block,
10073 				       lanparm_get_parm, handler_val);
10074 	    if (rv) {
10075 		ipmi_lanparm_deref(self);
10076 		deref_swig_cb_val(handler_val);
10077 	    }
10078 	}
10079 	IPMI_SWIG_C_CB_EXIT
10080 	return rv;
10081     }
10082 
10083     /*
10084      * Set an individual parm on the MC.  The parameter (parm1),
10085      * and string value (parm2) is specified, along with an optional
10086      * handler (parm3).  The lanparm_set_parm_cb method on the handler
10087      * will be called when the the operation completes with the
10088      * following parms: <self> <lanparm> <err>.
10089      *
10090      * The string value is in the form "0xNN 0xNN ...", basically
10091      * a string of integer values.
10092      */
10093     int set_parm(int parm, char *value, swig_cb *handler = NULL)
10094     {
10095 	int                  rv;
10096 	swig_cb_val          *handler_val = NULL;
10097 	unsigned char        *data;
10098 	unsigned int         length;
10099 
10100 	IPMI_SWIG_C_CB_ENTRY
10101 	data = parse_raw_str_data(value, &length);
10102 	if (!data) {
10103 	    rv = ENOMEM;
10104 	    goto out_err;
10105 	}
10106 
10107 	if (!nil_swig_cb(handler)) {
10108 	    if (! valid_swig_cb(handler, lanparm_set_parm_cb)) {
10109 		free(data);
10110 		rv = EINVAL;
10111 		goto out_err;
10112 	    }
10113 	    handler_val = ref_swig_cb(handler, lanparm_set_parm_cb);
10114 	}
10115 
10116 	if (handler_val)
10117 	    ipmi_lanparm_ref(self);
10118 	rv = ipmi_lanparm_set_parm(self, parm, data, length,
10119 				   lanparm_set_parm, handler_val);
10120 	free(data);
10121 	if (rv && handler_val) {
10122 	    ipmi_lanparm_deref(self);
10123 	    deref_swig_cb_val(handler_val);
10124 	}
10125     out_err:
10126 	IPMI_SWIG_C_CB_EXIT
10127 	return rv;
10128     }
10129 
10130     /*
10131      * Set an individual parm on the MC.  The parameter (parm1), and
10132      * an array of integers (parm2) is specified, along with an
10133      * optional handler (parm3).  The lanparm_set_parm_cb method on
10134      * the handler will be called when the the operation completes
10135      * with the following parms: <self> <lanparm> <err>.
10136      *
10137      * The string value is in the form "0xNN 0xNN ...", basically
10138      * a string of integer values.
10139      */
10140     int set_parm_array(int parm, intarray value, swig_cb *handler = NULL)
10141     {
10142 	int                  rv;
10143 	swig_cb_val          *handler_val = NULL;
10144 	unsigned char        *data;
10145 	unsigned int         length = value.len;
10146 
10147 	IPMI_SWIG_C_CB_ENTRY
10148 	if (length == 0)
10149 	    data = malloc(1);
10150 	else
10151 	    data = malloc(length);
10152 	if (!data) {
10153 	    rv = ENOMEM;
10154 	    goto out_err;
10155 	}
10156 	parse_ipmi_data(value, data, length, &length);
10157 
10158 	if (!nil_swig_cb(handler)) {
10159 	    if (! valid_swig_cb(handler, lanparm_set_parm_cb)) {
10160 		free(data);
10161 		rv = EINVAL;
10162 		goto out_err;
10163 	    }
10164 	    handler_val = ref_swig_cb(handler, lanparm_set_parm_cb);
10165 	}
10166 
10167 	if (handler_val)
10168 	    ipmi_lanparm_ref(self);
10169 	rv = ipmi_lanparm_set_parm(self, parm, data, length,
10170 				   lanparm_set_parm, handler_val);
10171 	free(data);
10172 	if (rv && handler_val) {
10173 	    ipmi_lanparm_deref(self);
10174 	    deref_swig_cb_val(handler_val);
10175 	}
10176     out_err:
10177 	IPMI_SWIG_C_CB_EXIT
10178 	return rv;
10179     }
10180 
10181     /*
10182      * Get the full standard configuration for the lanparms.  When
10183      * done, the lanparm_got_config_cb method will be called on the
10184      * handler (first parm) with the following parms: <self> <lanparm>
10185      * <err> <lanconfig>.  The lanconfig will be an object of type
10186      * ipmi_lan_config_t.
10187      */
get_config(swig_cb * handler)10188     int get_config(swig_cb *handler)
10189     {
10190 	int                  rv;
10191 	swig_cb_val          *handler_val = NULL;
10192 
10193 	IPMI_SWIG_C_CB_ENTRY
10194 	if (!valid_swig_cb(handler, lanparm_got_config_cb))
10195 	    rv = EINVAL;
10196 	else {
10197 	    handler_val = ref_swig_cb(handler, lanparm_got_config_cb);
10198 
10199 	    ipmi_lanparm_ref(self);
10200 	    rv = ipmi_lan_get_config(self, lanparm_get_config, handler_val);
10201 	    if (rv) {
10202 		ipmi_lanparm_deref(self);
10203 		deref_swig_cb_val(handler_val);
10204 	    }
10205 	}
10206 	IPMI_SWIG_C_CB_EXIT
10207 	return rv;
10208 
10209     }
10210 
10211     /*
10212      * Set the full standard configuration for the lanparms.  The
10213      * config to set is the first parm of type ipmi_lan_config_t.  When
10214      * done, the lanparm_set_config_cb method will be called on the
10215      * handler (second parm) with the following parms: <self>
10216      * <lanparm> <err>.
10217      */
10218     int set_config(ipmi_lan_config_t *config, swig_cb *handler = NULL)
10219     {
10220 	int                  rv;
10221 	swig_cb_val          *handler_val = NULL;
10222 
10223 	IPMI_SWIG_C_CB_ENTRY
10224 	if (!nil_swig_cb(handler)) {
10225 	    if (! valid_swig_cb(handler, lanparm_set_config_cb)) {
10226 		rv = EINVAL;
10227 		goto out_err;
10228 	    }
10229 	    handler_val = ref_swig_cb(handler, lanparm_set_config_cb);
10230 	}
10231 
10232 	if (handler_val)
10233 	    ipmi_lanparm_ref(self);
10234 	rv = ipmi_lan_set_config(self, config,
10235 				 lanparm_set_config, handler_val);
10236 	if (rv && handler_val) {
10237 	    ipmi_lanparm_deref(self);
10238 	    deref_swig_cb_val(handler_val);
10239 	}
10240     out_err:
10241 	IPMI_SWIG_C_CB_EXIT
10242 	return rv;
10243     }
10244 
10245     /*
10246      * Unlock the lock for the lanparm.  The config to set is the
10247      * first parm of type ipmi_lan_config_t and may be undefined
10248      * (meaning that the MC of the lanparm will be unlocked).  If the
10249      * config is supplied, it will be marked as unlocked.  When done,
10250      * the lanparm_clear_lock_cb method will be called on the handler
10251      * (second parm) with the following parms: <self> <lanparm> <err>.
10252      */
10253     int clear_lock(ipmi_lan_config_t *config = NULL, swig_cb *handler = NULL)
10254     {
10255 	int                  rv;
10256 	swig_cb_val          *handler_val = NULL;
10257 
10258 	IPMI_SWIG_C_CB_ENTRY
10259 	if (!nil_swig_cb(handler)) {
10260 	    if (! valid_swig_cb(handler, lanparm_clear_lock_cb)) {
10261 		rv = EINVAL;
10262 		goto out_err;
10263 	    }
10264 	    handler_val = ref_swig_cb(handler, lanparm_clear_lock_cb);
10265 	}
10266 
10267 	if (handler_val)
10268 	    ipmi_lanparm_ref(self);
10269 	rv = ipmi_lan_clear_lock(self, config,
10270 				 lanparm_clear_lock, handler_val);
10271 	if (rv && handler_val) {
10272 	    ipmi_lanparm_deref(self);
10273 	    deref_swig_cb_val(handler_val);
10274 	}
10275     out_err:
10276 	IPMI_SWIG_C_CB_EXIT
10277 	return rv;
10278     }
10279 }
10280 
10281 %extend ipmi_lan_config_t {
~ipmi_lan_config_t()10282     ~ipmi_lan_config_t()
10283     {
10284 	ipmi_lan_free_config(self);
10285     }
10286 
10287     /*
10288      * Get a value from the lanconfig.  The first parameter is the
10289      * parm number, the second is the parm index (which is a pointer
10290      * to an integer).  The returned value will be undefined if
10291      * an error occurred, it will be of the format:
10292      *   "<name> <type> <data>"
10293      * The type and data will not be present if the data value is not
10294      * supported or the index is out of range, but the name will still
10295      * be present.
10296      *
10297      * The supports types are: integer, bool, data, ip, and mac.  The
10298      * data for an integer is a number.  The data for a bool is true
10299      * or false.  The data for ip is an IP address in the form
10300      * "n.n.n.n".  Data for mac is a mac address in the form
10301      * "nn:nn:nn:nn:nn:nn"
10302      *
10303      * The second parameter (the index) is zero based and should be
10304      * set to zero when fetching an index for the first time.  It will
10305      * be unchanged if the data item does not support multiple items.
10306      * If it does support multiple items, then the number will be
10307      * changed to the next supported value, or to -1 if this is the
10308      * last item.
10309      *
10310      * Be careful with the index, it must be a number, not something
10311      * that can be interpreted to a number.  If necessary, in perl,
10312      * you must do $idx = int($idx) in some cases.
10313      */
10314     %newobject get_val;
get_val(int parm,int * index)10315     char *get_val(int parm, int *index)
10316     {
10317 	enum ipmi_lanconf_val_type_e valtype;
10318 	unsigned int      ival = 0;
10319 	unsigned char     *dval = NULL;
10320 	unsigned int      dval_len = 0;
10321 	const char        *name;
10322 	char              dummy[1];
10323 	char              *str = NULL, *s;
10324 	int               rv;
10325 	int               i;
10326 	unsigned int      len;
10327 
10328 	rv = ipmi_lanconfig_get_val(self, parm, &name, index, &valtype,
10329 				    &ival, &dval, &dval_len);
10330 	if ((rv == ENOSYS) || (rv == E2BIG))
10331 	    return strdup(name);
10332 	else if (rv)
10333 	    return NULL;
10334 
10335 	switch (valtype) {
10336 	case IPMI_LANCONFIG_INT:
10337 	    len = snprintf(dummy, 1, "%s integer %d", name, ival);
10338 	    str = malloc(len + 1);
10339 	    sprintf(str, "%s integer %d", name, ival);
10340 	    break;
10341 
10342 	case IPMI_LANCONFIG_BOOL:
10343 	    len = snprintf(dummy, 1, "%s bool %s", name,
10344 			   ival ? "true" : "false");
10345 	    str = malloc(len + 1);
10346 	    sprintf(str, "%s bool %s", name,
10347 		    ival ? "true" : "false");
10348 	    break;
10349 
10350 	case IPMI_LANCONFIG_DATA:
10351 	    len = snprintf(dummy, 1, "%s data", name);
10352 	    len += dval_len * 5;
10353 	    str = malloc(len + 1);
10354 	    s = str;
10355 	    s += sprintf(s, "%s data", name);
10356 	    for (i=0; i<dval_len; i++)
10357 		s += sprintf(s, " 0x%2.2x", dval[i]);
10358 	    break;
10359 
10360 	case IPMI_LANCONFIG_IP:
10361 	    len = snprintf(dummy, 1, "%s ip", name);
10362 	    len += 4 * 4; /* worst case */
10363 	    str = malloc(len + 1);
10364 	    sprintf(str, "%s ip %d.%d.%d.%d", name,
10365 		    dval[0], dval[1], dval[2], dval[3]);
10366 	    break;
10367 
10368 	case IPMI_LANCONFIG_MAC:
10369 	    len = snprintf(dummy, 1, "%s mac", name);
10370 	    len += 6 * 3;
10371 	    str = malloc(len + 1);
10372 	    s = str;
10373 	    s += sprintf(s, "%s mac ", name);
10374 	    for (i=0; i<5; i++)
10375 		s += sprintf(s, "%2.2x:", dval[i]);
10376 	    sprintf(s, "%2.2x", dval[i]);
10377 	    break;
10378 	}
10379 
10380 	if (dval)
10381 	    ipmi_lanconfig_data_free(dval);
10382 
10383 	return str;
10384     }
10385 
10386     /*
10387      * Set a value in the lanconfig.  The first parameter is the parm
10388      * number, the second is the parm index.  The type is a string
10389      * in the third parm.  The data is the fourth parm.
10390      *
10391      * The supports types are: integer, bool, data, ip, and mac.  The
10392      * data for an integer is a number.  The data for a bool is true
10393      * or false.  The data for ip is an IP address in the form
10394      * "n.n.n.n".  Data for mac is a mac address in the form
10395      * "nn.nn.nn.nn.nn.nn"
10396      *
10397      * The index is ignored for types that do not use it.
10398      */
set_val(int parm,int idx,char * type,char * value)10399     int set_val(int parm, int idx, char *type, char *value) {
10400 	enum ipmi_lanconf_val_type_e valtype;
10401 	int               rv;
10402 	unsigned int      ival = 0;
10403 	unsigned char     *dval = NULL;
10404 	unsigned int      dval_len = 0;
10405 
10406 	rv = ipmi_lanconfig_parm_to_type(parm, &valtype);
10407 	if (rv)
10408 	    return rv;
10409 
10410 	switch (valtype) {
10411 	case IPMI_LANCONFIG_INT:
10412 	{
10413 	    char *endstr;
10414 	    if (strcmp(type, "integer") != 0)
10415 		return EINVAL;
10416 	    if (!value)
10417 		return EINVAL;
10418 	    if (*value == '\0')
10419 		return EINVAL;
10420 	    ival = strtol(value, &endstr, 0);
10421 	    if (*endstr != '\0')
10422 		return EINVAL;
10423 	    break;
10424 	}
10425 
10426 	case IPMI_LANCONFIG_BOOL:
10427 	    if (strcmp(type, "bool") != 0)
10428 		return EINVAL;
10429 	    if (!value)
10430 		return EINVAL;
10431 	    if (strcasecmp(value, "true") == 0)
10432 		ival = 1;
10433 	    else if (strcasecmp(value, "false") == 0)
10434 		ival = 0;
10435 	    else if (strcasecmp(value, "on") == 0)
10436 		ival = 1;
10437 	    else if (strcasecmp(value, "off") == 0)
10438 		ival = 0;
10439 	    else
10440 		return EINVAL;
10441 	    break;
10442 
10443 	case IPMI_LANCONFIG_DATA:
10444 	    if (strcmp(type, "data") != 0)
10445 		return EINVAL;
10446 	    if (!value)
10447 		return EINVAL;
10448 	    dval = parse_raw_str_data(value, &dval_len);
10449 	    if (!dval)
10450 		return ENOMEM;
10451 	    break;
10452 
10453 	case IPMI_LANCONFIG_IP:
10454 	    {
10455 		struct in_addr addr;
10456 		if (strcmp(type, "ip") != 0)
10457 		    return EINVAL;
10458 		rv = parse_ip_addr(value, &addr);
10459 		if (rv)
10460 		    return rv;
10461 		dval = malloc(4);
10462 		memcpy(dval, &addr.s_addr, 4);
10463 		dval_len = 4;
10464 	    }
10465 	    break;
10466 
10467 	case IPMI_LANCONFIG_MAC:
10468 	    if (strcmp(type, "mac") != 0)
10469 		return EINVAL;
10470 	    dval = malloc(6);
10471 	    rv = parse_mac_addr(value, dval);
10472 	    if (rv) {
10473 		free(dval);
10474 		return rv;
10475 	    }
10476 	    dval_len = 6;
10477 	    break;
10478 	}
10479 
10480 	rv = ipmi_lanconfig_set_val(self, parm, idx, ival, dval, dval_len);
10481 	if (dval)
10482 	    free(dval);
10483 	return rv;
10484     }
10485 }
10486 
10487 %extend ipmi_pef_t {
~ipmi_pef_t()10488     ~ipmi_pef_t()
10489     {
10490 	ipmi_pef_deref(self);
10491     }
10492 
10493     %newobject get_mc_id;
get_mc_id()10494     ipmi_mcid_t *get_mc_id()
10495     {
10496 	ipmi_mcid_t *rv = malloc(sizeof(*rv));
10497 	if (rv)
10498 	    *rv = ipmi_pef_get_mc(self);
10499 	return rv;
10500     }
10501 
10502 %constant int PEFPARM_SET_IN_PROGRESS = IPMI_PEFPARM_SET_IN_PROGRESS;
10503 %constant int PEFPARM_CONTROL = IPMI_PEFPARM_CONTROL;
10504 %constant int PEFPARM_ACTION_GLOBAL_CONTROL = IPMI_PEFPARM_ACTION_GLOBAL_CONTROL;
10505 %constant int PEFPARM_STARTUP_DELAY = IPMI_PEFPARM_STARTUP_DELAY;
10506 %constant int PEFPARM_ALERT_STARTUP_DELAY = IPMI_PEFPARM_ALERT_STARTUP_DELAY;
10507 %constant int PEFPARM_NUM_EVENT_FILTERS = IPMI_PEFPARM_NUM_EVENT_FILTERS;
10508 %constant int PEFPARM_EVENT_FILTER_TABLE = IPMI_PEFPARM_EVENT_FILTER_TABLE;
10509 %constant int PEFPARM_EVENT_FILTER_TABLE_DATA1 = IPMI_PEFPARM_EVENT_FILTER_TABLE_DATA1;
10510 %constant int PEFPARM_NUM_ALERT_POLICIES = IPMI_PEFPARM_NUM_ALERT_POLICIES;
10511 %constant int PEFPARM_ALERT_POLICY_TABLE = IPMI_PEFPARM_ALERT_POLICY_TABLE;
10512 %constant int PEFPARM_SYSTEM_GUID = IPMI_PEFPARM_SYSTEM_GUID;
10513 %constant int PEFPARM_NUM_ALERT_STRINGS = IPMI_PEFPARM_NUM_ALERT_STRINGS;
10514 %constant int PEFPARM_ALERT_STRING_KEY = IPMI_PEFPARM_ALERT_STRING_KEY;
10515 %constant int PEFPARM_ALERT_STRING = IPMI_PEFPARM_ALERT_STRING;
10516 
10517     /*
10518      * Fetch an individual parm from the MC.  The parameter (parm1) ,
10519      * and set (parm2) and block (parm3) are specified, along with a
10520      * handler (parm4).  The pef_got_parm_cb method on the handler
10521      * will be called when the the operation completes with the
10522      * following parms: <self> <pef> <err> <parm_rev> <data1> [<data2> ...]
10523      */
get_parm(int parm,int set,int block,swig_cb * handler)10524     int get_parm(int parm, int set, int block, swig_cb *handler)
10525     {
10526 	int         rv;
10527 	swig_cb_val *handler_val;
10528 
10529 	IPMI_SWIG_C_CB_ENTRY
10530 	if (!valid_swig_cb(handler, pef_got_parm_cb))
10531 	    rv = EINVAL;
10532 	else {
10533 	    handler_val = ref_swig_cb(handler, pef_got_parm_cb);
10534 	    ipmi_pef_ref(self);
10535 	    rv = ipmi_pef_get_parm(self, parm, set, block, pef_get_parm,
10536 				   handler_val);
10537 	    if (rv) {
10538 		ipmi_pef_deref(self);
10539 		deref_swig_cb_val(handler_val);
10540 	    }
10541 	}
10542 	IPMI_SWIG_C_CB_EXIT
10543 	return rv;
10544     }
10545 
10546     /*
10547      * Set an individual parm on the MC.  The parameter (parm1),
10548      * and string value (parm2) is specified, along with an optional
10549      * handler (parm3).  The pef_set_parm_cb method on the handler
10550      * will be called when the the operation completes with the
10551      * following parms: <self> <pef> <err>.
10552      *
10553      * The string value is in the form "0xNN 0xNN ...", basically
10554      * a string of integer values.
10555      */
10556     int set_parm(int parm, char *value, swig_cb *handler = NULL)
10557     {
10558 	int                  rv;
10559 	swig_cb_val          *handler_val = NULL;
10560 	unsigned char        *data;
10561 	unsigned int         length;
10562 
10563 	IPMI_SWIG_C_CB_ENTRY
10564 	data = parse_raw_str_data(value, &length);
10565 	if (!data) {
10566 	    rv = ENOMEM;
10567 	    goto out_err;
10568 	}
10569 
10570 	if (!nil_swig_cb(handler)) {
10571 	    if (! valid_swig_cb(handler, pef_set_parm_cb)) {
10572 		free(data);
10573 		rv = EINVAL;
10574 		goto out_err;
10575 	    }
10576 	    handler_val = ref_swig_cb(handler, pef_set_parm_cb);
10577 	}
10578 
10579 	if (handler_val)
10580 	    ipmi_pef_ref(self);
10581 	rv = ipmi_pef_set_parm(self, parm, data, length,
10582 			       pef_set_parm, handler_val);
10583 	free(data);
10584 	if (rv && handler_val) {
10585 	    ipmi_pef_deref(self);
10586 	    deref_swig_cb_val(handler_val);
10587 	}
10588     out_err:
10589 	IPMI_SWIG_C_CB_EXIT
10590 	return rv;
10591     }
10592 
10593     /*
10594      * Set an individual parm on the MC.  The parameter (parm1), and
10595      * an array of integers (parm2) is specified, along with an
10596      * optional handler (parm3).  The pef_set_parm_cb method on
10597      * the handler will be called when the the operation completes
10598      * with the following parms: <self> <pef> <err>.
10599      *
10600      * The string value is in the form "0xNN 0xNN ...", basically
10601      * a string of integer values.
10602      */
10603     int set_parm_array(int parm, intarray value, swig_cb *handler = NULL)
10604     {
10605 	int                  rv;
10606 	swig_cb_val          *handler_val = NULL;
10607 	unsigned char        *data;
10608 	unsigned int         length = value.len;
10609 
10610 	IPMI_SWIG_C_CB_ENTRY
10611 	if (length == 0)
10612 	    data = malloc(1);
10613 	else
10614 	    data = malloc(length);
10615 	if (!data) {
10616 	    rv = ENOMEM;
10617 	    goto out_err;
10618 	}
10619 	parse_ipmi_data(value, data, length, &length);
10620 
10621 	if (!nil_swig_cb(handler)) {
10622 	    if (! valid_swig_cb(handler, pef_set_parm_cb)) {
10623 		free(data);
10624 		rv = EINVAL;
10625 		goto out_err;
10626 	    }
10627 	    handler_val = ref_swig_cb(handler, pef_set_parm_cb);
10628 	}
10629 
10630 	if (handler_val)
10631 	    ipmi_pef_ref(self);
10632 	rv = ipmi_pef_set_parm(self, parm, data, length,
10633 			       pef_set_parm, handler_val);
10634 	free(data);
10635 	if (rv && handler_val) {
10636 	    ipmi_pef_deref(self);
10637 	    deref_swig_cb_val(handler_val);
10638 	}
10639     out_err:
10640 	IPMI_SWIG_C_CB_EXIT
10641 	return rv;
10642     }
10643 
10644     /*
10645      * Get the full standard configuration for the pefs.  When
10646      * done, the pef_got_config_cb method will be called on the
10647      * handler (first parm) with the following parms: <self> <pef>
10648      * <err> <pefconfig>.  The pefconfig will be an object of type
10649      * ipmi_pef_config_t.
10650      */
get_config(swig_cb * handler)10651     int get_config(swig_cb *handler)
10652     {
10653 	int                  rv;
10654 	swig_cb_val          *handler_val = NULL;
10655 
10656 	IPMI_SWIG_C_CB_ENTRY
10657 	if (!valid_swig_cb(handler, pef_got_config_cb))
10658 	    rv = EINVAL;
10659 	else {
10660 	    handler_val = ref_swig_cb(handler, pef_got_config_cb);
10661 
10662 	    ipmi_pef_ref(self);
10663 	    rv = ipmi_pef_get_config(self, pef_get_config, handler_val);
10664 	    if (rv) {
10665 		ipmi_pef_deref(self);
10666 		deref_swig_cb_val(handler_val);
10667 	    }
10668 	}
10669 	IPMI_SWIG_C_CB_EXIT
10670 	return rv;
10671 
10672     }
10673 
10674     /*
10675      * Set the full standard configuration for the pefs.  The
10676      * config to set is the first parm of type ipmi_pef_config_t.  When
10677      * done, the pef_set_config_cb method will be called on the
10678      * handler (second parm) with the following parms: <self>
10679      * <pef> <err>.
10680      */
10681     int set_config(ipmi_pef_config_t *config, swig_cb *handler = NULL)
10682     {
10683 	int                  rv;
10684 	swig_cb_val          *handler_val = NULL;
10685 	ipmi_pef_done_cb done = NULL;
10686 
10687 	IPMI_SWIG_C_CB_ENTRY
10688 	if (!nil_swig_cb(handler)) {
10689 	    if (! valid_swig_cb(handler, pef_set_config_cb)) {
10690 		rv = EINVAL;
10691 		goto out_err;
10692 	    }
10693 	    done = pef_set_config;
10694 	    handler_val = ref_swig_cb(handler, pef_set_config_cb);
10695 	}
10696 
10697 	if (handler_val)
10698 	    ipmi_pef_ref(self);
10699 	rv = ipmi_pef_set_config(self, config, done, handler_val);
10700 	if (rv && handler_val) {
10701 	    ipmi_pef_deref(self);
10702 	    deref_swig_cb_val(handler_val);
10703 	}
10704     out_err:
10705 	IPMI_SWIG_C_CB_EXIT
10706 	return rv;
10707     }
10708 
10709     /*
10710      * Unlock the lock for the pef.  The config to set is the
10711      * first parm of type ipmi_pef_config_t and may be undefined
10712      * (meaning that the MC of the pef will be unlocked).  If the
10713      * config is supplied, it will be marked as unlocked.  When done,
10714      * the pef_clear_lock_cb method will be called on the handler
10715      * (second parm) with the following parms: <self> <pef> <err>.
10716      */
10717     int clear_lock(ipmi_pef_config_t *config = NULL, swig_cb *handler = NULL)
10718     {
10719 	int         rv;
10720 	swig_cb_val *handler_val = NULL;
10721 
10722 	IPMI_SWIG_C_CB_ENTRY
10723 	if (!nil_swig_cb(handler)) {
10724 	    if (! valid_swig_cb(handler, pef_clear_lock_cb)) {
10725 		rv = EINVAL;
10726 		goto out_err;
10727 	    }
10728 	    handler_val = ref_swig_cb(handler, pef_clear_lock_cb);
10729 	}
10730 
10731 	if (handler_val)
10732 	    ipmi_pef_ref(self);
10733 	rv = ipmi_pef_clear_lock(self, config, pef_clear_lock, handler_val);
10734 	if (rv && handler_val) {
10735 	    ipmi_pef_deref(self);
10736 	    deref_swig_cb_val(handler_val);
10737 	}
10738     out_err:
10739 	IPMI_SWIG_C_CB_EXIT
10740 	return rv;
10741     }
10742 }
10743 
10744 %extend ipmi_pef_config_t {
~ipmi_pef_config_t()10745     ~ipmi_pef_config_t()
10746     {
10747 	ipmi_pef_free_config(self);
10748     }
10749 
10750     /*
10751      * Get a value from the pefconfig.  The first parameter is the
10752      * parm number, the second is the parm index (which is a pointer
10753      * to an integer).  The returned value will be undefined if
10754      * an error occurred, it will be of the format:
10755      *   "<name> <type> <data>"
10756      * The type and data will not be present if the data value is not
10757      * supported or the index is out of range, but the name will still
10758      * be present.
10759      *
10760      * The supports types are: integer, bool, data, and string.  The
10761      * data for an integer is a number.  The data for a bool is true
10762      * or false.  The data for string is a string, starting one space
10763      * after the string and going to the end of the returned valid
10764      *
10765      * The second parameter (the index) is zero based and should be
10766      * set to zero when fetching an index for the first time.  It will
10767      * be unchanged if the data item does not support multiple items.
10768      * If it does support multiple items, then the number will be
10769      * changed to the next supported value, or to -1 if this is the
10770      * last item.
10771      *
10772      * Be careful with the index, it must be a number, not something
10773      * that can be interpreted to a number.  If necessary, in perl,
10774      * you must do $idx = int($idx) in some cases.
10775      */
10776     %newobject get_val;
get_val(int parm,int * index)10777     char *get_val(int parm, int *index)
10778     {
10779 	enum ipmi_pefconf_val_type_e valtype;
10780 	unsigned int      ival = 0;
10781 	unsigned char     *dval = NULL;
10782 	unsigned int      dval_len = 0;
10783 	const char        *name;
10784 	char              dummy[1];
10785 	char              *str = NULL, *s;
10786 	int               rv;
10787 	int               i;
10788 	unsigned int      len;
10789 
10790 	rv = ipmi_pefconfig_get_val(self, parm, &name, index, &valtype,
10791 				    &ival, &dval, &dval_len);
10792 	if ((rv == ENOSYS) || (rv == E2BIG))
10793 	    return strdup(name);
10794 	else if (rv)
10795 	    return NULL;
10796 
10797 	switch (valtype) {
10798 	case IPMI_PEFCONFIG_INT:
10799 	    len = snprintf(dummy, 1, "%s integer %d", name, ival);
10800 	    str = malloc(len + 1);
10801 	    sprintf(str, "%s integer %d", name, ival);
10802 	    break;
10803 
10804 	case IPMI_PEFCONFIG_BOOL:
10805 	    len = snprintf(dummy, 1, "%s bool %s", name,
10806 			   ival ? "true" : "false");
10807 	    str = malloc(len + 1);
10808 	    sprintf(str, "%s bool %s", name,
10809 		    ival ? "true" : "false");
10810 	    break;
10811 
10812 	case IPMI_PEFCONFIG_DATA:
10813 	    len = snprintf(dummy, 1, "%s data", name);
10814 	    len += dval_len * 5;
10815 	    str = malloc(len + 1);
10816 	    s = str;
10817 	    s += sprintf(s, "%s data", name);
10818 	    for (i=0; i<dval_len; i++)
10819 		s += sprintf(s, " 0x%2.2x", dval[i]);
10820 	    break;
10821 
10822 	case IPMI_PEFCONFIG_STR:
10823 	    len = snprintf(dummy, 1, "%s string %s", name, (char *) dval);
10824 	    str = malloc(len + 1);
10825 	    sprintf(str, "%s string %s", name, (char *) dval);
10826 	    break;
10827 	}
10828 
10829 	if (dval)
10830 	    ipmi_pefconfig_data_free(dval);
10831 
10832 	return str;
10833     }
10834 
10835     /*
10836      * Set a value in the pefconfig.  The first parameter is the parm
10837      * number, the second is the parm index.  The type is a string
10838      * in the third parm.  The data is the fourth parm.
10839      *
10840      * The supports types are: integer, bool, data, and string.  The
10841      * data for an integer is a number.  The data for a bool is true
10842      * or false.  The data for string is just a string.
10843      *
10844      * The index is ignored for types that do not use it.
10845      */
set_val(int parm,int idx,char * type,char * value)10846     int set_val(int parm, int idx, char *type, char *value) {
10847 	enum ipmi_pefconf_val_type_e valtype;
10848 	int               rv;
10849 	unsigned int      ival = 0;
10850 	unsigned char     *dval = NULL;
10851 	unsigned int      dval_len = 0;
10852 
10853 	rv = ipmi_pefconfig_parm_to_type(parm, &valtype);
10854 	if (rv)
10855 	    return rv;
10856 
10857 	switch (valtype) {
10858 	case IPMI_PEFCONFIG_INT:
10859 	{
10860 	    char *endstr;
10861 	    if (strcmp(type, "integer") != 0)
10862 		return EINVAL;
10863 	    if (!value)
10864 		return EINVAL;
10865 	    if (*value == '\0')
10866 		return EINVAL;
10867 	    ival = strtol(value, &endstr, 0);
10868 	    if (*endstr != '\0')
10869 		return EINVAL;
10870 	    break;
10871 	}
10872 
10873 	case IPMI_PEFCONFIG_BOOL:
10874 	    if (strcmp(type, "bool") != 0)
10875 		return EINVAL;
10876 	    if (!value)
10877 		return EINVAL;
10878 	    if (strcasecmp(value, "true") == 0)
10879 		ival = 1;
10880 	    else if (strcasecmp(value, "false") == 0)
10881 		ival = 0;
10882 	    else if (strcasecmp(value, "on") == 0)
10883 		ival = 1;
10884 	    else if (strcasecmp(value, "off") == 0)
10885 		ival = 0;
10886 	    else
10887 		return EINVAL;
10888 	    break;
10889 
10890 	case IPMI_PEFCONFIG_DATA:
10891 	    if (strcmp(type, "data") != 0)
10892 		return EINVAL;
10893 	    if (!value)
10894 		return EINVAL;
10895 	    dval = parse_raw_str_data(value, &dval_len);
10896 	    if (!dval)
10897 		return ENOMEM;
10898 	    break;
10899 
10900 	case IPMI_PEFCONFIG_STR:
10901 	    if (strcmp(type, "string") != 0)
10902 		return EINVAL;
10903 	    if (!value)
10904 		return EINVAL;
10905 	    dval = (unsigned char *) strdup((char *) value);
10906 	    if (!dval)
10907 		return ENOMEM;
10908 	    break;
10909 	}
10910 
10911 	rv = ipmi_pefconfig_set_val(self, parm, idx, ival, dval, dval_len);
10912 	if (dval)
10913 	    free(dval);
10914 	return rv;
10915     }
10916 }
10917 
10918 %extend ipmi_pet_t {
~ipmi_pet_t()10919     ~ipmi_pet_t()
10920     {
10921 	ipmi_pet_deref(self);
10922     }
10923 
10924     %newobject get_mc_id;
get_mc_id()10925     ipmi_mcid_t *get_mc_id()
10926     {
10927 	ipmi_mcid_t *rv = malloc(sizeof(*rv));
10928 	if (rv)
10929 	    *rv = ipmi_pet_get_mc_id(self);
10930 	return rv;
10931     }
10932 
get_channel()10933     int get_channel()
10934     {
10935 	return ipmi_pet_get_channel(self);
10936     }
10937 
10938     %newobject get_ip_addr;
get_ip_addr()10939     char *get_ip_addr()
10940     {
10941 	struct in_addr ip;
10942 	char           *dval = malloc(16);
10943 	unsigned char  d[4];
10944 
10945 	if (!dval)
10946 	    return NULL;
10947 	ipmi_pet_get_ip_addr(self, &ip);
10948 	d[0] = (ip.s_addr >> 24) & 0xff;
10949 	d[1] = (ip.s_addr >> 16) & 0xff;
10950 	d[2] = (ip.s_addr >> 8) & 0xff;
10951 	d[3] = (ip.s_addr >> 0) & 0xff;
10952 	sprintf(dval, "%d.%d.%d.%d", d[0], d[1], d[2], d[3]);
10953 	return dval;
10954     }
10955 
10956     %newobject get_mac_addr;
get_mac_addr()10957     char *get_mac_addr()
10958     {
10959 	char          *dval = malloc(18);
10960 	unsigned char d[6];
10961 
10962 	if (!dval)
10963 	    return NULL;
10964 	ipmi_pet_get_mac_addr(self, d);
10965 	sprintf(dval, "%d:%d:%d:%d:%d:%d", d[0], d[1], d[2], d[3], d[4], d[5]);
10966 	return dval;
10967     }
10968 
get_eft_sel()10969     int get_eft_sel()
10970     {
10971 	return ipmi_pet_get_eft_sel(self);
10972     }
10973 
get_policy_num()10974     int get_policy_num()
10975     {
10976 	return ipmi_pet_get_policy_num(self);
10977     }
10978 
get_apt_sel()10979     int get_apt_sel()
10980     {
10981 	return ipmi_pet_get_apt_sel(self);
10982     }
10983 
get_lan_dest_sel()10984     int get_lan_dest_sel()
10985     {
10986 	return ipmi_pet_get_lan_dest_sel(self);
10987     }
10988 }
10989 
10990 %newobject alloc_cmdlang;
10991 /*
10992  * Allocate a command language handler for use by the interpreted
10993  * language.  This allows commands to be entered and the responses
10994  * received by the handler object passed in.  The handler object must
10995  * implement a large number of methods:
10996  *
10997  * cmdlang_out - Normal output of a name/value pair.  Has the following
10998  *  parameters: <self> <cmdlang> <name> <value>
10999  *
11000  * cmdlang_out_binary - Output binary information.  Has the following
11001  *  parameters: <self> <cmdlang> <name> <val1> [<val2> ...] where the
11002  *  values are either a list of parameters or an array of integer
11003  *  values (depending on the language).
11004  *
11005  * cmdlang_out_unicode - Output a unicode string.  Has the following
11006  *  parameters: <self> <cmdlang> <name> <val1> [<val2> ...] where the
11007  *  values are either a list of parameters or an array of integer
11008  *  values (depending on the language).
11009  *
11010  * cmdlang_down - increase the nesting level of the output.  Takes
11011  *  the following parameters: <self> <cmdlang>.
11012 
11013  * cmdlang_up - decrease the nesting level of the output.  Takes
11014  *  the following parameters: <self> <cmdlang>.
11015  *
11016  * cmdlang_done - Execution of a command is complete.  This will be
11017  * called after every handled command so the upper layer will know
11018  * when a new command can be entered..  Takes the following
11019  * parameters: <self> <cmdlang>.
11020  */
11021 ipmi_cmdlang_t *alloc_cmdlang(swig_cb *handler);
11022 
11023 /*
11024  * Enable or disable full information for events registers with
11025  * set_cmdlang_event_handler.  Normally (with this set to false) only
11026  * minimal event information is printed.  With this set to true, all
11027  * information about the object the event occurs for is printed.
11028  */
11029 void cmdlang_set_evinfo(int evinfo);
11030 
11031 /*
11032  * Get the event info flag value.
11033  */
11034 int cmdlang_get_evinfo(void);
11035 
11036 /*
11037  * Set an error handler for handling "global" errors from the OpenIPMI
11038  * command language.  Basically, these are errors that are note
11039  * related to any specific command handler.  The handler has the
11040  * global_cmdlang_err method called on it with the following parms:
11041  * <self>
11042  * <objstr> - The name of the object associated with the error.  May
11043  * be empty.
11044  * <location> - The location (in the source code) where the error was
11045  * generated.  May be empty.
11046  * <errstr> - The error string generated.
11047  * <errval> - an integer value for the error.
11048  */
11049 void set_cmdlang_global_err_handler(swig_cb *handler);
11050 
11051 /*
11052  * Handle event from the cmdlang interface.  These are basically
11053  * events that occur asyncronously and are thus not associated with
11054  * any specific cmdlang handler.  The handler's cmdlang_event method
11055  * will be called with the following parameters: <self> <event>.  The
11056  * event is of the type ipmi_cmdlang_event_t.
11057  */
11058 void set_cmdlang_event_handler(swig_cb *handler);
11059 
11060 
11061 %{
cmdlang_set_evinfo(int evinfo)11062     static void cmdlang_set_evinfo(int evinfo)
11063     {
11064 	ipmi_cmdlang_set_evinfo(evinfo);
11065     }
11066 
cmdlang_get_evinfo(void)11067     static int cmdlang_get_evinfo(void)
11068     {
11069 	return ipmi_cmdlang_get_evinfo();
11070     }
11071 
cmdlang_down(ipmi_cmdlang_t * info)11072     static void cmdlang_down(ipmi_cmdlang_t *info)
11073     {
11074 	swig_cb_val *cb = info->user_data;
11075 	swig_ref    ref = swig_make_ref(info, ipmi_cmdlang_t);
11076 
11077 	swig_call_cb(cb, "cmdlang_down", "%p", &ref);
11078 	swig_free_ref(ref);
11079     }
11080 
cmdlang_up(ipmi_cmdlang_t * info)11081     static void cmdlang_up(ipmi_cmdlang_t *info)
11082     {
11083 	swig_cb_val *cb = info->user_data;
11084 	swig_ref    ref = swig_make_ref(info, ipmi_cmdlang_t);
11085 
11086 	swig_call_cb(cb, "cmdlang_up", "%p", &ref);
11087 	swig_free_ref(ref);
11088     }
11089 
cmdlang_done(ipmi_cmdlang_t * info)11090     static void cmdlang_done(ipmi_cmdlang_t *info)
11091     {
11092 	swig_cb_val *cb = info->user_data;
11093 	swig_ref    ref = swig_make_ref(info, ipmi_cmdlang_t);
11094 
11095 	swig_call_cb(cb, "cmdlang_done", "%p", &ref);
11096 	swig_free_ref(ref);
11097 
11098 	/* Clean up the cmdlang information */
11099 	if (info->errstr_dynalloc)
11100 	    ipmi_mem_free(info->errstr);
11101 	info->errstr_dynalloc = 0;
11102 	info->errstr = NULL;
11103 	info->objstr[0] = '\0';
11104 	info->err = 0;
11105     }
11106 
cmdlang_out(ipmi_cmdlang_t * info,const char * name,const char * value)11107     static void cmdlang_out(ipmi_cmdlang_t *info,
11108 			    const char     *name,
11109 			    const char     *value)
11110     {
11111 	swig_cb_val *cb = info->user_data;
11112 	swig_ref    ref = swig_make_ref(info, ipmi_cmdlang_t);
11113 
11114 	if (!value)
11115 	    value = "";
11116 	swig_call_cb(cb, "cmdlang_out", "%p%s%s", &ref, name, value);
11117 	swig_free_ref(ref);
11118     }
11119 
cmdlang_out_binary(ipmi_cmdlang_t * info,const char * name,const char * value,unsigned int len)11120     static void cmdlang_out_binary(ipmi_cmdlang_t *info,
11121 				   const char     *name,
11122 				   const char     *value,
11123 				   unsigned int   len)
11124     {
11125 	swig_cb_val *cb = info->user_data;
11126 	swig_ref    ref = swig_make_ref(info, ipmi_cmdlang_t);
11127 
11128 	swig_call_cb(cb, "cmdlang_out_binary", "%p%s%*s", &ref, name,
11129 		     len, value);
11130 	swig_free_ref(ref);
11131     }
11132 
cmdlang_out_unicode(ipmi_cmdlang_t * info,const char * name,const char * value,unsigned int len)11133     static void cmdlang_out_unicode(ipmi_cmdlang_t *info,
11134 				    const char     *name,
11135 				    const char     *value,
11136 				    unsigned int   len)
11137     {
11138 	swig_cb_val *cb = info->user_data;
11139 	swig_ref    ref = swig_make_ref(info, ipmi_cmdlang_t);
11140 
11141 	swig_call_cb(cb, "cmdlang_out_unicode", "%p%s%*s", &ref, name,
11142 		     len, value);
11143 	swig_free_ref(ref);
11144     }
11145 
11146     static ipmi_cmdlang_t *
alloc_cmdlang(swig_cb * handler)11147     alloc_cmdlang(swig_cb *handler)
11148     {
11149 	ipmi_cmdlang_t *cmdlang = NULL;
11150 
11151 	IPMI_SWIG_C_CB_ENTRY
11152 	if (nil_swig_cb(handler))
11153 	    goto out;
11154 
11155 	if (!valid_swig_cb(handler, cmdlang_out))
11156 	    goto out;
11157 	if (!valid_swig_cb(handler, cmdlang_out_binary))
11158 	    goto out;
11159 	if (!valid_swig_cb(handler, cmdlang_out_unicode))
11160 	    goto out;
11161 	if (!valid_swig_cb(handler, cmdlang_down))
11162 	    goto out;
11163 	if (!valid_swig_cb(handler, cmdlang_up))
11164 	    goto out;
11165 	if (!valid_swig_cb(handler, cmdlang_done))
11166 	    goto out;
11167 
11168 	cmdlang = malloc(sizeof(*cmdlang));
11169 	if (!cmdlang)
11170 	    goto out;
11171 	memset(cmdlang, 0, sizeof(*cmdlang));
11172 
11173 	cmdlang->out = cmdlang_out;
11174 	cmdlang->down = cmdlang_down;
11175 	cmdlang->up = cmdlang_up;
11176 	cmdlang->done = cmdlang_done;
11177 	cmdlang->out_binary = cmdlang_out_binary;
11178 	cmdlang->out_unicode = cmdlang_out_unicode;
11179 
11180 	cmdlang->os_hnd = swig_os_hnd;
11181 
11182 	cmdlang->objstr = malloc(IPMI_MAX_NAME_LEN);
11183 	if (!cmdlang->objstr) {
11184 	    free(cmdlang);
11185 	    cmdlang = NULL;
11186 	    goto out;
11187 	}
11188 	cmdlang->objstr[0] = '\0';
11189 	cmdlang->objstr_len = IPMI_MAX_NAME_LEN;
11190 
11191 	cmdlang->user_data = ref_swig_gencb(handler);
11192 
11193     out:
11194 	IPMI_SWIG_C_CB_EXIT
11195 	return cmdlang;
11196     }
11197 
11198     swig_cb_val *cmdlang_global_err_handler = NULL;
11199 
ipmi_cmdlang_global_err(char * objstr,char * location,char * errstr,int errval)11200     void ipmi_cmdlang_global_err(char *objstr,
11201 				 char *location,
11202 				 char *errstr,
11203 				 int  errval)
11204     {
11205 	swig_cb_val *handler = cmdlang_global_err_handler;
11206 
11207 	if (!objstr)
11208 	    objstr = "";
11209 	if (!location)
11210 	    location = "";
11211 	if (! handler) {
11212 	    fprintf(stderr, "Global IPMI cmdlang error: %s(%s): %s (%d)\n",
11213 		    objstr, location, errstr, errval);
11214 	} else {
11215 	    swig_call_cb(handler,
11216 			 "global_cmdlang_err",
11217 			 "%s%s%s%d", objstr, location, errstr, errval);
11218 	}
11219     }
11220 
11221     swig_cb_val *cmdlang_event_handler = NULL;
11222 
ipmi_cmdlang_report_event(ipmi_cmdlang_event_t * event)11223     void ipmi_cmdlang_report_event(ipmi_cmdlang_event_t *event)
11224     {
11225 	swig_ref event_ref;
11226 	swig_cb_val *handler = cmdlang_event_handler;
11227 
11228 	if (! handler)
11229 	    return;
11230 
11231 	event_ref = swig_make_ref(event, ipmi_cmdlang_event_t);
11232 	swig_call_cb(handler, "cmdlang_event", "%p", &event_ref);
11233 	/* User shouldn't keep these around. */
11234 	swig_free_ref_check(event_ref, ipmi_cmdlang_event_t);
11235     }
11236 
set_cmdlang_global_err_handler(swig_cb * handler)11237     void set_cmdlang_global_err_handler(swig_cb *handler)
11238     {
11239 	swig_cb_val *old_handler = cmdlang_global_err_handler;
11240 	IPMI_SWIG_C_CB_ENTRY
11241 	if (valid_swig_cb(handler, global_cmdlang_err))
11242 	    cmdlang_global_err_handler = ref_swig_cb(handler,
11243 						     global_cmdlang_err);
11244 	else
11245 	    cmdlang_global_err_handler = NULL;
11246 	if (old_handler)
11247 	    deref_swig_cb_val(old_handler);
11248 	IPMI_SWIG_C_CB_EXIT
11249     }
11250 
set_cmdlang_event_handler(swig_cb * handler)11251     void set_cmdlang_event_handler(swig_cb *handler)
11252     {
11253 	swig_cb_val *old_handler = cmdlang_event_handler;
11254 	IPMI_SWIG_C_CB_ENTRY
11255 	if (valid_swig_cb(handler, cmdlang_event))
11256 	    cmdlang_event_handler = ref_swig_cb(handler, cmdlang_event);
11257 	else
11258 	    cmdlang_event_handler = NULL;
11259 	if (old_handler)
11260 	    deref_swig_cb_val(old_handler);
11261 	IPMI_SWIG_C_CB_EXIT
11262     }
11263 %}
11264 
11265 
11266 %extend ipmi_cmdlang_t {
~ipmi_cmdlang_t()11267     ~ipmi_cmdlang_t()
11268     {
11269 	swig_cb_val *handler_val = self->user_data;
11270 
11271 	IPMI_SWIG_C_CB_ENTRY
11272 	if (handler_val)
11273 	    deref_swig_cb_val(handler_val);
11274 	if (self->objstr)
11275 	    free(self->objstr);
11276 	free(self);
11277 	IPMI_SWIG_C_CB_EXIT
11278     }
11279 
11280     /*
11281      * Process a command for the command language.
11282      */
handle(const char * icmd)11283     void handle(const char *icmd)
11284     {
11285 	char *cmd = strdup(icmd);
11286 
11287 	IPMI_SWIG_C_CB_ENTRY
11288 	ipmi_cmdlang_handle(self, cmd);
11289 	IPMI_SWIG_C_CB_EXIT
11290     }
11291 
11292     /*
11293      * When outputting, tells if this is help output.
11294      */
is_help()11295     int is_help()
11296     {
11297 	return self->help;
11298     }
11299 
11300     /*
11301      * When outputting, gets the error value, or 0 if there was no
11302      * error.
11303      */
get_err()11304     int get_err()
11305     {
11306 	return self->err;
11307     }
11308 
11309     %newobject get_errstr;
11310     /*
11311      * If there was an error, get the error string.
11312      */
get_errstr()11313     char *get_errstr()
11314     {
11315 	return strdup(self->errstr);
11316     }
11317 
11318     /*
11319      * If there was an error, get the object name associated with the error.
11320      */
11321     %newobject get_objstr;
get_objstr()11322     char *get_objstr()
11323     {
11324 	return strdup(self->objstr);
11325     }
11326 
11327     /*
11328      * If there was an error, get the location in the source code
11329      * where the error was generated.
11330      */
11331     %newobject get_location;
get_location()11332     char *get_location()
11333     {
11334 	return strdup(self->location);
11335     }
11336 }
11337 
11338 /*
11339  * A cmdlang event is a series of name/value fields that may be
11340  * fetched in sequence.
11341  */
11342 %extend ipmi_cmdlang_event_t {
~ipmi_cmdlang_event_t()11343     ~ipmi_cmdlang_event_t()
11344     {
11345 	/* Nothing to do. */
11346     }
11347 
11348     /*
11349      * Restart with the first field.
11350      */
restart()11351     void restart()
11352     {
11353 	ipmi_cmdlang_event_restart(self);
11354     }
11355 
11356     /*
11357      * Get the values of the next field.  The level is the nesting
11358      * level, the type is either "string", "binary", or "unicode", the
11359      * name is the name of the field, and value is its value.  binary
11360      * and unicode are returned as a string of hex values (0xnn 0xnn ...).
11361      */
next_field(unsigned int * level,const char ** type,char ** name,char ** value)11362     int next_field(unsigned int *level,
11363 		   const char   **type,
11364 		   char         **name,
11365 		   char         **value)
11366     {
11367 	int rv;
11368 	unsigned int len;
11369 	char         *n, *v;
11370 	char         *np, *vp;
11371 	enum ipmi_cmdlang_out_types t;
11372 	char         *tp;
11373 	int          i;
11374 	char         *s;
11375 
11376 	rv = ipmi_cmdlang_event_next_field(self, level, &t, &n, &len, &v);
11377 	if (!rv) {
11378 	    *type = "";
11379 	    *name = NULL;
11380 	    *value = NULL;
11381 	    return rv;
11382 	}
11383 
11384 	if (!v)
11385 	    v = "";
11386 
11387 	np = strdup(n);
11388 	if (!np)
11389 	    return ENOMEM;
11390 
11391 	switch (t) {
11392 	case IPMI_CMDLANG_STRING:
11393 	    tp = "string";
11394 	    vp = strdup(v);
11395 	    break;
11396 	case IPMI_CMDLANG_BINARY:
11397 	    tp = "binary";
11398 	    vp = malloc(len * 5);
11399 	    if (!vp)
11400 		break;
11401 	    s = vp;
11402 	    if (len > 0)
11403 		s += sprintf(s, "0x%2.2x", (unsigned char) v[0]);
11404 	    for (i=1; i<len; i++)
11405 		s += sprintf(s, " 0x%2.2x", (unsigned char) v[i]);
11406 	    break;
11407 	case IPMI_CMDLANG_UNICODE:
11408 	    tp = "unicode";
11409 	    vp = malloc(len * 5);
11410 	    if (!vp)
11411 		break;
11412 	    s = vp;
11413 	    if (len > 0)
11414 		s += sprintf(s, "0x%2.2x", (unsigned char) v[0]);
11415 	    for (i=1; i<len; i++)
11416 		s += sprintf(s, " 0x%2.2x", (unsigned char) v[i]);
11417 	    break;
11418 	default:
11419 	    free(np);
11420 	    return EINVAL;
11421 	}
11422 
11423 	if (!vp) {
11424 	    free(np);
11425 	    return ENOMEM;
11426 	}
11427 
11428 	*name = np;
11429 	*value = vp;
11430 	*type = tp;
11431 
11432 	return 1;
11433     }
11434 }
11435 
11436 %{
sol_state_string(int val)11437 static char *sol_state_string(int val)
11438 {
11439     switch (val) {
11440     case ipmi_sol_state_closed:
11441 	return "closed";
11442     case ipmi_sol_state_connecting:
11443 	return "connecting";
11444     case ipmi_sol_state_connected:
11445 	return "connected";
11446     case ipmi_sol_state_connected_ctu:
11447 	return "connected no char xfer";
11448     case ipmi_sol_state_closing:
11449 	return "closing";
11450     default:
11451 	return "unknown";
11452     }
11453 }
11454 %}
11455 char *sol_state_string(int val);
11456 
11457 %extend ipmi_sol_conn_t
11458 {
~ipmi_sol_conn_t()11459     ~ipmi_sol_conn_t()
11460     {
11461 	ipmi_sol_free(self);
11462     }
11463 
11464 %constant int sol_state_closed = ipmi_sol_state_closed;
11465 %constant int sol_state_connecting = ipmi_sol_state_connecting;
11466 %constant int sol_state_connected = ipmi_sol_state_connected;
11467 %constant int sol_state_connected_ctu = ipmi_sol_state_connected_ctu;
11468 %constant int sol_state_closing = ipmi_sol_state_closing;
11469 
set_ACK_timeout(int timeout_usec)11470     void set_ACK_timeout(int timeout_usec)
11471     {
11472 	ipmi_sol_set_ACK_timeout(self, timeout_usec);
11473     }
11474 
get_ACK_timeout()11475     int get_ACK_timeout()
11476     {
11477 	return ipmi_sol_get_ACK_timeout(self);
11478     }
11479 
set_ACK_retries(int retries)11480     void set_ACK_retries(int retries)
11481     {
11482 	ipmi_sol_set_ACK_retries(self, retries);
11483     }
11484 
get_ACK_retries()11485     int get_ACK_retries()
11486     {
11487 	return ipmi_sol_get_ACK_retries(self);
11488     }
11489 
set_use_authentication(int use_authentication)11490     int set_use_authentication(int use_authentication)
11491     {
11492 	return ipmi_sol_set_use_authentication(self, use_authentication);
11493     }
11494 
get_use_authentication()11495     int get_use_authentication()
11496     {
11497 	return ipmi_sol_get_use_authentication(self);
11498     }
11499 
set_use_encryption(int use_encryption)11500     int set_use_encryption(int use_encryption)
11501     {
11502 	return ipmi_sol_set_use_encryption(self, use_encryption);
11503     }
11504 
get_use_encryption()11505     int get_use_encryption()
11506     {
11507 	return ipmi_sol_get_use_encryption(self);
11508     }
11509 
11510 
11511 %constant int sol_serial_alerts_fail = ipmi_sol_serial_alerts_fail;
11512 %constant int sol_serial_alerts_deferred = ipmi_sol_serial_alerts_deferred;
11513 %constant int sol_serial_alerts_succeed = ipmi_sol_serial_alerts_succeed;
11514 
set_shared_serial_alert_behavior(int behavior)11515     int set_shared_serial_alert_behavior(int behavior)
11516     {
11517 	return ipmi_sol_set_shared_serial_alert_behavior(self, behavior);
11518     }
11519 
get_shared_serial_alert_behavior()11520     int get_shared_serial_alert_behavior()
11521     {
11522 	return ipmi_sol_get_shared_serial_alert_behavior(self);
11523     }
11524 
set_deassert_CTS_DCD_DSR_on_connect(int assert)11525     int set_deassert_CTS_DCD_DSR_on_connect(int assert)
11526     {
11527 	return ipmi_sol_set_deassert_CTS_DCD_DSR_on_connect(self, assert);
11528     }
11529 
get_deassert_CTS_DCD_DSR_on_connect()11530     int get_deassert_CTS_DCD_DSR_on_connect()
11531     {
11532 	return ipmi_sol_get_deassert_CTS_DCD_DSR_on_connect(self);
11533     }
11534 
11535 
11536 %constant int SOL_BIT_RATE_DEFAULT = IPMI_SOL_BIT_RATE_DEFAULT;
11537 %constant int SOL_BIT_RATE_9600 = IPMI_SOL_BIT_RATE_9600;
11538 %constant int SOL_BIT_RATE_19200 = IPMI_SOL_BIT_RATE_19200;
11539 %constant int SOL_BIT_RATE_38400 = IPMI_SOL_BIT_RATE_38400;
11540 %constant int SOL_BIT_RATE_57600 = IPMI_SOL_BIT_RATE_57600;
11541 %constant int SOL_BIT_RATE_115200 = IPMI_SOL_BIT_RATE_115200;
11542 
set_bit_rate(unsigned int rate)11543     int set_bit_rate(unsigned int rate)
11544     {
11545 	return ipmi_sol_set_bit_rate(self, rate);
11546     }
11547 
get_bit_rate()11548     unsigned int get_bit_rate()
11549     {
11550 	return ipmi_sol_get_bit_rate(self);
11551     }
11552 
11553 
open()11554     int open()
11555     {
11556 	int rv;
11557 	IPMI_SWIG_C_CB_ENTRY
11558 	rv = ipmi_sol_open(self);
11559 	IPMI_SWIG_C_CB_EXIT
11560 	return rv;
11561     }
11562 
close()11563     int close()
11564     {
11565 	int rv;
11566 	IPMI_SWIG_C_CB_ENTRY
11567 	rv = ipmi_sol_close(self);
11568 	IPMI_SWIG_C_CB_EXIT
11569 	return rv;
11570     }
11571 
force_close()11572     int force_close()
11573     {
11574 	int rv;
11575 	IPMI_SWIG_C_CB_ENTRY
11576 	rv = ipmi_sol_force_close(self);
11577 	IPMI_SWIG_C_CB_EXIT
11578 	return rv;
11579     }
11580 
11581     /*
11582      * Write the given buffer to the serial port.  When complete, the
11583      * sol_write_complete method of the handler will be called with
11584      * the following parameters: <self> <conn> <error>
11585      */
11586     int write(charbuf buf, swig_cb *handler = NULL)
11587     {
11588 	ipmi_sol_transmit_complete_cb cb = NULL;
11589 	swig_cb_val                   *handler_val = NULL;
11590 	int                           rv;
11591 
11592 	IPMI_SWIG_C_CB_ENTRY
11593 	if (!nil_swig_cb(handler)) {
11594 	    if (! valid_swig_cb(handler, sol_write_complete)) {
11595 		rv = EINVAL;
11596 		goto out_err;
11597 	    }
11598 	    cb = sol_write_complete_cb;
11599 	    handler_val = ref_swig_cb(handler, sol_write_complete);
11600 	}
11601 	rv = ipmi_sol_write(self, buf.val, buf.len, cb, handler_val);
11602 	if (rv && handler_val)
11603 	    deref_swig_cb_val(handler_val);
11604     out_err:
11605 	IPMI_SWIG_C_CB_EXIT
11606 	return rv;
11607     }
11608 
11609     /*
11610      * For every NACK returned from the receive routine, this function
11611      * must be called to release the NACK.
11612      */
release_nack()11613     int release_nack()
11614     {
11615 	int rv;
11616 	IPMI_SWIG_C_CB_ENTRY
11617 	rv = ipmi_sol_release_nack(self);
11618 	IPMI_SWIG_C_CB_EXIT
11619 	return rv;
11620     }
11621 
11622     /*
11623      * Send a break to the serial port.  When complete, the
11624      * sol_send_break method of the handler will be called with
11625      * the following parameters: <self> <conn> <error>
11626      */
11627     int send_break(swig_cb *handler = NULL)
11628     {
11629 	ipmi_sol_transmit_complete_cb cb = NULL;
11630 	swig_cb_val                   *handler_val = NULL;
11631 	int                           rv;
11632 
11633 	IPMI_SWIG_C_CB_ENTRY
11634 	if (!nil_swig_cb(handler)) {
11635 	    if (! valid_swig_cb(handler, sol_send_break)) {
11636 		rv = EINVAL;
11637 		goto out_err;
11638 	    }
11639 	    cb = sol_send_break_cb;
11640 	    handler_val = ref_swig_cb(handler, sol_send_break);
11641 	}
11642 	rv = ipmi_sol_send_break(self, cb, handler_val);
11643 	if (rv && handler_val)
11644 	    deref_swig_cb_val(handler_val);
11645     out_err:
11646 	IPMI_SWIG_C_CB_EXIT
11647 	return rv;
11648     }
11649 
11650     /*
11651      * Send CTS assertable (or not) on the serial port.  When
11652      * complete, the sol_set_CTS_assertable method of the handler will
11653      * be called with the following parameters: <self> <conn> <error>
11654      */
11655     int set_CTS_assertable(int asserted, swig_cb *handler = NULL)
11656     {
11657 	ipmi_sol_transmit_complete_cb cb = NULL;
11658 	swig_cb_val                   *handler_val = NULL;
11659 	int                           rv;
11660 
11661 	IPMI_SWIG_C_CB_ENTRY
11662 	if (!nil_swig_cb(handler)) {
11663 	    if (! valid_swig_cb(handler, sol_set_CTS_assertable)) {
11664 		rv = EINVAL;
11665 		goto out_err;
11666 	    }
11667 	    cb = sol_set_CTS_assertable_cb;
11668 	    handler_val = ref_swig_cb(handler, sol_set_CTS_assertable);
11669 	}
11670 	rv = ipmi_sol_set_CTS_assertable(self, asserted, cb, handler_val);
11671 	if (rv && handler_val)
11672 	    deref_swig_cb_val(handler_val);
11673     out_err:
11674 	IPMI_SWIG_C_CB_EXIT
11675 	return rv;
11676     }
11677 
11678     /*
11679      * Assert or deassert DCD and DSR on the serial port.  When
11680      * complete, the sol_set_DCD_DSR_asserted method of the handler
11681      * will be called with the following parameters: <self> <conn>
11682      * <error>
11683      */
11684     int set_DCD_DSR_asserted(int asserted, swig_cb *handler = NULL)
11685     {
11686 	ipmi_sol_transmit_complete_cb cb = NULL;
11687 	swig_cb_val                   *handler_val = NULL;
11688 	int                           rv;
11689 
11690 	IPMI_SWIG_C_CB_ENTRY
11691 	if (!nil_swig_cb(handler)) {
11692 	    if (! valid_swig_cb(handler, sol_set_DCD_DSR_asserted)) {
11693 		rv = EINVAL;
11694 		goto out_err;
11695 	    }
11696 	    cb = sol_set_DCD_DSR_asserted_cb;
11697 	    handler_val = ref_swig_cb(handler, sol_set_DCD_DSR_asserted);
11698 	}
11699 	rv = ipmi_sol_set_DCD_DSR_asserted(self, asserted, cb, handler_val);
11700 	if (rv && handler_val)
11701 	    deref_swig_cb_val(handler_val);
11702     out_err:
11703 	IPMI_SWIG_C_CB_EXIT
11704 	return rv;
11705     }
11706 
11707     /*
11708      * Assert or deassert RI on the serial port.  When complete, the
11709      * sol_set_RI_asserted method of the handler will be called with
11710      * the following parameters: <self> <conn> <error>
11711      */
11712     int set_RI_asserted(int asserted, swig_cb *handler = NULL)
11713     {
11714 	ipmi_sol_transmit_complete_cb cb = NULL;
11715 	swig_cb_val                   *handler_val = NULL;
11716 	int                           rv;
11717 
11718 	IPMI_SWIG_C_CB_ENTRY
11719 	if (!nil_swig_cb(handler)) {
11720 	    if (! valid_swig_cb(handler, sol_set_RI_asserted)) {
11721 		rv = EINVAL;
11722 		goto out_err;
11723 	    }
11724 	    cb = sol_set_RI_asserted_cb;
11725 	    handler_val = ref_swig_cb(handler, sol_set_RI_asserted);
11726 	}
11727 	rv = ipmi_sol_set_RI_asserted(self, asserted, cb, handler_val);
11728 	if (rv && handler_val)
11729 	    deref_swig_cb_val(handler_val);
11730     out_err:
11731 	IPMI_SWIG_C_CB_EXIT
11732 	return rv;
11733     }
11734 
11735 
11736 %constant int SOL_BMC_TRANSMIT_QUEUE = IPMI_SOL_BMC_TRANSMIT_QUEUE;
11737 %constant int SOL_BMC_RECEIVE_QUEUE = IPMI_SOL_BMC_RECEIVE_QUEUE;
11738 %constant int SOL_MANAGEMENT_CONSOLE_TRANSMIT_QUEUE = IPMI_SOL_MANAGEMENT_CONSOLE_TRANSMIT_QUEUE;
11739 %constant int SOL_MANAGEMENT_CONSOLE_RECEIVE_QUEUE = IPMI_SOL_MANAGEMENT_CONSOLE_RECEIVE_QUEUE;
11740 %constant int SOL_BMC_QUEUES = IPMI_SOL_BMC_QUEUES;
11741 %constant int SOL_MANAGEMENT_CONSOLE_QUEUES = IPMI_SOL_MANAGEMENT_CONSOLE_QUEUES;
11742 %constant int SOL_ALL_QUEUES = IPMI_SOL_ALL_QUEUES;
11743 
11744     /*
11745      * Flush the given queues, as specified by the queue selectors
11746      * above.  When complete, the sol_flush_complete method of the
11747      * handler will be called with the following parameters: <self>
11748      * <conn> <queue selectors> <error>
11749      */
11750     int flush(int queue_selectors, swig_cb *handler = NULL)
11751     {
11752 	ipmi_sol_flush_complete_cb cb = NULL;
11753 	swig_cb_val                *handler_val = NULL;
11754 	int                        rv;
11755 
11756 	IPMI_SWIG_C_CB_ENTRY
11757 	if (!nil_swig_cb(handler)) {
11758 	    if (! valid_swig_cb(handler, sol_flush_complete)) {
11759 		rv = EINVAL;
11760 		goto out_err;
11761 	    }
11762 	    cb = sol_flush_complete_cb;
11763 	    handler_val = ref_swig_cb(handler, sol_flush_complete);
11764 	}
11765 	rv = ipmi_sol_flush(self, queue_selectors, cb, handler_val);
11766 	if (rv && handler_val)
11767 	    deref_swig_cb_val(handler_val);
11768     out_err:
11769 	IPMI_SWIG_C_CB_EXIT
11770 	return rv;
11771     }
11772 
11773 }
11774 
11775 %extend ipmi_solparm_t {
~ipmi_solparm_t()11776     ~ipmi_solparm_t()
11777     {
11778 	ipmi_solparm_deref(self);
11779     }
11780 
11781     %newobject get_mc_id;
get_mc_id()11782     ipmi_mcid_t *get_mc_id()
11783     {
11784 	ipmi_mcid_t *rv = malloc(sizeof(*rv));
11785 	if (rv)
11786 	    *rv = ipmi_solparm_get_mc_id(self);
11787 	return rv;
11788     }
11789 
get_channel()11790     int get_channel()
11791     {
11792 	return ipmi_solparm_get_channel(self);
11793     }
11794 
11795 %constant int SOLPARM_SET_IN_PROGRESS = IPMI_SOLPARM_SET_IN_PROGRESS;
11796 %constant int SOLPARM_ENABLE = IPMI_SOLPARM_ENABLE;
11797 %constant int SOLPARM_AUTHENTICATION = IPMI_SOLPARM_AUTHENTICATION;
11798 %constant int SOLPARM_CHAR_SETTINGS = IPMI_SOLPARM_CHAR_SETTINGS;
11799 %constant int SOLPARM_RETRY = IPMI_SOLPARM_RETRY;
11800 %constant int SOLPARM_NONVOLATILE_BITRATE = IPMI_SOLPARM_NONVOLATILE_BITRATE;
11801 %constant int SOLPARM_VOLATILE_BITRATE = IPMI_SOLPARM_VOLATILE_BITRATE;
11802 %constant int SOLPARM_PAYLOAD_CHANNEL = IPMI_SOLPARM_PAYLOAD_CHANNEL;
11803 %constant int SOLPARM_PAYLOAD_PORT_NUMBER = IPMI_SOLPARM_PAYLOAD_PORT_NUMBER;
11804 
11805     /*
11806      * Fetch an individual parm from the MC.  The parameter (parm1) ,
11807      * and set (parm2) and block (parm3) are specified, along with a
11808      * handler (parm4).  The solparm_got_parm_cb method on the handler
11809      * will be called when the the operation completes with the
11810      * following parms: <self> <solparm> <err> <parm_rev> <data1> [<data2> ...]
11811      */
get_parm(int parm,int set,int block,swig_cb * handler)11812     int get_parm(int parm, int set, int block, swig_cb *handler)
11813     {
11814 	int         rv;
11815 	swig_cb_val *handler_val;
11816 
11817 	IPMI_SWIG_C_CB_ENTRY
11818 	if (!valid_swig_cb(handler, solparm_got_parm_cb))
11819 	    rv = EINVAL;
11820 	else {
11821 	    handler_val = ref_swig_cb(handler, solparm_got_parm_cb);
11822 	    ipmi_solparm_ref(self);
11823 	    rv = ipmi_solparm_get_parm(self, parm, set, block,
11824 				       solparm_get_parm, handler_val);
11825 	    if (rv) {
11826 		ipmi_solparm_deref(self);
11827 		deref_swig_cb_val(handler_val);
11828 	    }
11829 	}
11830 	IPMI_SWIG_C_CB_EXIT
11831 	return rv;
11832     }
11833 
11834     /*
11835      * Set an individual parm on the MC.  The parameter (parm1),
11836      * and string value (parm2) is specified, along with an optional
11837      * handler (parm3).  The solparm_set_parm_cb method on the handler
11838      * will be called when the the operation completes with the
11839      * following parms: <self> <solparm> <err>.
11840      *
11841      * The string value is in the form "0xNN 0xNN ...", basically
11842      * a string of integer values.
11843      */
11844     int set_parm(int parm, char *value, swig_cb *handler = NULL)
11845     {
11846 	int           rv;
11847 	swig_cb_val   *handler_val = NULL;
11848 	unsigned char *data;
11849 	unsigned int  length;
11850 
11851 	IPMI_SWIG_C_CB_ENTRY
11852 	data = parse_raw_str_data(value, &length);
11853 	if (!data) {
11854 	    rv = ENOMEM;
11855 	    goto out_err;
11856 	}
11857 
11858 	if (!nil_swig_cb(handler)) {
11859 	    if (! valid_swig_cb(handler, solparm_set_parm_cb)) {
11860 		free(data);
11861 		rv = EINVAL;
11862 		goto out_err;
11863 	    }
11864 	    handler_val = ref_swig_cb(handler, solparm_set_parm_cb);
11865 	}
11866 
11867 	if (handler_val)
11868 	    ipmi_solparm_ref(self);
11869 	rv = ipmi_solparm_set_parm(self, parm, data, length,
11870 				   solparm_set_parm, handler_val);
11871 	free(data);
11872 	if (rv && handler_val) {
11873 	    ipmi_solparm_deref(self);
11874 	    deref_swig_cb_val(handler_val);
11875 	}
11876     out_err:
11877 	IPMI_SWIG_C_CB_EXIT
11878 	return rv;
11879     }
11880 
11881     /*
11882      * Set an individual parm on the MC.  The parameter (parm1), and
11883      * an array of integers (parm2) is specified, along with an
11884      * optional handler (parm3).  The solparm_set_parm_cb method on
11885      * the handler will be called when the the operation completes
11886      * with the following parms: <self> <solparm> <err>.
11887      *
11888      * The string value is in the form "0xNN 0xNN ...", basically
11889      * a string of integer values.
11890      */
11891     int set_parm_array(int parm, intarray value, swig_cb *handler = NULL)
11892     {
11893 	int           rv;
11894 	swig_cb_val   *handler_val = NULL;
11895 	unsigned char *data;
11896 	unsigned int  length = value.len;
11897 
11898 	IPMI_SWIG_C_CB_ENTRY
11899 	if (length == 0)
11900 	    data = malloc(1);
11901 	else
11902 	    data = malloc(length);
11903 	if (!data) {
11904 	    rv = ENOMEM;
11905 	    goto out_err;
11906 	}
11907 	parse_ipmi_data(value, data, length, &length);
11908 
11909 	if (!nil_swig_cb(handler)) {
11910 	    if (! valid_swig_cb(handler, solparm_set_parm_cb)) {
11911 		free(data);
11912 		rv = EINVAL;
11913 		goto out_err;
11914 	    }
11915 	    handler_val = ref_swig_cb(handler, solparm_set_parm_cb);
11916 	}
11917 
11918 	if (handler_val)
11919 	    ipmi_solparm_ref(self);
11920 	rv = ipmi_solparm_set_parm(self, parm, data, length,
11921 				   solparm_set_parm, handler_val);
11922 	free(data);
11923 	if (rv && handler_val) {
11924 	    ipmi_solparm_deref(self);
11925 	    deref_swig_cb_val(handler_val);
11926 	}
11927     out_err:
11928 	IPMI_SWIG_C_CB_EXIT
11929 	return rv;
11930     }
11931 
11932     /*
11933      * Get the full standard configuration for the solparms.  When
11934      * done, the solparm_got_config_cb method will be called on the
11935      * handler (first parm) with the following parms: <self> <solparm>
11936      * <err> <solconfig>.  The solconfig will be an object of type
11937      * ipmi_sol_config_t.
11938      */
get_config(swig_cb * handler)11939     int get_config(swig_cb *handler)
11940     {
11941 	int         rv;
11942 	swig_cb_val *handler_val = NULL;
11943 
11944 	IPMI_SWIG_C_CB_ENTRY
11945 	if (!valid_swig_cb(handler, solparm_got_config_cb))
11946 	    rv = EINVAL;
11947 	else {
11948 	    handler_val = ref_swig_cb(handler, solparm_got_config_cb);
11949 
11950 	    ipmi_solparm_ref(self);
11951 	    rv = ipmi_sol_get_config(self, solparm_get_config, handler_val);
11952 	    if (rv) {
11953 		ipmi_solparm_deref(self);
11954 		deref_swig_cb_val(handler_val);
11955 	    }
11956 	}
11957 	IPMI_SWIG_C_CB_EXIT
11958 	return rv;
11959 
11960     }
11961 
11962     /*
11963      * Set the full standard configuration for the solparms.  The
11964      * config to set is the first parm of type ipmi_sol_config_t.  When
11965      * done, the solparm_set_config_cb method will be called on the
11966      * handler (second parm) with the following parms: <self>
11967      * <solparm> <err>.
11968      */
11969     int set_config(ipmi_sol_config_t *config, swig_cb *handler = NULL)
11970     {
11971 	int         rv;
11972 	swig_cb_val *handler_val = NULL;
11973 
11974 	IPMI_SWIG_C_CB_ENTRY
11975 	if (!nil_swig_cb(handler)) {
11976 	    if (! valid_swig_cb(handler, solparm_set_config_cb)) {
11977 		rv = EINVAL;
11978 		goto out_err;
11979 	    }
11980 	    handler_val = ref_swig_cb(handler, solparm_set_config_cb);
11981 	}
11982 
11983 	if (handler_val)
11984 	    ipmi_solparm_ref(self);
11985 	rv = ipmi_sol_set_config(self, config,
11986 				 solparm_set_config, handler_val);
11987 	if (rv && handler_val) {
11988 	    ipmi_solparm_deref(self);
11989 	    deref_swig_cb_val(handler_val);
11990 	}
11991     out_err:
11992 	IPMI_SWIG_C_CB_EXIT
11993 	return rv;
11994     }
11995 
11996     /*
11997      * Unlock the lock for the solparm.  The config to set is the
11998      * first parm of type ipmi_sol_config_t and may be undefined
11999      * (meaning that the MC of the solparm will be unlocked).  If the
12000      * config is supplied, it will be marked as unlocked.  When done,
12001      * the solparm_clear_lock_cb method will be called on the handler
12002      * (second parm) with the following parms: <self> <solparm> <err>.
12003      */
12004     int clear_lock(ipmi_sol_config_t *config = NULL, swig_cb *handler = NULL)
12005     {
12006 	int         rv;
12007 	swig_cb_val *handler_val = NULL;
12008 
12009 	IPMI_SWIG_C_CB_ENTRY
12010 	if (!nil_swig_cb(handler)) {
12011 	    if (! valid_swig_cb(handler, solparm_clear_lock_cb)) {
12012 		rv = EINVAL;
12013 		goto out_err;
12014 	    }
12015 	    handler_val = ref_swig_cb(handler, solparm_clear_lock_cb);
12016 	}
12017 
12018 	if (handler_val)
12019 	    ipmi_solparm_ref(self);
12020 	rv = ipmi_sol_clear_lock(self, config,
12021 				 solparm_clear_lock, handler_val);
12022 	if (rv && handler_val) {
12023 	    ipmi_solparm_deref(self);
12024 	    deref_swig_cb_val(handler_val);
12025 	}
12026     out_err:
12027 	IPMI_SWIG_C_CB_EXIT
12028 	return rv;
12029     }
12030 }
12031 
12032 %extend ipmi_sol_config_t {
~ipmi_sol_config_t()12033     ~ipmi_sol_config_t()
12034     {
12035 	ipmi_sol_free_config(self);
12036     }
12037 
12038     /*
12039      * Get a value from the solconfig.  The first parameter is the
12040      * parm number, the second is the parm index (which is a pointer
12041      * to an integer).  The returned value will be undefined if
12042      * an error occurred, it will be of the format:
12043      *   "<name> <type> <data>"
12044      * The type and data will not be present if the data value is not
12045      * supported or the index is out of range, but the name will still
12046      * be present.
12047      *
12048      * The supports types are: integer, bool, data, ip, and mac.  The
12049      * data for an integer is a number.  The data for a bool is true
12050      * or false.  The data for ip is an IP address in the form
12051      * "n.n.n.n".  Data for mac is a mac address in the form
12052      * "nn:nn:nn:nn:nn:nn"
12053      *
12054      * The second parameter (the index) is zero based and should be
12055      * set to zero when fetching an index for the first time.  It will
12056      * be unchanged if the data item does not support multiple items.
12057      * If it does support multiple items, then the number will be
12058      * changed to the next supported value, or to -1 if this is the
12059      * last item.
12060      *
12061      * Be careful with the index, it must be a number, not something
12062      * that can be interpreted to a number.  If necessary, in perl,
12063      * you must do $idx = int($idx) in some cases.
12064      */
12065     %newobject get_val;
get_val(int parm,int * index)12066     char *get_val(int parm, int *index)
12067     {
12068 	enum ipmi_solconf_val_type_e valtype;
12069 	unsigned int      ival = 0;
12070 	unsigned char     *dval = NULL;
12071 	unsigned int      dval_len = 0;
12072 	const char        *name;
12073 	char              dummy[1];
12074 	char              *str = NULL, *s;
12075 	int               rv;
12076 	int               i;
12077 	unsigned int      len;
12078 
12079 	rv = ipmi_solconfig_get_val(self, parm, &name, index, &valtype,
12080 				    &ival, &dval, &dval_len);
12081 	if ((rv == ENOSYS) || (rv == E2BIG))
12082 	    return strdup(name);
12083 	else if (rv)
12084 	    return NULL;
12085 
12086 	switch (valtype) {
12087 	case IPMI_SOLCONFIG_INT:
12088 	    len = snprintf(dummy, 1, "%s integer %d", name, ival);
12089 	    str = malloc(len + 1);
12090 	    sprintf(str, "%s integer %d", name, ival);
12091 	    break;
12092 
12093 	case IPMI_SOLCONFIG_BOOL:
12094 	    len = snprintf(dummy, 1, "%s bool %s", name,
12095 			   ival ? "true" : "false");
12096 	    str = malloc(len + 1);
12097 	    sprintf(str, "%s bool %s", name,
12098 		    ival ? "true" : "false");
12099 	    break;
12100 
12101 	case IPMI_SOLCONFIG_DATA:
12102 	    len = snprintf(dummy, 1, "%s data", name);
12103 	    len += dval_len * 5;
12104 	    str = malloc(len + 1);
12105 	    s = str;
12106 	    s += sprintf(s, "%s data", name);
12107 	    for (i=0; i<dval_len; i++)
12108 		s += sprintf(s, " 0x%2.2x", dval[i]);
12109 	    break;
12110 
12111 	case IPMI_SOLCONFIG_IP:
12112 	    len = snprintf(dummy, 1, "%s ip", name);
12113 	    len += 4 * 4; /* worst case */
12114 	    str = malloc(len + 1);
12115 	    sprintf(str, "%s ip %d.%d.%d.%d", name,
12116 		    dval[0], dval[1], dval[2], dval[3]);
12117 	    break;
12118 
12119 	case IPMI_SOLCONFIG_MAC:
12120 	    len = snprintf(dummy, 1, "%s mac", name);
12121 	    len += 6 * 3;
12122 	    str = malloc(len + 1);
12123 	    s = str;
12124 	    s += sprintf(s, "%s mac ", name);
12125 	    for (i=0; i<5; i++)
12126 		s += sprintf(s, "%2.2x:", dval[i]);
12127 	    sprintf(s, "%2.2x", dval[i]);
12128 	    break;
12129 	}
12130 
12131 	if (dval)
12132 	    ipmi_solconfig_data_free(dval);
12133 
12134 	return str;
12135     }
12136 
12137     /*
12138      * Set a value in the solconfig.  The first parameter is the parm
12139      * number, the second is the parm index.  The type is a string
12140      * in the third parm.  The data is the fourth parm.
12141      *
12142      * The supports types are: integer, bool, data, ip, and mac.  The
12143      * data for an integer is a number.  The data for a bool is true
12144      * or false.  The data for ip is an IP address in the form
12145      * "n.n.n.n".  Data for mac is a mac address in the form
12146      * "nn.nn.nn.nn.nn.nn"
12147      *
12148      * The index is ignored for types that do not use it.
12149      */
set_val(int parm,int idx,char * type,char * value)12150     int set_val(int parm, int idx, char *type, char *value) {
12151 	enum ipmi_solconf_val_type_e valtype;
12152 	int               rv;
12153 	unsigned int      ival = 0;
12154 	unsigned char     *dval = NULL;
12155 	unsigned int      dval_len = 0;
12156 
12157 	rv = ipmi_solconfig_parm_to_type(parm, &valtype);
12158 	if (rv)
12159 	    return rv;
12160 
12161 	switch (valtype) {
12162 	case IPMI_SOLCONFIG_INT:
12163 	{
12164 	    char *endstr;
12165 	    if (strcmp(type, "integer") != 0)
12166 		return EINVAL;
12167 	    if (!value)
12168 		return EINVAL;
12169 	    if (*value == '\0')
12170 		return EINVAL;
12171 	    ival = strtol(value, &endstr, 0);
12172 	    if (*endstr != '\0')
12173 		return EINVAL;
12174 	    break;
12175 	}
12176 
12177 	case IPMI_SOLCONFIG_BOOL:
12178 	    if (strcmp(type, "bool") != 0)
12179 		return EINVAL;
12180 	    if (!value)
12181 		return EINVAL;
12182 	    if (strcasecmp(value, "true") == 0)
12183 		ival = 1;
12184 	    else if (strcasecmp(value, "false") == 0)
12185 		ival = 0;
12186 	    else if (strcasecmp(value, "on") == 0)
12187 		ival = 1;
12188 	    else if (strcasecmp(value, "off") == 0)
12189 		ival = 0;
12190 	    else
12191 		return EINVAL;
12192 	    break;
12193 
12194 	case IPMI_SOLCONFIG_DATA:
12195 	    if (strcmp(type, "data") != 0)
12196 		return EINVAL;
12197 	    if (!value)
12198 		return EINVAL;
12199 	    dval = parse_raw_str_data(value, &dval_len);
12200 	    if (!dval)
12201 		return ENOMEM;
12202 	    break;
12203 
12204 	case IPMI_SOLCONFIG_IP:
12205 	    {
12206 		struct in_addr addr;
12207 		if (strcmp(type, "ip") != 0)
12208 		    return EINVAL;
12209 		rv = parse_ip_addr(value, &addr);
12210 		if (rv)
12211 		    return rv;
12212 		dval = malloc(4);
12213 		memcpy(dval, &addr.s_addr, 4);
12214 		dval_len = 4;
12215 	    }
12216 	    break;
12217 
12218 	case IPMI_SOLCONFIG_MAC:
12219 	    if (strcmp(type, "mac") != 0)
12220 		return EINVAL;
12221 	    dval = malloc(6);
12222 	    rv = parse_mac_addr(value, dval);
12223 	    if (rv) {
12224 		free(dval);
12225 		return rv;
12226 	    }
12227 	    dval_len = 6;
12228 	    break;
12229 	}
12230 
12231 	rv = ipmi_solconfig_set_val(self, parm, idx, ival, dval, dval_len);
12232 	if (dval)
12233 	    free(dval);
12234 	return rv;
12235     }
12236 }
12237