~ubuntu-branches/ubuntu/karmic/openipmi/karmic

« back to all changes in this revision

Viewing changes to ui/ui.c

  • Committer: Bazaar Package Importer
  • Author(s): Noèl Köthe
  • Date: 2005-07-04 21:29:17 UTC
  • Revision ID: james.westby@ubuntu.com-20050704212917-igddk5jawjmhrlay
Tags: upstream-2.0.1
Import upstream version 2.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ui.c
 
3
 *
 
4
 * MontaVista IPMI code, a simple curses UI for IPMI
 
5
 *
 
6
 * Author: MontaVista Software, Inc.
 
7
 *         Corey Minyard <minyard@mvista.com>
 
8
 *         source@mvista.com
 
9
 *
 
10
 * Copyright 2002,2003,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
#include <stdio.h>
 
35
#include <stdlib.h>
 
36
#include <string.h>
 
37
#include <curses.h>
 
38
#include <stdarg.h>
 
39
#include <errno.h>
 
40
#include <unistd.h>
 
41
#include <termios.h>
 
42
#include <fcntl.h>
 
43
#include <time.h>
 
44
#include <sys/time.h>
 
45
#include <ctype.h>
 
46
 
 
47
#include <OpenIPMI/selector.h>
 
48
#include <OpenIPMI/ipmi_err.h>
 
49
#include <OpenIPMI/ipmi_msgbits.h>
 
50
#include <OpenIPMI/ipmi_mc.h>
 
51
#include <OpenIPMI/ipmiif.h>
 
52
#include <OpenIPMI/ipmi_ui.h>
 
53
#include <OpenIPMI/ipmi_fru.h>
 
54
#include <OpenIPMI/ipmi_pef.h>
 
55
#include <OpenIPMI/ipmi_lanparm.h>
 
56
#include <OpenIPMI/ipmi_pet.h>
 
57
#include <OpenIPMI/ipmi_conn.h>
 
58
#include <OpenIPMI/ipmi_debug.h>
 
59
#include <OpenIPMI/internal/ipmi_mc.h>
 
60
 
 
61
#include <OpenIPMI/internal/ipmi_malloc.h>
 
62
#include <OpenIPMI/internal/ipmi_event.h>
 
63
 
 
64
#include "ui_keypad.h"
 
65
#include "ui_command.h"
 
66
 
 
67
WINDOW *main_win;
 
68
WINDOW *cmd_win;
 
69
WINDOW *stat_win;
 
70
WINDOW *log_pad;
 
71
WINDOW *dummy_pad;
 
72
WINDOW *display_pad;
 
73
 
 
74
selector_t *ui_sel;
 
75
 
 
76
int log_pad_top_line;
 
77
int display_pad_top_line;
 
78
 
 
79
keypad_t keymap;
 
80
command_t commands;
 
81
 
 
82
ipmi_domain_id_t domain_id;
 
83
 
 
84
extern os_handler_t ipmi_ui_cb_handlers;
 
85
ipmi_pef_t *pef;
 
86
ipmi_pef_config_t *pef_config;
 
87
ipmi_lanparm_t *lanparm;
 
88
ipmi_lan_config_t *lanparm_config;
 
89
 
 
90
static int full_screen;
 
91
struct termios old_termios;
 
92
int old_flags;
 
93
 
 
94
#define STATUS_WIN_LINES 2
 
95
#define STATUS_WIN_COLS COLS
 
96
#define STATUS_WIN_TOP 0
 
97
#define STATUS_WIN_LEFT 0
 
98
 
 
99
#define CMD_WIN_LINES 3
 
100
#define CMD_WIN_COLS COLS
 
101
#define CMD_WIN_LEFT 0
 
102
#define CMD_WIN_TOP  (LINES-CMD_WIN_LINES)
 
103
 
 
104
#define DISPLAY_WIN_LINES (LINES - STATUS_WIN_LINES - CMD_WIN_LINES - 2)
 
105
#define DISPLAY_WIN_COLS (COLS/2-1)
 
106
#define DISPLAY_WIN_TOP (STATUS_WIN_LINES+1)
 
107
#define DISPLAY_WIN_LEFT 0
 
108
#define DISPLAY_WIN_RIGHT (COLS/2-2)
 
109
#define DISPLAY_WIN_BOTTOM (CMD_WIN_TOP-2)
 
110
#define NUM_DISPLAY_LINES 1024
 
111
 
 
112
#define LOG_WIN_LINES (LINES - STATUS_WIN_LINES - CMD_WIN_LINES - 2)
 
113
#define LOG_WIN_COLS (COLS-(COLS/2))
 
114
#define LOG_WIN_LEFT (COLS/2)
 
115
#define LOG_WIN_RIGHT (COLS-1)
 
116
#define LOG_WIN_TOP (STATUS_WIN_LINES+1)
 
117
#define LOG_WIN_BOTTOM (CMD_WIN_TOP-2)
 
118
#define NUM_LOG_LINES 1024
 
119
 
 
120
#define TOP_LINE    STATUS_WIN_LINES
 
121
#define BOTTOM_LINE (LINES-CMD_WIN_LINES-1)
 
122
#define MID_COL (COLS/2-1)
 
123
#define MID_LINES (LINES - STATUS_WIN_LINES - CMD_WIN_LINES - 2)
 
124
 
 
125
enum scroll_wins_e { LOG_WIN_SCROLL, DISPLAY_WIN_SCROLL };
 
126
 
 
127
enum scroll_wins_e curr_win = LOG_WIN_SCROLL;
 
128
 
 
129
/* The current thing display in the display pad. */
 
130
enum {
 
131
    DISPLAY_NONE, DISPLAY_SENSOR, DISPLAY_SENSORS,
 
132
    DISPLAY_CONTROLS, DISPLAY_CONTROL, DISPLAY_ENTITIES, DISPLAY_MCS,
 
133
    DISPLAY_MC,
 
134
    DISPLAY_RSP, DISPLAY_SDRS, HELP, EVENTS, DISPLAY_ENTITY, DISPLAY_FRU
 
135
} curr_display_type;
 
136
ipmi_sensor_id_t curr_sensor_id;
 
137
ipmi_control_id_t curr_control_id;
 
138
typedef struct pos_s {int y; int x; } pos_t;
 
139
typedef struct thr_pos_s
 
140
{
 
141
    int   set;
 
142
    pos_t value;
 
143
    pos_t enabled;
 
144
    pos_t oor;
 
145
} thr_pos_t;
 
146
thr_pos_t threshold_positions[6];
 
147
 
 
148
pos_t value_pos;
 
149
pos_t enabled_pos;
 
150
pos_t scanning_pos;
 
151
pos_t discr_assert_enab;
 
152
pos_t discr_deassert_enab;
 
153
 
 
154
ipmi_entity_id_t curr_entity_id;
 
155
 
 
156
static char *line_buffer = NULL;
 
157
static int  line_buffer_max = 0;
 
158
static int  line_buffer_pos = 0;
 
159
 
 
160
sel_timer_t *redisplay_timer;
 
161
 
 
162
static void
 
163
conv_from_spaces(char *name)
 
164
{
 
165
    while (*name) {
 
166
        if (*name == ' ')
 
167
            *name = '~';
 
168
        name++;
 
169
    }
 
170
}
 
171
 
 
172
static void
 
173
conv_to_spaces(char *name)
 
174
{
 
175
    while (*name) {
 
176
        if (*name == '~')
 
177
            *name = ' ';
 
178
        name++;
 
179
    }
 
180
}
 
181
 
 
182
void
 
183
log_pad_refresh(int newlines)
 
184
{
 
185
    if (full_screen) {
 
186
        if (log_pad_top_line < 0)
 
187
            log_pad_top_line = 0;
 
188
 
 
189
        if (log_pad_top_line > (NUM_LOG_LINES - LOG_WIN_LINES))
 
190
            log_pad_top_line = NUM_LOG_LINES - LOG_WIN_LINES;
 
191
 
 
192
        if (log_pad_top_line != (NUM_LOG_LINES - LOG_WIN_LINES)) {
 
193
            /* We are not at the bottom, so hold the same position. */
 
194
            log_pad_top_line -= newlines;
 
195
        }
 
196
        prefresh(log_pad,
 
197
                 log_pad_top_line, 0,
 
198
                 LOG_WIN_TOP, LOG_WIN_LEFT,
 
199
                 LOG_WIN_BOTTOM, LOG_WIN_RIGHT);
 
200
        wrefresh(cmd_win);
 
201
    }
 
202
}
 
203
 
 
204
void
 
205
vlog_pad_out(char *format, va_list ap)
 
206
{
 
207
    if (full_screen)
 
208
        vw_printw(log_pad, format, ap);
 
209
    else
 
210
        vprintf(format, ap);
 
211
}
 
212
 
 
213
void
 
214
log_pad_out(char *format, ...)
 
215
{
 
216
    va_list ap;
 
217
 
 
218
    va_start(ap, format);
 
219
    vlog_pad_out(format, ap);
 
220
    va_end(ap);
 
221
}
 
222
 
 
223
void
 
224
display_pad_refresh(void)
 
225
{
 
226
    if (full_screen) {
 
227
        if (display_pad_top_line >= NUM_DISPLAY_LINES)
 
228
            display_pad_top_line = NUM_DISPLAY_LINES;
 
229
 
 
230
        if (display_pad_top_line < 0)
 
231
            display_pad_top_line = 0;
 
232
 
 
233
        prefresh(display_pad,
 
234
                 display_pad_top_line, 0,
 
235
                 DISPLAY_WIN_TOP, DISPLAY_WIN_LEFT,
 
236
                 DISPLAY_WIN_BOTTOM, DISPLAY_WIN_RIGHT);
 
237
        wrefresh(cmd_win);
 
238
    }
 
239
}
 
240
 
 
241
void
 
242
display_pad_clear(void)
 
243
{
 
244
    display_pad_top_line = 0;
 
245
    if (full_screen) {
 
246
        werase(display_pad);
 
247
        wmove(display_pad, 0, 0);
 
248
    }
 
249
}
 
250
 
 
251
void
 
252
display_pad_clear_nomove(void)
 
253
{
 
254
    if (full_screen) {
 
255
        werase(display_pad);
 
256
        wmove(display_pad, 0, 0);
 
257
    }
 
258
}
 
259
 
 
260
void
 
261
display_pad_out(char *format, ...)
 
262
{
 
263
    va_list ap;
 
264
 
 
265
    va_start(ap, format);
 
266
    if (full_screen)
 
267
        vw_printw(display_pad, format, ap);
 
268
    else
 
269
        vprintf(format, ap);
 
270
    va_end(ap);
 
271
}
 
272
 
 
273
void
 
274
cmd_win_out(char *format, ...)
 
275
{
 
276
    va_list ap;
 
277
 
 
278
    va_start(ap, format);
 
279
    if (full_screen)
 
280
        vw_printw(cmd_win, format, ap);
 
281
    else
 
282
        vprintf(format, ap);
 
283
    va_end(ap);
 
284
}
 
285
 
 
286
void
 
287
cmd_win_refresh(void)
 
288
{
 
289
    if (full_screen)
 
290
        wrefresh(cmd_win);
 
291
    else
 
292
        fflush(stdout);
 
293
}
 
294
 
 
295
static int
 
296
get_uchar(char **toks, unsigned char *val, char *errstr)
 
297
{
 
298
    char *str, *tmpstr;
 
299
 
 
300
    str = strtok_r(NULL, " \t\n", toks);
 
301
    if (!str) {
 
302
        if (errstr)
 
303
            cmd_win_out("No %s given\n", errstr);
 
304
        return EINVAL;
 
305
    }
 
306
    *val = strtoul(str, &tmpstr, 16);
 
307
    if (*tmpstr != '\0') {
 
308
        if (errstr)
 
309
            cmd_win_out("Invalid %s given\n", errstr);
 
310
        return EINVAL;
 
311
    }
 
312
 
 
313
    return 0;
 
314
}
 
315
 
 
316
static int
 
317
get_uint(char **toks, unsigned int *val, char *errstr)
 
318
{
 
319
    char *str, *tmpstr;
 
320
 
 
321
    str = strtok_r(NULL, " \t\n", toks);
 
322
    if (!str) {
 
323
        if (errstr)
 
324
            cmd_win_out("No %s given\n", errstr);
 
325
        return EINVAL;
 
326
    }
 
327
    *val = strtoul(str, &tmpstr, 16);
 
328
    if (*tmpstr != '\0') {
 
329
        if (errstr)
 
330
            cmd_win_out("Invalid %s given\n", errstr);
 
331
        return EINVAL;
 
332
    }
 
333
 
 
334
    return 0;
 
335
}
 
336
 
 
337
static int
 
338
get_ip_addr(char **toks, struct in_addr *ip_addr, char *errstr)
 
339
{
 
340
    u_int32_t     addr;
 
341
    unsigned char val;
 
342
    char          *str, *tmpstr, *istr;
 
343
    char          *ntok;
 
344
    int           i;
 
345
 
 
346
    str = strtok_r(NULL, " \t\n", toks);
 
347
    if (!str) {
 
348
        if (errstr)
 
349
            cmd_win_out("No %s given\n", errstr);
 
350
        return EINVAL;
 
351
    }
 
352
 
 
353
    addr = 0;
 
354
    for (i=0; i<4; i++) {
 
355
        istr = strtok_r(str, ".", &ntok);
 
356
        str = NULL;
 
357
        if (!istr) {
 
358
            if (errstr)
 
359
                cmd_win_out("%s: invalid IP address\n", errstr);
 
360
            return EINVAL;
 
361
        }
 
362
        val = strtoul(istr, &tmpstr, 10);
 
363
        if (*tmpstr != '\0') {
 
364
            if (errstr)
 
365
                cmd_win_out("%s: Invalid IP address\n", errstr);
 
366
            return EINVAL;
 
367
        }
 
368
        addr = (addr << 8) | val;
 
369
    }
 
370
 
 
371
    ip_addr->s_addr = htonl(addr);
 
372
    return 0;
 
373
}
 
374
 
 
375
static int
 
376
get_mac_addr(char **toks, unsigned char *mac_addr, char *errstr)
 
377
{
 
378
    char *str, *tmpstr, *istr;
 
379
    char *ntok;
 
380
    int  i;
 
381
 
 
382
    str = strtok_r(NULL, " \t\n", toks);
 
383
    if (!str) {
 
384
        if (errstr)
 
385
            cmd_win_out("No %s given\n", errstr);
 
386
        return EINVAL;
 
387
    }
 
388
 
 
389
    for (i=0; i<6; i++) {
 
390
        istr = strtok_r(str, ":", &ntok);
 
391
        str = NULL;
 
392
        if (!istr) {
 
393
            if (errstr)
 
394
                cmd_win_out("%s: invalid IP address\n", errstr);
 
395
            return EINVAL;
 
396
        }
 
397
        mac_addr[i] = strtoul(istr, &tmpstr, 16);
 
398
        if (*tmpstr != '\0') {
 
399
            if (errstr)
 
400
                cmd_win_out("%s: Invalid IP address\n", errstr);
 
401
            return EINVAL;
 
402
        }
 
403
    }
 
404
    return 0;
 
405
}
 
406
 
 
407
void
 
408
draw_lines()
 
409
{
 
410
    werase(main_win);
 
411
    wmove(main_win, TOP_LINE, 0);
 
412
    whline(main_win, 0, COLS);
 
413
    wmove(main_win, BOTTOM_LINE, 0);
 
414
    whline(main_win, 0, COLS);
 
415
    wmove(main_win, TOP_LINE, MID_COL);
 
416
    wvline(main_win, ACS_TTEE, 1);
 
417
    wmove(main_win, TOP_LINE+1, MID_COL);
 
418
    wvline(main_win, 0, MID_LINES);
 
419
    wmove(main_win, TOP_LINE+1+MID_LINES, MID_COL);
 
420
    wvline(main_win, ACS_BTEE, 1);
 
421
    wrefresh(main_win);
 
422
}    
 
423
 
 
424
void
 
425
ui_vlog(char *format, enum ipmi_log_type_e log_type, va_list ap)
 
426
{
 
427
    int do_nl = 1;
 
428
    struct timeval now;
 
429
 
 
430
    gettimeofday(&now, NULL);
 
431
 
 
432
    if (full_screen) {
 
433
        int x = 0, y = 0, old_x = 0, old_y = 0;
 
434
        int max_x, max_y, i, j;
 
435
 
 
436
        /* Generate the output to the dummy pad to see how many lines we
 
437
           will use. */
 
438
        getyx(dummy_pad, old_y, old_x);
 
439
        switch(log_type)
 
440
        {
 
441
            case IPMI_LOG_INFO:
 
442
                wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
 
443
                wprintw(dummy_pad, "INFO: ");
 
444
                break;
 
445
 
 
446
            case IPMI_LOG_WARNING:
 
447
                wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
 
448
                wprintw(dummy_pad, "WARN: ");
 
449
                break;
 
450
 
 
451
            case IPMI_LOG_SEVERE:
 
452
                wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
 
453
                wprintw(dummy_pad, "SEVR: ");
 
454
                break;
 
455
 
 
456
            case IPMI_LOG_FATAL:
 
457
                wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
 
458
                wprintw(dummy_pad, "FATL: ");
 
459
                break;
 
460
 
 
461
            case IPMI_LOG_ERR_INFO:
 
462
                wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
 
463
                wprintw(dummy_pad, "EINF: ");
 
464
                break;
 
465
 
 
466
            case IPMI_LOG_DEBUG_START:
 
467
                do_nl = 0;
 
468
                /* FALLTHROUGH */
 
469
            case IPMI_LOG_DEBUG:
 
470
                wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
 
471
                wprintw(dummy_pad, "DEBG: ");
 
472
                break;
 
473
 
 
474
            case IPMI_LOG_DEBUG_CONT:
 
475
                do_nl = 0;
 
476
                /* FALLTHROUGH */
 
477
            case IPMI_LOG_DEBUG_END:
 
478
                break;
 
479
        }
 
480
        vw_printw(dummy_pad, format, ap);
 
481
        if (do_nl)
 
482
            wprintw(dummy_pad, "\n");
 
483
        getyx(dummy_pad, y, x);
 
484
 
 
485
        if (old_y == y) {
 
486
            for (j=old_x; j<x; j++)
 
487
                waddch(log_pad, mvwinch(dummy_pad, y, j));
 
488
        } else {
 
489
            getmaxyx(dummy_pad, max_y, max_x);
 
490
            for (j=old_x; j<max_x; j++)
 
491
                waddch(log_pad, mvwinch(dummy_pad, old_y, j));
 
492
            for (i=old_y+1; i<y; i++) {
 
493
                for (j=0; j<max_x; j++)
 
494
                    waddch(log_pad, mvwinch(dummy_pad, i, j));
 
495
            }
 
496
            for (j=0; j<x; j++)
 
497
                waddch(log_pad, mvwinch(dummy_pad, y, j));
 
498
        }
 
499
        y -= old_y;
 
500
        wmove(dummy_pad, 0, x);
 
501
        log_pad_refresh(y);
 
502
    } else {
 
503
        switch(log_type)
 
504
        {
 
505
            case IPMI_LOG_INFO:
 
506
                log_pad_out("%d.%6.6d: ", now.tv_sec, now.tv_usec);
 
507
                log_pad_out("INFO: ");
 
508
                break;
 
509
 
 
510
            case IPMI_LOG_WARNING:
 
511
                log_pad_out("%d.%6.6d: ", now.tv_sec, now.tv_usec);
 
512
                log_pad_out("WARN: ");
 
513
                break;
 
514
 
 
515
            case IPMI_LOG_SEVERE:
 
516
                log_pad_out("%d.%6.6d: ", now.tv_sec, now.tv_usec);
 
517
                log_pad_out("SEVR: ");
 
518
                break;
 
519
 
 
520
            case IPMI_LOG_FATAL:
 
521
                log_pad_out("%d.%6.6d: ", now.tv_sec, now.tv_usec);
 
522
                log_pad_out("FATL: ");
 
523
                break;
 
524
 
 
525
            case IPMI_LOG_ERR_INFO:
 
526
                log_pad_out("%d.%6.6d: ", now.tv_sec, now.tv_usec);
 
527
                log_pad_out("EINF: ");
 
528
                break;
 
529
 
 
530
            case IPMI_LOG_DEBUG_START:
 
531
                do_nl = 0;
 
532
                /* FALLTHROUGH */
 
533
            case IPMI_LOG_DEBUG:
 
534
                log_pad_out("%d.%6.6d: ", now.tv_sec, now.tv_usec);
 
535
                log_pad_out("DEBG: ");
 
536
                break;
 
537
 
 
538
            case IPMI_LOG_DEBUG_CONT:
 
539
                do_nl = 0;
 
540
                /* FALLTHROUGH */
 
541
            case IPMI_LOG_DEBUG_END:
 
542
                break;
 
543
        }
 
544
 
 
545
        vlog_pad_out(format, ap);
 
546
        if (do_nl)
 
547
            log_pad_out("\n");
 
548
        log_pad_refresh(0);
 
549
    }
 
550
    cmd_win_refresh();
 
551
}
 
552
 
 
553
void
 
554
ui_log(char *format, ...)
 
555
{
 
556
    int y = 0, x;
 
557
    struct timeval now;
 
558
    va_list ap;
 
559
 
 
560
    gettimeofday(&now, NULL);
 
561
 
 
562
    va_start(ap, format);
 
563
 
 
564
    if (full_screen) {
 
565
        /* Generate the output to the dummy pad to see how many lines we
 
566
           will use. */
 
567
        wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
 
568
        vw_printw(dummy_pad, format, ap);
 
569
        getyx(dummy_pad, y, x);
 
570
        wmove(dummy_pad, 0, x);
 
571
        va_end(ap);
 
572
        va_start(ap, format);
 
573
    }
 
574
 
 
575
    log_pad_out("%ld.%6.6ld: ", now.tv_sec, now.tv_usec);
 
576
    vlog_pad_out(format, ap);
 
577
    log_pad_refresh(y);
 
578
    cmd_win_refresh();
 
579
    va_end(ap);
 
580
}
 
581
 
 
582
void
 
583
leave(int rv, char *format, ...)
 
584
{
 
585
    va_list ap;
 
586
 
 
587
    ipmi_shutdown();
 
588
 
 
589
    sel_stop_timer(redisplay_timer);
 
590
    sel_free_timer(redisplay_timer);
 
591
 
 
592
    if (full_screen) {
 
593
        endwin();
 
594
        full_screen = 0;
 
595
    } else {
 
596
        tcsetattr(0, TCSADRAIN, &old_termios);
 
597
        fcntl(0, F_SETFL, old_flags);
 
598
        tcdrain(0);
 
599
    }
 
600
 
 
601
    if (pef_config) {
 
602
        ipmi_pef_free_config(pef_config);
 
603
        pef_config = NULL;
 
604
    }
 
605
    if (pef) {
 
606
        ipmi_pef_destroy(pef, NULL, NULL);
 
607
        pef = NULL;
 
608
    }
 
609
    if (lanparm_config) {
 
610
        ipmi_lan_free_config(lanparm_config);
 
611
        lanparm_config = NULL;
 
612
    }
 
613
    if (lanparm) {
 
614
        ipmi_lanparm_destroy(lanparm, NULL, NULL);
 
615
        lanparm = NULL;
 
616
    }
 
617
 
 
618
    if (line_buffer) {
 
619
        ipmi_mem_free(line_buffer);
 
620
    }
 
621
    command_free(commands);
 
622
    keypad_free(keymap);
 
623
 
 
624
    sel_free_selector(ui_sel);
 
625
 
 
626
    va_start(ap, format);
 
627
    vfprintf(stderr, format, ap);
 
628
    va_end(ap);
 
629
 
 
630
    ipmi_debug_malloc_cleanup();
 
631
    exit(rv);
 
632
}
 
633
 
 
634
void
 
635
leave_err(int err, char *format, ...)
 
636
{
 
637
    va_list ap;
 
638
 
 
639
    if (full_screen)
 
640
        endwin();
 
641
    else {
 
642
        tcsetattr(0, TCSADRAIN, &old_termios);
 
643
        fcntl(0, F_SETFL, old_flags);
 
644
        tcdrain(0);
 
645
    }
 
646
    sel_free_selector(ui_sel);
 
647
 
 
648
    va_start(ap, format);
 
649
    vfprintf(stderr, format, ap);
 
650
    va_end(ap);
 
651
 
 
652
    if (IPMI_IS_OS_ERR(err)) {
 
653
        fprintf(stderr, ": %s\n", strerror(IPMI_GET_OS_ERR(err)));
 
654
    } else {
 
655
        fprintf(stderr, ": IPMI Error %2.2x\n", IPMI_GET_IPMI_ERR(err));
 
656
    }
 
657
 
 
658
    ipmi_debug_malloc_cleanup();
 
659
    exit(1);
 
660
}
 
661
 
 
662
void
 
663
recalc_windows(void)
 
664
{
 
665
    draw_lines();
 
666
 
 
667
    mvwin(stat_win, STATUS_WIN_TOP, STATUS_WIN_LEFT);
 
668
    wresize(stat_win, STATUS_WIN_LINES, STATUS_WIN_COLS);
 
669
    wrefresh(stat_win);
 
670
    touchwin(stat_win);
 
671
 
 
672
    wresize(display_pad, DISPLAY_WIN_LINES, DISPLAY_WIN_COLS);
 
673
 
 
674
    mvwin(cmd_win, CMD_WIN_TOP, CMD_WIN_LEFT);
 
675
    wresize(cmd_win, CMD_WIN_LINES, CMD_WIN_COLS);
 
676
    wrefresh(cmd_win);
 
677
    touchwin(cmd_win);
 
678
 
 
679
    wresize(log_pad, NUM_LOG_LINES, LOG_WIN_COLS);
 
680
    wresize(dummy_pad, NUM_LOG_LINES, LOG_WIN_COLS);
 
681
 
 
682
    doupdate();
 
683
 
 
684
    log_pad_refresh(0);
 
685
    display_pad_refresh();
 
686
}
 
687
 
 
688
static
 
689
void handle_user_char(int c)
 
690
{
 
691
    int err = keypad_handle_key(keymap, c, NULL);
 
692
    if (err)
 
693
        ui_log("Got error on char 0x%x 0%o %d\n", c, c, c);
 
694
}
 
695
 
 
696
void
 
697
user_input_ready(int fd, void *data)
 
698
{
 
699
    int c;
 
700
 
 
701
    if (full_screen) {
 
702
        c = wgetch(cmd_win);
 
703
        while (c != ERR) {
 
704
            handle_user_char(c);
 
705
            c = wgetch(cmd_win);
 
706
        }
 
707
    } else {
 
708
        char rc;
 
709
        int count;
 
710
 
 
711
        count = read(0, &rc, 1);
 
712
        if (count > 0)
 
713
            handle_user_char(rc);
 
714
    }
 
715
}
 
716
 
 
717
static int
 
718
normal_char(int key, void *cb_data)
 
719
{
 
720
    char out[2];
 
721
 
 
722
    if (line_buffer_pos >= line_buffer_max) {
 
723
        char *new_line = ipmi_mem_alloc(line_buffer_max+10+1);
 
724
        if (!new_line)
 
725
            return ENOMEM;
 
726
        line_buffer_max += 10;
 
727
        if (line_buffer) {
 
728
            memcpy(new_line, line_buffer, line_buffer_pos);
 
729
            ipmi_mem_free(line_buffer);
 
730
        }
 
731
        line_buffer = new_line;
 
732
    }
 
733
    line_buffer[line_buffer_pos] = key;
 
734
    line_buffer_pos++;
 
735
    out[0] = key;
 
736
    out[1] = '\0';
 
737
    cmd_win_out(out);
 
738
    cmd_win_refresh();
 
739
    return 0;
 
740
}
 
741
 
 
742
static int
 
743
end_of_line(int key, void *cb_data)
 
744
{
 
745
    int err;
 
746
 
 
747
    if (!line_buffer)
 
748
        return 0;
 
749
 
 
750
    line_buffer[line_buffer_pos] = '\0';
 
751
    cmd_win_out("\n");
 
752
    err = command_handle(commands, line_buffer, NULL);
 
753
    if (err)
 
754
        cmd_win_out("Invalid command: %s\n> ", line_buffer);
 
755
    else
 
756
        cmd_win_out("> ");
 
757
    line_buffer_pos = 0;
 
758
    cmd_win_refresh();
 
759
    return 0;
 
760
}
 
761
 
 
762
static int
 
763
backspace(int key, void *cb_data)
 
764
{
 
765
    if (line_buffer_pos == 0)
 
766
        return 0;
 
767
 
 
768
    line_buffer_pos--;
 
769
    cmd_win_out("\b \b");
 
770
    cmd_win_refresh();
 
771
    return 0;
 
772
}
 
773
 
 
774
static int
 
775
key_up(int key, void *cb_data)
 
776
{
 
777
    return 0;
 
778
}
 
779
 
 
780
static int
 
781
key_down(int key, void *cb_data)
 
782
{
 
783
    return 0;
 
784
}
 
785
 
 
786
static int
 
787
key_right(int key, void *cb_data)
 
788
{
 
789
    return 0;
 
790
}
 
791
 
 
792
static int
 
793
key_left(int key, void *cb_data)
 
794
{
 
795
    return 0;
 
796
}
 
797
 
 
798
static int
 
799
key_ppage(int key, void *cb_data)
 
800
{
 
801
    if (curr_win == LOG_WIN_SCROLL) {
 
802
        log_pad_top_line -= (LOG_WIN_LINES-1);
 
803
        log_pad_refresh(0);
 
804
    } else if (curr_win == DISPLAY_WIN_SCROLL) {
 
805
        display_pad_top_line -= (DISPLAY_WIN_LINES-1);
 
806
        display_pad_refresh();
 
807
    }
 
808
    return 0;
 
809
}
 
810
 
 
811
static int
 
812
key_npage(int key, void *cb_data)
 
813
{
 
814
    if (curr_win == LOG_WIN_SCROLL) {
 
815
        log_pad_top_line += (LOG_WIN_LINES-1);
 
816
        log_pad_refresh(0);
 
817
    } else if (curr_win == DISPLAY_WIN_SCROLL) {
 
818
        display_pad_top_line += (DISPLAY_WIN_LINES-1);
 
819
        display_pad_refresh();
 
820
    }
 
821
    return 0;
 
822
}
 
823
 
 
824
static int leave_count = 0;
 
825
 
 
826
static void
 
827
final_leave(void *cb_data)
 
828
{
 
829
    leave_count--;
 
830
    if (leave_count == 0)
 
831
        leave(0, "");
 
832
}
 
833
 
 
834
static void
 
835
leave_cmder(ipmi_domain_t *domain, void *cb_data)
 
836
{
 
837
    int rv;
 
838
 
 
839
    rv = ipmi_domain_close(domain, final_leave, NULL);
 
840
    if (!rv)
 
841
        leave_count++;
 
842
}
 
843
 
 
844
static int
 
845
key_leave(int key, void *cb_data)
 
846
{
 
847
    ipmi_domain_iterate_domains(leave_cmder, NULL);
 
848
    if (leave_count == 0)
 
849
        leave(0, "");
 
850
 
 
851
    return 0;
 
852
}
 
853
 
 
854
static int
 
855
key_resize(int key, void *cb_data)
 
856
{
 
857
    recalc_windows();
 
858
    return 0;
 
859
}
 
860
 
 
861
static int
 
862
key_set_display(int key, void *cb_data)
 
863
{
 
864
    curr_win = DISPLAY_WIN_SCROLL;
 
865
    return 0;
 
866
}
 
867
 
 
868
static int
 
869
key_set_log(int key, void *cb_data)
 
870
{
 
871
    curr_win = LOG_WIN_SCROLL;
 
872
    return 0;
 
873
}
 
874
 
 
875
/* Includes 3 3-byte fields (entity id, entity instance, and slave
 
876
   address) and 1 2-byte field (channel) and three periods and the nil
 
877
   char at the end and possible a leading "r" for device-relative. */
 
878
#define MAX_ENTITY_LOC_SIZE 16
 
879
 
 
880
/* Convert an entity to a locator for the entity.  This is either:
 
881
     <num>.<num> for an absolute entity, or
 
882
     r<num>.<num>.<num>.<num> for a device-relative entity. */
 
883
static char *
 
884
get_entity_loc(ipmi_entity_t *entity, char *str, int strlen)
 
885
{
 
886
    ipmi_entity_id_t id;
 
887
 
 
888
    id = ipmi_entity_convert_to_id(entity);
 
889
    if (id.entity_instance >= 0x60)
 
890
        snprintf(str, strlen, "r%d.%d.%d.%d",
 
891
                 id.channel,
 
892
                 id.address,
 
893
                 id.entity_id,
 
894
                 id.entity_instance - 0x60);
 
895
    else
 
896
        snprintf(str, strlen, "%d.%d",
 
897
                 id.entity_id,
 
898
                 id.entity_instance);
 
899
    return str;
 
900
}
 
901
 
 
902
static void
 
903
entities_handler(ipmi_entity_t *entity,
 
904
                 void          *cb_data)
 
905
{
 
906
    char *present;
 
907
    char loc[MAX_ENTITY_LOC_SIZE];
 
908
    char name[33];
 
909
    enum ipmi_dlr_type_e type;
 
910
    static char *ent_types[] = { "unknown", "mc", "fru",
 
911
                                 "generic", "invalid" };
 
912
 
 
913
    type = ipmi_entity_get_type(entity);
 
914
    if (type > IPMI_ENTITY_GENERIC)
 
915
        type = IPMI_ENTITY_GENERIC + 1;
 
916
    curr_entity_id = ipmi_entity_convert_to_id(entity);
 
917
    ipmi_entity_get_id(entity, name, 32);
 
918
    if (strlen(name) == 0)
 
919
        strncpy(name, ipmi_entity_get_entity_id_string(entity), 33);
 
920
    if (ipmi_entity_is_present(entity))
 
921
        present = "present";
 
922
    else
 
923
        present = "not present";
 
924
    display_pad_out("  %s (%s) %s  %s\n",
 
925
                    get_entity_loc(entity, loc, sizeof(loc)),
 
926
                    name,
 
927
                    ent_types[type], present);
 
928
}
 
929
 
 
930
static void
 
931
entities_cmder(ipmi_domain_t *domain, void *cb_data)
 
932
{
 
933
    if (cb_data)
 
934
        display_pad_clear_nomove();
 
935
    else
 
936
        display_pad_clear();
 
937
    display_pad_out("Entities:\n");
 
938
    ipmi_domain_iterate_entities(domain, entities_handler, NULL);
 
939
    display_pad_refresh();
 
940
}
 
941
 
 
942
static int
 
943
entities_cmd(char *cmd, char **toks, void *cb_data)
 
944
{
 
945
    int rv;
 
946
 
 
947
    rv = ipmi_domain_pointer_cb(domain_id, entities_cmder, NULL);
 
948
    if (rv) {
 
949
        cmd_win_out("Unable to convert domain id to a pointer\n");
 
950
        return 0;
 
951
    }
 
952
    curr_display_type = DISPLAY_ENTITIES;
 
953
    return 0;
 
954
}
 
955
 
 
956
typedef void (*entity_handler_cb)(ipmi_entity_t *entity,
 
957
                                  char          **toks,
 
958
                                  char          **toks2,
 
959
                                  void          *cb_data);
 
960
struct ent_rec {
 
961
    int id, instance, found;
 
962
    int channel, address;
 
963
    entity_handler_cb handler;
 
964
    char **toks, **toks2;
 
965
    void *cb_data;
 
966
};
 
967
 
 
968
static void
 
969
entity_searcher(ipmi_entity_t *entity,
 
970
                void          *cb_data)
 
971
{
 
972
    struct ent_rec   *info = cb_data;
 
973
    ipmi_entity_id_t id;
 
974
 
 
975
    id = ipmi_entity_convert_to_id(entity);
 
976
    if ((info->id == id.entity_id)
 
977
        && (info->instance == id.entity_instance)
 
978
        && (info->address == id.address)
 
979
        && (info->channel == id.channel))
 
980
    {
 
981
        info->found = 1;
 
982
        info->handler(entity, info->toks, info->toks2, info->cb_data);
 
983
    }
 
984
}
 
985
 
 
986
static void
 
987
entity_finder_d(ipmi_domain_t *domain, void *cb_data)
 
988
{
 
989
    ipmi_domain_iterate_entities(domain, entity_searcher, cb_data);
 
990
}
 
991
 
 
992
int
 
993
entity_finder(char *cmd, char **toks,
 
994
              entity_handler_cb handler,
 
995
              void *cb_data)
 
996
{
 
997
    struct ent_rec info;
 
998
    char           *ent_name;
 
999
    char           *id_name, *instance_name, *toks2, *estr;
 
1000
    int            rv;
 
1001
 
 
1002
    ent_name = strtok_r(NULL, " \t\n", toks);
 
1003
    if (!ent_name) {
 
1004
        cmd_win_out("No entity given\n");
 
1005
        return EINVAL;
 
1006
    }
 
1007
 
 
1008
    if (ent_name[0] == 'r') {
 
1009
        /* Device-relative address. */
 
1010
        char *name;
 
1011
        name = strtok_r(ent_name+1, ".", &toks2);
 
1012
        info.channel = strtoul(name, &estr, 0);
 
1013
        if (*estr != '\0') {
 
1014
            cmd_win_out("Invalid entity channel given\n");
 
1015
            return EINVAL;
 
1016
        }
 
1017
 
 
1018
        name = strtok_r(NULL, ".", &toks2);
 
1019
        info.address = strtoul(name, &estr, 0);
 
1020
        if (*estr != '\0') {
 
1021
            cmd_win_out("Invalid entity address given\n");
 
1022
            return EINVAL;
 
1023
        }
 
1024
 
 
1025
        id_name = strtok_r(NULL, ".", &toks2);
 
1026
    } else {
 
1027
        info.address = 0;
 
1028
        info.channel = 0;
 
1029
        id_name = strtok_r(ent_name, ".", &toks2);
 
1030
    }
 
1031
    instance_name = strtok_r(NULL, ".", &toks2);
 
1032
    if (!instance_name) {
 
1033
        cmd_win_out("Invalid entity given\n");
 
1034
        return EINVAL;
 
1035
    }
 
1036
    info.id = strtoul(id_name, &estr, 0);
 
1037
    if (*estr != '\0') {
 
1038
        cmd_win_out("Invalid entity id given\n");
 
1039
        return EINVAL;
 
1040
    }
 
1041
    info.instance = strtoul(instance_name, &estr, 0);
 
1042
    if (*estr != '\0') {
 
1043
        cmd_win_out("Invalid entity instance given\n");
 
1044
        return EINVAL;
 
1045
    }
 
1046
    if (ent_name[0] == 'r')
 
1047
        info.instance += 0x60;
 
1048
 
 
1049
    info.found = 0;
 
1050
 
 
1051
    info.handler = handler;
 
1052
    info.cb_data = cb_data;
 
1053
    info.toks = toks;
 
1054
    info.toks2 = &toks2;
 
1055
 
 
1056
    rv = ipmi_domain_pointer_cb(domain_id, entity_finder_d, &info);
 
1057
    if (!info.found) {
 
1058
        if (ent_name[0] == 'r')
 
1059
            cmd_win_out("Entity r%d.%d.%d.%d not found\n",
 
1060
                        info.channel, info.address, info.id,
 
1061
                        info.instance-0x60);
 
1062
        else
 
1063
            cmd_win_out("Entity %d.%d not found\n", info.id, info.instance);
 
1064
 
 
1065
        return EINVAL;
 
1066
    }
 
1067
 
 
1068
    return 0;
 
1069
}
 
1070
 
 
1071
static void
 
1072
entity_iterate_handler(ipmi_entity_t *o,
 
1073
                       ipmi_entity_t *entity,
 
1074
                       void          *cb_data)
 
1075
{
 
1076
    char name[33];
 
1077
    char loc[MAX_ENTITY_LOC_SIZE];
 
1078
 
 
1079
    ipmi_entity_get_id(entity, name, 32);
 
1080
 
 
1081
    display_pad_out("    %s (%s)\n",
 
1082
                    get_entity_loc(entity, loc, sizeof(loc)),
 
1083
                    name);
 
1084
}
 
1085
 
 
1086
static void
 
1087
entity_handler(ipmi_entity_t *entity,
 
1088
               char          **toks,
 
1089
               char          **toks2,
 
1090
               void          *cb_data)
 
1091
{
 
1092
    char *present;
 
1093
    char name[33];
 
1094
    char ename[IPMI_ENTITY_NAME_LEN];
 
1095
    char loc[MAX_ENTITY_LOC_SIZE];
 
1096
    enum ipmi_dlr_type_e type;
 
1097
    static char *ent_types[] = { "unknown", "mc", "fru",
 
1098
                                 "generic", "invalid" };
 
1099
 
 
1100
    display_pad_clear();
 
1101
    type = ipmi_entity_get_type(entity);
 
1102
    if (type > IPMI_ENTITY_GENERIC)
 
1103
        type = IPMI_ENTITY_GENERIC + 1;
 
1104
    curr_entity_id = ipmi_entity_convert_to_id(entity);
 
1105
    ipmi_entity_get_id(entity, name, 32);
 
1106
    if (ipmi_entity_is_present(entity))
 
1107
        present = "present";
 
1108
    else
 
1109
        present = "not present";
 
1110
    display_pad_out("Entity %s (%s)  %s\n", 
 
1111
                    get_entity_loc(entity, loc, sizeof(loc)),
 
1112
                    name,  present);
 
1113
 
 
1114
    ipmi_entity_get_name(entity, ename, sizeof(ename));
 
1115
    display_pad_out("  name = %s\n", ename);
 
1116
 
 
1117
    display_pad_out("  type = %s\n", ent_types[type]);
 
1118
    display_pad_out("  entity id string = %s\n",
 
1119
                    ipmi_entity_get_entity_id_string(entity));
 
1120
    display_pad_out("  is%s fru\n",
 
1121
                    ipmi_entity_get_is_fru(entity) ? "" : " not");
 
1122
    display_pad_out("  present sensor%s always there\n",
 
1123
                    ipmi_entity_get_presence_sensor_always_there(entity)
 
1124
                    ? "" : " not");
 
1125
    if (ipmi_entity_get_is_child(entity)) {
 
1126
        display_pad_out("  Parents:\n");
 
1127
        ipmi_entity_iterate_parents(entity, entity_iterate_handler, NULL);
 
1128
    }
 
1129
    if (ipmi_entity_get_is_parent(entity)) {
 
1130
        display_pad_out("  Children:\n");
 
1131
        ipmi_entity_iterate_children(entity, entity_iterate_handler, NULL);
 
1132
    }
 
1133
 
 
1134
    switch (type) {
 
1135
    case IPMI_ENTITY_MC:
 
1136
        display_pad_out("  channel = 0x%x\n", ipmi_entity_get_channel(entity));
 
1137
        display_pad_out("  lun = 0x%x\n", ipmi_entity_get_lun(entity));
 
1138
        display_pad_out("  oem = 0x%x\n", ipmi_entity_get_oem(entity));
 
1139
        display_pad_out("  slave_address = 0x%x\n",
 
1140
                        ipmi_entity_get_slave_address(entity));
 
1141
        display_pad_out("  ACPI_system_power_notify_required = 0x%x\n",
 
1142
                        ipmi_entity_get_ACPI_system_power_notify_required(entity));
 
1143
        display_pad_out("  ACPI_device_power_notify_required = 0x%x\n",
 
1144
                        ipmi_entity_get_ACPI_device_power_notify_required(entity));
 
1145
        display_pad_out("  controller_logs_init_agent_errors = 0x%x\n",
 
1146
                        ipmi_entity_get_controller_logs_init_agent_errors(entity));
 
1147
        display_pad_out("  log_init_agent_errors_accessing = 0x%x\n",
 
1148
                        ipmi_entity_get_log_init_agent_errors_accessing(entity));
 
1149
        display_pad_out("  global_init = 0x%x\n",
 
1150
                        ipmi_entity_get_global_init(entity));
 
1151
        display_pad_out("  chassis_device = 0x%x\n",
 
1152
                        ipmi_entity_get_chassis_device(entity));
 
1153
        display_pad_out("  bridge = 0x%x\n",
 
1154
                        ipmi_entity_get_bridge(entity));
 
1155
        display_pad_out("  IPMB_event_generator = 0x%x\n",
 
1156
                        ipmi_entity_get_IPMB_event_generator(entity));
 
1157
        display_pad_out("  IPMB_event_receiver = 0x%x\n",
 
1158
                        ipmi_entity_get_IPMB_event_receiver(entity));
 
1159
        display_pad_out("  FRU_inventory_device = 0x%x\n",
 
1160
                        ipmi_entity_get_FRU_inventory_device(entity));
 
1161
        display_pad_out("  SEL_device = 0x%x\n",
 
1162
                        ipmi_entity_get_SEL_device(entity));
 
1163
        display_pad_out("  SDR_repository_device = 0x%x\n",
 
1164
                        ipmi_entity_get_SDR_repository_device(entity));
 
1165
        display_pad_out("  sensor_device = 0x%x\n",
 
1166
                        ipmi_entity_get_sensor_device(entity));
 
1167
        break;
 
1168
 
 
1169
    case IPMI_ENTITY_FRU:
 
1170
        display_pad_out("  channel = 0x%x\n", ipmi_entity_get_channel(entity));
 
1171
        display_pad_out("  lun = 0x%x\n", ipmi_entity_get_lun(entity));
 
1172
        display_pad_out("  oem = 0x%x\n", ipmi_entity_get_oem(entity));
 
1173
        display_pad_out("  access_address = 0x%x\n",
 
1174
                        ipmi_entity_get_access_address(entity));
 
1175
        display_pad_out("  private_bus_id = 0x%x\n",
 
1176
                        ipmi_entity_get_private_bus_id(entity));
 
1177
        display_pad_out("  device_type = 0x%x\n",
 
1178
                        ipmi_entity_get_device_type(entity));
 
1179
        display_pad_out("  device_modifier = 0x%x\n",
 
1180
                        ipmi_entity_get_device_modifier(entity));
 
1181
        display_pad_out("  is_logical_fru = 0x%x\n",
 
1182
                        ipmi_entity_get_is_logical_fru(entity));
 
1183
        display_pad_out("  fru_device_id = 0x%x\n",
 
1184
                        ipmi_entity_get_fru_device_id(entity));
 
1185
        break;
 
1186
 
 
1187
    case IPMI_ENTITY_GENERIC:
 
1188
        display_pad_out("  channel = 0x%x\n", ipmi_entity_get_channel(entity));
 
1189
        display_pad_out("  lun = 0x%x\n", ipmi_entity_get_lun(entity));
 
1190
        display_pad_out("  oem = 0x%x\n", ipmi_entity_get_oem(entity));
 
1191
        display_pad_out("  access_address = 0x%x\n",
 
1192
                        ipmi_entity_get_access_address(entity));
 
1193
        display_pad_out("  private_bus_id = 0x%x\n",
 
1194
                        ipmi_entity_get_private_bus_id(entity));
 
1195
        display_pad_out("  device_type = 0x%x\n",
 
1196
                        ipmi_entity_get_device_type(entity));
 
1197
        display_pad_out("  device_modifier = 0x%x\n",
 
1198
                        ipmi_entity_get_device_modifier(entity));
 
1199
        display_pad_out("  slave_address = 0x%x\n",
 
1200
                        ipmi_entity_get_slave_address(entity));
 
1201
        display_pad_out("  address_span = 0x%x\n",
 
1202
                        ipmi_entity_get_address_span(entity));
 
1203
        break;
 
1204
 
 
1205
    default:
 
1206
        break;
 
1207
    }
 
1208
    display_pad_refresh();
 
1209
}
 
1210
 
 
1211
int
 
1212
entity_cmd(char *cmd, char **toks, void *cb_data)
 
1213
{
 
1214
    entity_finder(cmd, toks, entity_handler, NULL);
 
1215
    curr_display_type = DISPLAY_ENTITY;
 
1216
    return 0;
 
1217
}
 
1218
 
 
1219
 
 
1220
static void
 
1221
hs_get_act_time_cb(ipmi_entity_t  *ent,
 
1222
                   int            err,
 
1223
                   ipmi_timeout_t val,
 
1224
                   void           *cb_data)
 
1225
{
 
1226
    char loc[MAX_ENTITY_LOC_SIZE];
 
1227
 
 
1228
    if (err) {
 
1229
        ui_log("Could not get hot-swap act time: error 0x%x\n", err);
 
1230
        return;
 
1231
    }
 
1232
 
 
1233
    ui_log("Hot-swap activate time for %s is %lld\n",
 
1234
           get_entity_loc(ent, loc, sizeof(loc)), val);
 
1235
}
 
1236
 
 
1237
static void
 
1238
hs_get_act_time_handler(ipmi_entity_t *entity,
 
1239
                        char          **toks,
 
1240
                        char          **toks2,
 
1241
                        void          *cb_data)
 
1242
{
 
1243
    int rv;
 
1244
 
 
1245
    rv = ipmi_entity_get_auto_activate_time(entity, hs_get_act_time_cb, NULL);
 
1246
    if (rv)
 
1247
        cmd_win_out("Could not get auto-activate: error 0x%x\n", rv);
 
1248
}
 
1249
 
 
1250
int
 
1251
hs_get_act_time(char *cmd, char **toks, void *cb_data)
 
1252
{
 
1253
    entity_finder(cmd, toks, hs_get_act_time_handler, NULL);
 
1254
    return 0;
 
1255
}
 
1256
 
 
1257
static void
 
1258
hs_set_act_time_cb(ipmi_entity_t  *ent,
 
1259
                   int            err,
 
1260
                   void           *cb_data)
 
1261
{
 
1262
    if (err)
 
1263
        ui_log("Could not get hot-swap act time: error 0x%x\n", err);
 
1264
    else
 
1265
        ui_log("hot-swap act time set\n");
 
1266
}
 
1267
 
 
1268
static void
 
1269
hs_set_act_time_handler(ipmi_entity_t *entity,
 
1270
                        char          **toks,
 
1271
                        char          **toks2,
 
1272
                        void          *cb_data)
 
1273
{
 
1274
    int          rv;
 
1275
    unsigned int timeout;
 
1276
 
 
1277
    if (get_uint(toks, &timeout, "Hot swap activate time"))
 
1278
        return;
 
1279
 
 
1280
    rv = ipmi_entity_set_auto_activate_time(entity, timeout,
 
1281
                                            hs_set_act_time_cb, NULL);
 
1282
    if (rv)
 
1283
        cmd_win_out("Could not set auto-activate: error 0x%x\n", rv);
 
1284
}
 
1285
 
 
1286
int
 
1287
hs_set_act_time(char *cmd, char **toks, void *cb_data)
 
1288
{
 
1289
    entity_finder(cmd, toks, hs_set_act_time_handler, NULL);
 
1290
    return 0;
 
1291
}
 
1292
 
 
1293
static void
 
1294
hs_get_deact_time_cb(ipmi_entity_t  *ent,
 
1295
                     int            err,
 
1296
                     ipmi_timeout_t val,
 
1297
                     void           *cb_data)
 
1298
{
 
1299
    char loc[MAX_ENTITY_LOC_SIZE];
 
1300
 
 
1301
    if (err) {
 
1302
        ui_log("Could not get hot-swap deact time: error 0x%x\n", err);
 
1303
        return;
 
1304
    }
 
1305
 
 
1306
    ui_log("Hot-swap deactivate time for %s is %lld\n",
 
1307
           get_entity_loc(ent, loc, sizeof(loc)), val);
 
1308
}
 
1309
 
 
1310
static void
 
1311
hs_get_deact_time_handler(ipmi_entity_t *entity,
 
1312
                          char          **toks,
 
1313
                          char          **toks2,
 
1314
                          void          *cb_data)
 
1315
{
 
1316
    int rv;
 
1317
 
 
1318
    rv = ipmi_entity_get_auto_deactivate_time(entity, hs_get_deact_time_cb, NULL);
 
1319
    if (rv)
 
1320
        cmd_win_out("Could not get auto-deactivate: error 0x%x\n", rv);
 
1321
}
 
1322
 
 
1323
int
 
1324
hs_get_deact_time(char *cmd, char **toks, void *cb_data)
 
1325
{
 
1326
    entity_finder(cmd, toks, hs_get_deact_time_handler, NULL);
 
1327
    return 0;
 
1328
}
 
1329
 
 
1330
static void
 
1331
hs_set_deact_time_cb(ipmi_entity_t  *ent,
 
1332
                     int            err,
 
1333
                     void           *cb_data)
 
1334
{
 
1335
    if (err)
 
1336
        ui_log("Could not get hot-swap deact time: error 0x%x\n", err);
 
1337
    else
 
1338
        ui_log("hot-swap deact time set\n");
 
1339
}
 
1340
 
 
1341
static void
 
1342
hs_set_deact_time_handler(ipmi_entity_t *entity,
 
1343
                          char          **toks,
 
1344
                          char          **toks2,
 
1345
                          void          *cb_data)
 
1346
{
 
1347
    int rv;
 
1348
    unsigned int timeout;
 
1349
 
 
1350
    if (get_uint(toks, &timeout, "Hot swap deactivate time"))
 
1351
        return;
 
1352
 
 
1353
    rv = ipmi_entity_set_auto_deactivate_time(entity, timeout,
 
1354
                                              hs_set_deact_time_cb, NULL);
 
1355
    if (rv)
 
1356
        cmd_win_out("Could not set auto-deactivate: error 0x%x\n", rv);
 
1357
}
 
1358
 
 
1359
int
 
1360
hs_set_deact_time(char *cmd, char **toks, void *cb_data)
 
1361
{
 
1362
    entity_finder(cmd, toks, hs_set_deact_time_handler, NULL);
 
1363
    return 0;
 
1364
}
 
1365
 
 
1366
static void
 
1367
hs_activation_request_cb(ipmi_entity_t  *ent,
 
1368
                         int            err,
 
1369
                         void           *cb_data)
 
1370
{
 
1371
    if (err)
 
1372
        ui_log("Could not activate entity: error 0x%x\n", err);
 
1373
    else
 
1374
        ui_log("entity activated\n");
 
1375
}
 
1376
 
 
1377
static void
 
1378
hs_activation_request_handler(ipmi_entity_t *entity,
 
1379
                              char          **toks,
 
1380
                              char          **toks2,
 
1381
                              void          *cb_data)
 
1382
{
 
1383
    int rv;
 
1384
 
 
1385
    rv = ipmi_entity_set_activation_requested(entity,
 
1386
                                              hs_activation_request_cb,
 
1387
                                              NULL);
 
1388
    if (rv)
 
1389
        cmd_win_out("Could not set activation requested: error 0x%x\n", rv);
 
1390
}
 
1391
 
 
1392
static int
 
1393
hs_activation_request(char *cmd, char **toks, void *cb_data)
 
1394
{
 
1395
    entity_finder(cmd, toks, hs_activation_request_handler, NULL);
 
1396
    return 0;
 
1397
}
 
1398
 
 
1399
static void
 
1400
hs_activate_cb(ipmi_entity_t  *ent,
 
1401
               int            err,
 
1402
               void           *cb_data)
 
1403
{
 
1404
    if (err)
 
1405
        ui_log("Could not activate entity: error 0x%x\n", err);
 
1406
    else
 
1407
        ui_log("entity activated\n");
 
1408
}
 
1409
 
 
1410
static void
 
1411
hs_activate_handler(ipmi_entity_t *entity,
 
1412
                    char          **toks,
 
1413
                    char          **toks2,
 
1414
                    void          *cb_data)
 
1415
{
 
1416
    int rv;
 
1417
 
 
1418
    rv = ipmi_entity_activate(entity, hs_activate_cb, NULL);
 
1419
    if (rv)
 
1420
        cmd_win_out("Could not activate entity: error 0x%x\n", rv);
 
1421
}
 
1422
 
 
1423
int
 
1424
hs_activate(char *cmd, char **toks, void *cb_data)
 
1425
{
 
1426
    entity_finder(cmd, toks, hs_activate_handler, NULL);
 
1427
    return 0;
 
1428
}
 
1429
 
 
1430
static void
 
1431
hs_deactivate_cb(ipmi_entity_t  *ent,
 
1432
                 int            err,
 
1433
                 void           *cb_data)
 
1434
{
 
1435
    if (err)
 
1436
        ui_log("Could not deactivate entity: error 0x%x\n", err);
 
1437
    else
 
1438
        ui_log("entity deactivated\n");
 
1439
}
 
1440
 
 
1441
static void
 
1442
hs_deactivate_handler(ipmi_entity_t *entity,
 
1443
                      char          **toks,
 
1444
                      char          **toks2,
 
1445
                      void          *cb_data)
 
1446
{
 
1447
    int rv;
 
1448
 
 
1449
    rv = ipmi_entity_deactivate(entity, hs_deactivate_cb, NULL);
 
1450
    if (rv)
 
1451
        cmd_win_out("Could not deactivate entity: error 0x%x\n", rv);
 
1452
}
 
1453
 
 
1454
int
 
1455
hs_deactivate(char *cmd, char **toks, void *cb_data)
 
1456
{
 
1457
    entity_finder(cmd, toks, hs_deactivate_handler, NULL);
 
1458
    return 0;
 
1459
}
 
1460
 
 
1461
static void
 
1462
hs_state_cb(ipmi_entity_t             *ent,
 
1463
            int                       err,
 
1464
            enum ipmi_hot_swap_states state,
 
1465
            void                      *cb_data)
 
1466
{
 
1467
    if (err)
 
1468
        ui_log("Could not get hot-swap state: error 0x%x\n", err);
 
1469
    else
 
1470
        ui_log("Hot-swap state is %s\n", ipmi_hot_swap_state_name(state));
 
1471
}
 
1472
 
 
1473
static void
 
1474
hs_state_handler(ipmi_entity_t *entity,
 
1475
                 char          **toks,
 
1476
                 char          **toks2,
 
1477
                 void          *cb_data)
 
1478
{
 
1479
    int rv;
 
1480
 
 
1481
    rv = ipmi_entity_get_hot_swap_state(entity, hs_state_cb, NULL);
 
1482
    if (rv)
 
1483
        cmd_win_out("Could not get entity state: error 0x%x\n", rv);
 
1484
}
 
1485
 
 
1486
int
 
1487
hs_state(char *cmd, char **toks, void *cb_data)
 
1488
{
 
1489
    entity_finder(cmd, toks, hs_state_handler, NULL);
 
1490
    return 0;
 
1491
}
 
1492
 
 
1493
static void
 
1494
hs_check_ent(ipmi_entity_t *entity, void *cb_data)
 
1495
{
 
1496
    ipmi_entity_check_hot_swap_state(entity);
 
1497
}
 
1498
 
 
1499
static void
 
1500
hs_check_cmder(ipmi_domain_t *domain, void *cb_data)
 
1501
{
 
1502
    ipmi_domain_iterate_entities(domain, hs_check_ent, NULL);
 
1503
}
 
1504
 
 
1505
int
 
1506
hs_check_cmd(char *cmd, char **toks, void *cb_data)
 
1507
{
 
1508
    int rv;
 
1509
 
 
1510
    rv = ipmi_domain_pointer_cb(domain_id, hs_check_cmder, NULL);
 
1511
    if (rv) {
 
1512
        cmd_win_out("Unable to convert domain id to a pointer\n");
 
1513
        return 0;
 
1514
    }
 
1515
    
 
1516
    return 0;
 
1517
}
 
1518
 
 
1519
 
 
1520
 
 
1521
static void
 
1522
sensors_handler(ipmi_entity_t *entity, ipmi_sensor_t *sensor, void *cb_data)
 
1523
{
 
1524
    char name[33];
 
1525
    char name2[33];
 
1526
    char loc[MAX_ENTITY_LOC_SIZE];
 
1527
 
 
1528
    ipmi_sensor_get_id(sensor, name, 33);
 
1529
    strcpy(name2, name);
 
1530
    conv_from_spaces(name2);
 
1531
    display_pad_out("  %s.%s - %s\n",
 
1532
                    get_entity_loc(entity, loc, sizeof(loc)),
 
1533
                    name2, name);
 
1534
}
 
1535
 
 
1536
static void
 
1537
found_entity_for_sensors(ipmi_entity_t *entity,
 
1538
                         char          **toks,
 
1539
                         char          **toks2,
 
1540
                         void          *cb_data)
 
1541
{
 
1542
    char loc[MAX_ENTITY_LOC_SIZE];
 
1543
 
 
1544
    curr_display_type = DISPLAY_SENSORS;
 
1545
    display_pad_clear();
 
1546
    display_pad_out("Sensors for entity %s:\n",
 
1547
                    get_entity_loc(entity, loc, sizeof(loc)));
 
1548
    ipmi_entity_iterate_sensors(entity, sensors_handler, NULL);
 
1549
    display_pad_refresh();
 
1550
}
 
1551
 
 
1552
int
 
1553
sensors_cmd(char *cmd, char **toks, void *cb_data)
 
1554
{
 
1555
    entity_finder(cmd, toks, found_entity_for_sensors, NULL);
 
1556
    return 0;
 
1557
}
 
1558
 
 
1559
struct sensor_info {
 
1560
    int  found;
 
1561
    char *name;
 
1562
};
 
1563
 
 
1564
/* Has this sensor been displayed yet? */
 
1565
int sensor_displayed;
 
1566
 
 
1567
/* Decrement whenever the sensor is not displayed and data is
 
1568
   recevied, when this hits zero it's time to display. */
 
1569
int sensor_ops_to_read_count;
 
1570
 
 
1571
/* Return value from ipmi_states_get or ipmi_reading_get. */
 
1572
int sensor_read_err;
 
1573
 
 
1574
/* Values from ipmi_reading_get. */
 
1575
enum ipmi_value_present_e sensor_value_present;
 
1576
unsigned int              sensor_raw_val;
 
1577
double                    sensor_val;
 
1578
 
 
1579
/* Values from ipmi_states_get and ipmi_reading_get. */
 
1580
ipmi_states_t *sensor_states;
 
1581
 
 
1582
/* Values from ipmi_sensor_event_enables_get. */
 
1583
int                sensor_event_states_err;
 
1584
ipmi_event_state_t *sensor_event_states;
 
1585
 
 
1586
/* Values from ipmi_thresholds_get */
 
1587
int               sensor_read_thresh_err;
 
1588
ipmi_thresholds_t *sensor_thresholds;
 
1589
 
 
1590
static void
 
1591
display_sensor(ipmi_entity_t *entity, ipmi_sensor_t *sensor)
 
1592
{
 
1593
    char loc[MAX_ENTITY_LOC_SIZE];
 
1594
    char name[33];
 
1595
    char sname[IPMI_SENSOR_NAME_LEN];
 
1596
    int  rv;
 
1597
 
 
1598
    if (sensor_displayed)
 
1599
        return;
 
1600
 
 
1601
    sensor_ops_to_read_count--;
 
1602
    if (sensor_ops_to_read_count > 0)
 
1603
        return;
 
1604
 
 
1605
    sensor_displayed = 1;
 
1606
 
 
1607
    ipmi_sensor_get_name(sensor, sname, sizeof(sname));
 
1608
 
 
1609
    ipmi_sensor_get_id(sensor, name, 33);
 
1610
    display_pad_clear();
 
1611
 
 
1612
    conv_from_spaces(name);
 
1613
    display_pad_out("Sensor %s.%s:\n",
 
1614
                    get_entity_loc(entity, loc, sizeof(loc)),
 
1615
                    name);
 
1616
    if (ipmi_sensor_get_ignore_if_no_entity(sensor))
 
1617
        display_pad_out("  ignore if entity not present\n");
 
1618
    else
 
1619
        display_pad_out("  still there if entity not present\n");
 
1620
    display_pad_out("  name = %s\n", sname);
 
1621
    display_pad_out("  value = ");
 
1622
    getyx(display_pad, value_pos.y, value_pos.x);
 
1623
    if (!ipmi_entity_is_present(entity)
 
1624
        && ipmi_sensor_get_ignore_if_no_entity(sensor))
 
1625
    {
 
1626
        display_pad_out("not present");
 
1627
    } else {
 
1628
        if (sensor_read_err) {
 
1629
            display_pad_out("unreadable");
 
1630
        } else if (ipmi_sensor_get_event_reading_type(sensor)
 
1631
            == IPMI_EVENT_READING_TYPE_THRESHOLD)
 
1632
        {
 
1633
            if (sensor_value_present == IPMI_BOTH_VALUES_PRESENT)
 
1634
                display_pad_out("%f (%2.2x)", sensor_val, sensor_raw_val);
 
1635
            else if (sensor_value_present == IPMI_RAW_VALUE_PRESENT)
 
1636
                display_pad_out("0x%x (RAW)", sensor_raw_val);
 
1637
            else
 
1638
                display_pad_out("unreadable");
 
1639
        } else {
 
1640
            int i;
 
1641
            for (i=0; i<15; i++) {
 
1642
                int val;
 
1643
                val = ipmi_is_state_set(sensor_states, i);
 
1644
                display_pad_out("%d", val != 0);
 
1645
            }    
 
1646
        }
 
1647
    }
 
1648
    display_pad_out("\n  Events = ");
 
1649
    getyx(display_pad, enabled_pos.y, enabled_pos.x);
 
1650
    if (sensor_event_states_err)
 
1651
        display_pad_out("?         ");
 
1652
    else {
 
1653
        int global_enable;
 
1654
        global_enable = ipmi_event_state_get_events_enabled
 
1655
            (sensor_event_states);
 
1656
        if (global_enable)
 
1657
            display_pad_out("enabled");
 
1658
        else
 
1659
            display_pad_out("disabled");
 
1660
    }
 
1661
    display_pad_out("\n  Scanning = ");
 
1662
    getyx(display_pad, scanning_pos.y, scanning_pos.x);
 
1663
    if (sensor_event_states_err)
 
1664
        display_pad_out("?         ");
 
1665
    else {
 
1666
        int scanning_enable;
 
1667
        scanning_enable = ipmi_event_state_get_scanning_enabled
 
1668
            (sensor_event_states);
 
1669
        if (scanning_enable)
 
1670
            display_pad_out("enabled");
 
1671
        else
 
1672
            display_pad_out("disabled");
 
1673
    }
 
1674
    display_pad_out("\n  Hysteresis = ");
 
1675
    switch (ipmi_sensor_get_hysteresis_support(sensor)) {
 
1676
    case IPMI_HYSTERESIS_SUPPORT_NONE: display_pad_out("none"); break;
 
1677
    case IPMI_HYSTERESIS_SUPPORT_READABLE: display_pad_out("readable"); break;
 
1678
    case IPMI_HYSTERESIS_SUPPORT_SETTABLE: display_pad_out("settable"); break;
 
1679
    case IPMI_HYSTERESIS_SUPPORT_FIXED: display_pad_out("fixed"); break;
 
1680
    default: display_pad_out("invalid"); break;
 
1681
    }
 
1682
    display_pad_out("\n");
 
1683
    display_pad_out("  sensor type = %s (0x%2.2x)\n",
 
1684
                    ipmi_sensor_get_sensor_type_string(sensor),
 
1685
                    ipmi_sensor_get_sensor_type(sensor));
 
1686
    display_pad_out("  event/reading type = %s (0x%2.2x)\n",
 
1687
                    ipmi_sensor_get_event_reading_type_string(sensor),
 
1688
                    ipmi_sensor_get_event_reading_type(sensor));
 
1689
 
 
1690
    if (ipmi_sensor_get_event_reading_type(sensor)
 
1691
        == IPMI_EVENT_READING_TYPE_THRESHOLD)
 
1692
    {
 
1693
        enum ipmi_thresh_e t;
 
1694
        double val;
 
1695
 
 
1696
        display_pad_out("  units = %s%s",
 
1697
                        ipmi_sensor_get_base_unit_string(sensor),
 
1698
                        ipmi_sensor_get_rate_unit_string(sensor));
 
1699
        switch(ipmi_sensor_get_modifier_unit_use(sensor)) {
 
1700
        case IPMI_MODIFIER_UNIT_BASE_DIV_MOD:
 
1701
            display_pad_out("/%s",
 
1702
                            ipmi_sensor_get_modifier_unit_string(sensor));
 
1703
            break;
 
1704
                
 
1705
        case IPMI_MODIFIER_UNIT_BASE_MULT_MOD:
 
1706
            display_pad_out("*%s",
 
1707
                            ipmi_sensor_get_modifier_unit_string(sensor));
 
1708
            break;
 
1709
 
 
1710
        case IPMI_MODIFIER_UNIT_NONE:
 
1711
            break;
 
1712
        }
 
1713
        display_pad_out("\n");
 
1714
 
 
1715
        rv = ipmi_sensor_get_nominal_reading(sensor, &val);
 
1716
        if (!rv) display_pad_out("  nominal = %f\n", val);
 
1717
        
 
1718
        rv = ipmi_sensor_get_normal_min(sensor, &val);
 
1719
        if (!rv) display_pad_out("  normal_min = %f\n", val);
 
1720
        
 
1721
        rv = ipmi_sensor_get_normal_max(sensor, &val);
 
1722
        if (!rv) display_pad_out("  normal_max = %f\n", val);
 
1723
        
 
1724
        rv = ipmi_sensor_get_sensor_min(sensor, &val);
 
1725
        if (!rv) display_pad_out("  sensor_min = %f\n", val);
 
1726
        
 
1727
        rv = ipmi_sensor_get_sensor_max(sensor, &val);
 
1728
        if (!rv) display_pad_out("  sensor_max = %f\n", val);
 
1729
        
 
1730
        display_pad_out("Thresholds:\n");
 
1731
        for (t=IPMI_LOWER_NON_CRITICAL; t<=IPMI_UPPER_NON_RECOVERABLE; t++){
 
1732
            int settable, readable;
 
1733
            int i;
 
1734
            int assert_sup[2], deassert_sup[2];
 
1735
            int anything_set = 0;
 
1736
            
 
1737
            ipmi_sensor_threshold_settable(sensor, t, &settable);
 
1738
            anything_set |= settable;
 
1739
            ipmi_sensor_threshold_readable(sensor, t, &readable);
 
1740
            anything_set |= readable;
 
1741
            for (i=0; i<=1; i++) {
 
1742
                ipmi_sensor_threshold_event_supported(
 
1743
                    sensor, t, i, IPMI_ASSERTION, &(assert_sup[i]));
 
1744
                anything_set |= assert_sup[i];
 
1745
                ipmi_sensor_threshold_event_supported(
 
1746
                    sensor, t, i, IPMI_DEASSERTION, &(deassert_sup[i]));
 
1747
                anything_set |= deassert_sup[i];
 
1748
            }
 
1749
            if (anything_set) {
 
1750
                display_pad_out("  %s:", ipmi_get_threshold_string(t));
 
1751
                threshold_positions[t].set = 1;
 
1752
                display_pad_out("\n    available: ");
 
1753
                if (readable) display_pad_out("R");
 
1754
                else display_pad_out(" ");
 
1755
                if (settable) display_pad_out("W");
 
1756
                else display_pad_out(" ");
 
1757
                if (assert_sup[0]) display_pad_out("L^");
 
1758
                else display_pad_out("  ");
 
1759
                if (deassert_sup[0]) display_pad_out("Lv");
 
1760
                else display_pad_out("  ");
 
1761
                if (assert_sup[1]) display_pad_out("H^");
 
1762
                else display_pad_out("  ");
 
1763
                if (deassert_sup[1]) display_pad_out("Hv");
 
1764
                else display_pad_out("  ");
 
1765
                display_pad_out("\n      enabled: ");
 
1766
                getyx(display_pad,
 
1767
                      threshold_positions[t].enabled.y,
 
1768
                      threshold_positions[t].enabled.x);
 
1769
                if (sensor_event_states_err)
 
1770
                    display_pad_out("?         ");
 
1771
                else {
 
1772
                    if (ipmi_is_threshold_event_set(sensor_event_states, t,
 
1773
                                                    IPMI_GOING_LOW,
 
1774
                                                    IPMI_ASSERTION))
 
1775
                        display_pad_out("L^");
 
1776
                    else
 
1777
                        display_pad_out("  ");
 
1778
                    if (ipmi_is_threshold_event_set(sensor_event_states, t,
 
1779
                                                    IPMI_GOING_LOW,
 
1780
                                                    IPMI_DEASSERTION))
 
1781
                        display_pad_out("Lv");
 
1782
                    else
 
1783
                        display_pad_out("  ");
 
1784
                    if (ipmi_is_threshold_event_set(sensor_event_states, t,
 
1785
                                                    IPMI_GOING_HIGH,
 
1786
                                                    IPMI_ASSERTION))
 
1787
                        display_pad_out("H^");
 
1788
                    else
 
1789
                        display_pad_out("  ");
 
1790
                    if (ipmi_is_threshold_event_set(sensor_event_states, t,
 
1791
                                                    IPMI_GOING_HIGH,
 
1792
                                                    IPMI_DEASSERTION))
 
1793
                        display_pad_out("HV");
 
1794
                    else
 
1795
                        display_pad_out("  ");
 
1796
                }
 
1797
                    
 
1798
                display_pad_out("\n        value: ");
 
1799
                getyx(display_pad,
 
1800
                      threshold_positions[t].value.y,
 
1801
                      threshold_positions[t].value.x);
 
1802
                if (sensor_read_thresh_err)
 
1803
                    display_pad_out("?");
 
1804
                else {
 
1805
                    double val;
 
1806
                    rv = ipmi_threshold_get(sensor_thresholds, t, &val);
 
1807
                    if (rv)
 
1808
                        display_pad_out("?", val);
 
1809
                    else
 
1810
                        display_pad_out("%f", val);
 
1811
                }
 
1812
                display_pad_out("\n out of range: ");
 
1813
                getyx(display_pad,
 
1814
                      threshold_positions[t].oor.y,
 
1815
                      threshold_positions[t].oor.x);
 
1816
                if (!sensor_read_err) {
 
1817
                    if (ipmi_is_threshold_out_of_range(sensor_states, t))
 
1818
                        display_pad_out("true ");
 
1819
                    else
 
1820
                        display_pad_out("false");
 
1821
                }
 
1822
                display_pad_out("\n");
 
1823
            } else {
 
1824
                threshold_positions[t].set = 0;
 
1825
            }
 
1826
        }
 
1827
    } else {
 
1828
        int val;
 
1829
        int i;
 
1830
        
 
1831
        /* A discrete sensor. */
 
1832
        display_pad_out("\n  Assertion: ");
 
1833
        display_pad_out("\n    available: ");
 
1834
        for (i=0; i<15; i++) {
 
1835
            ipmi_sensor_discrete_event_supported(sensor,
 
1836
                                                 i,
 
1837
                                                 IPMI_ASSERTION,
 
1838
                                                 &val);
 
1839
            display_pad_out("%d", val != 0);
 
1840
        }
 
1841
        display_pad_out("\n      enabled: ");
 
1842
        getyx(display_pad, discr_assert_enab.y, discr_assert_enab.x);
 
1843
        if (sensor_event_states_err)
 
1844
            display_pad_out("?");
 
1845
        else {
 
1846
            for (i=0; i<15; i++) {
 
1847
                val = ipmi_is_discrete_event_set(sensor_event_states,
 
1848
                                                 i, IPMI_ASSERTION);
 
1849
                display_pad_out("%d", val != 0);
 
1850
            }
 
1851
        }   
 
1852
 
 
1853
        display_pad_out("\n  Deasertion: ");
 
1854
        display_pad_out("\n    available: ");
 
1855
        for (i=0; i<15; i++) {
 
1856
            ipmi_sensor_discrete_event_supported(sensor,
 
1857
                                                 i,
 
1858
                                                 IPMI_DEASSERTION,
 
1859
                                                 &val);
 
1860
            display_pad_out("%d", val != 0);
 
1861
        }
 
1862
        display_pad_out("\n      enabled: ");
 
1863
        getyx(display_pad, discr_deassert_enab.y, discr_deassert_enab.x);
 
1864
        if (sensor_event_states_err)
 
1865
            display_pad_out("?");
 
1866
        else {
 
1867
            for (i=0; i<15; i++) {
 
1868
                val = ipmi_is_discrete_event_set(sensor_event_states,
 
1869
                                                 i, IPMI_DEASSERTION);
 
1870
                display_pad_out("%d", val != 0);
 
1871
            }
 
1872
        }
 
1873
        display_pad_out("\n");
 
1874
    }
 
1875
 
 
1876
    display_pad_refresh();
 
1877
}
 
1878
 
 
1879
static void
 
1880
read_sensor(ipmi_sensor_t             *sensor,
 
1881
            int                       err,
 
1882
            enum ipmi_value_present_e value_present,
 
1883
            unsigned int              raw_val,
 
1884
            double                    val,
 
1885
            ipmi_states_t             *states,
 
1886
            void                      *cb_data)
 
1887
{
 
1888
    ipmi_sensor_id_t   sensor_id;
 
1889
    enum ipmi_thresh_e t;
 
1890
 
 
1891
    if (err) {
 
1892
        if (sensor_displayed) {
 
1893
            wmove(display_pad, value_pos.y, value_pos.x);
 
1894
            display_pad_out("unreadable: %x", err);
 
1895
            display_pad_refresh();
 
1896
        } else {
 
1897
            curr_display_type = DISPLAY_NONE;
 
1898
        }
 
1899
        return;
 
1900
    }
 
1901
 
 
1902
    sensor_id = ipmi_sensor_convert_to_id(sensor);
 
1903
    if (!((curr_display_type == DISPLAY_SENSOR)
 
1904
          && (ipmi_cmp_sensor_id(sensor_id, curr_sensor_id) == 0)))
 
1905
        return;
 
1906
 
 
1907
    if (sensor_displayed) {
 
1908
        wmove(display_pad, value_pos.y, value_pos.x);
 
1909
        if (value_present == IPMI_BOTH_VALUES_PRESENT)
 
1910
            display_pad_out("%f (%2.2x)", val, raw_val);
 
1911
        else if (value_present == IPMI_RAW_VALUE_PRESENT)
 
1912
            display_pad_out("0x%x (RAW)", raw_val);
 
1913
        else
 
1914
            display_pad_out("unreadable");
 
1915
 
 
1916
        for (t=IPMI_LOWER_NON_CRITICAL; t<=IPMI_UPPER_NON_RECOVERABLE; t++) {
 
1917
            if (threshold_positions[t].set) {
 
1918
                wmove(display_pad,
 
1919
                      threshold_positions[t].oor.y,
 
1920
                      threshold_positions[t].oor.x);
 
1921
                if (ipmi_is_threshold_out_of_range(states, t))
 
1922
                    display_pad_out("true ");
 
1923
                else
 
1924
                    display_pad_out("false");
 
1925
            }
 
1926
        }    
 
1927
        display_pad_refresh();
 
1928
    } else {
 
1929
        sensor_read_err = err;
 
1930
        sensor_value_present = value_present;
 
1931
        sensor_raw_val = raw_val;
 
1932
        sensor_val = val;
 
1933
        if (states)
 
1934
            ipmi_copy_states(sensor_states, states);
 
1935
        display_sensor(ipmi_sensor_get_entity(sensor), sensor);
 
1936
    }
 
1937
}
 
1938
 
 
1939
 
 
1940
static void
 
1941
read_thresholds(ipmi_sensor_t     *sensor,
 
1942
                int               err,
 
1943
                ipmi_thresholds_t *th,
 
1944
                void              *cb_data)
 
1945
{
 
1946
    ipmi_sensor_id_t   sensor_id;
 
1947
    enum ipmi_thresh_e t;
 
1948
    double             val;
 
1949
    int                rv;
 
1950
 
 
1951
    sensor_id = ipmi_sensor_convert_to_id(sensor);
 
1952
    if (!((curr_display_type == DISPLAY_SENSOR)
 
1953
          && (ipmi_cmp_sensor_id(sensor_id, curr_sensor_id) == 0)))
 
1954
        return;
 
1955
 
 
1956
    if (sensor_displayed) {
 
1957
        if (err) {
 
1958
            for (t=IPMI_LOWER_NON_CRITICAL; t<=IPMI_UPPER_NON_RECOVERABLE; t++)
 
1959
            {
 
1960
                if (threshold_positions[t].set) {
 
1961
                    wmove(display_pad,
 
1962
                          threshold_positions[t].value.y,
 
1963
                          threshold_positions[t].value.x);
 
1964
                    display_pad_out("?");
 
1965
                }
 
1966
            }    
 
1967
        } else {
 
1968
            for (t=IPMI_LOWER_NON_CRITICAL; t<=IPMI_UPPER_NON_RECOVERABLE; t++) {
 
1969
                if (threshold_positions[t].set) {
 
1970
                    rv = ipmi_threshold_get(th, t, &val);
 
1971
                    wmove(display_pad,
 
1972
                          threshold_positions[t].value.y,
 
1973
                          threshold_positions[t].value.x);
 
1974
                    if (rv)
 
1975
                        display_pad_out("?", val);
 
1976
                    else
 
1977
                        display_pad_out("%f", val);
 
1978
                }
 
1979
            }    
 
1980
        }
 
1981
        display_pad_refresh();
 
1982
    } else {
 
1983
        sensor_read_thresh_err = err;
 
1984
        if (th)
 
1985
            ipmi_copy_thresholds(sensor_thresholds, th);
 
1986
        display_sensor(ipmi_sensor_get_entity(sensor), sensor);
 
1987
    }
 
1988
}
 
1989
 
 
1990
static void
 
1991
read_thresh_event_enables(ipmi_sensor_t      *sensor,
 
1992
                          int                err,
 
1993
                          ipmi_event_state_t *states,
 
1994
                          void               *cb_data)
 
1995
{
 
1996
    ipmi_sensor_id_t   sensor_id;
 
1997
    enum ipmi_thresh_e t;
 
1998
    int                global_enable;
 
1999
    int                scanning_enable;
 
2000
 
 
2001
    sensor_id = ipmi_sensor_convert_to_id(sensor);
 
2002
    if (!((curr_display_type == DISPLAY_SENSOR)
 
2003
          && (ipmi_cmp_sensor_id(sensor_id, curr_sensor_id) == 0)))
 
2004
        return;
 
2005
 
 
2006
    if (sensor_displayed) {
 
2007
        if (err)
 
2008
            return;
 
2009
 
 
2010
        global_enable = ipmi_event_state_get_events_enabled(states);
 
2011
        scanning_enable = ipmi_event_state_get_scanning_enabled(states);
 
2012
        wmove(display_pad, enabled_pos.y, enabled_pos.x);
 
2013
        if (err)
 
2014
            display_pad_out("?         ");
 
2015
        else if (global_enable)
 
2016
            display_pad_out("enabled");
 
2017
        else
 
2018
            display_pad_out("disabled");
 
2019
 
 
2020
        wmove(display_pad, scanning_pos.y, scanning_pos.x);
 
2021
        if (err)
 
2022
            display_pad_out("?         ");
 
2023
        else if (scanning_enable)
 
2024
            display_pad_out("enabled");
 
2025
        else
 
2026
            display_pad_out("disabled");
 
2027
 
 
2028
        if (ipmi_sensor_get_event_support(sensor)
 
2029
            != IPMI_EVENT_SUPPORT_PER_STATE)
 
2030
            goto out;
 
2031
 
 
2032
        for (t=IPMI_LOWER_NON_CRITICAL; t<=IPMI_UPPER_NON_RECOVERABLE; t++) {
 
2033
            if (threshold_positions[t].set) {
 
2034
                wmove(display_pad,
 
2035
                      threshold_positions[t].enabled.y,
 
2036
                      threshold_positions[t].enabled.x);
 
2037
                if (err) {
 
2038
                    display_pad_out("?         ");
 
2039
                    continue;
 
2040
                }
 
2041
                display_pad_out("  ");
 
2042
                if (ipmi_is_threshold_event_set(states, t,
 
2043
                                                IPMI_GOING_LOW,
 
2044
                                                IPMI_ASSERTION))
 
2045
                    display_pad_out("L^");
 
2046
                else
 
2047
                    display_pad_out("  ");
 
2048
                if (ipmi_is_threshold_event_set(states, t,
 
2049
                                                IPMI_GOING_LOW,
 
2050
                                                IPMI_DEASSERTION))
 
2051
                    display_pad_out("Lv");
 
2052
                else
 
2053
                    display_pad_out("  ");
 
2054
                if (ipmi_is_threshold_event_set(states, t,
 
2055
                                                IPMI_GOING_HIGH,
 
2056
                                                IPMI_ASSERTION))
 
2057
                    display_pad_out("H^");
 
2058
                else
 
2059
                    display_pad_out("  ");
 
2060
                if (ipmi_is_threshold_event_set(states, t,
 
2061
                                                IPMI_GOING_HIGH,
 
2062
                                                IPMI_DEASSERTION))
 
2063
                    display_pad_out("HV");
 
2064
                else
 
2065
                    display_pad_out("  ");
 
2066
            }
 
2067
        }    
 
2068
 
 
2069
    out:
 
2070
        display_pad_refresh();
 
2071
    } else {
 
2072
        sensor_event_states_err = err;
 
2073
        if (states)
 
2074
            ipmi_copy_event_state(sensor_event_states, states);
 
2075
        display_sensor(ipmi_sensor_get_entity(sensor), sensor);
 
2076
    }
 
2077
}
 
2078
 
 
2079
static void
 
2080
read_discrete_event_enables(ipmi_sensor_t      *sensor,
 
2081
                            int                err,
 
2082
                            ipmi_event_state_t *states,
 
2083
                            void               *cb_data)
 
2084
{
 
2085
    ipmi_sensor_id_t sensor_id;
 
2086
    int              i;
 
2087
    int              val;
 
2088
    int              global_enable;
 
2089
    int              scanning_enable;
 
2090
 
 
2091
    sensor_id = ipmi_sensor_convert_to_id(sensor);
 
2092
    if (!((curr_display_type == DISPLAY_SENSOR)
 
2093
          && (ipmi_cmp_sensor_id(sensor_id, curr_sensor_id) == 0)))
 
2094
        return;
 
2095
 
 
2096
    if (sensor_displayed) {
 
2097
        global_enable = ipmi_event_state_get_events_enabled(states);
 
2098
        scanning_enable = ipmi_event_state_get_scanning_enabled(states);
 
2099
        
 
2100
        wmove(display_pad, enabled_pos.y, enabled_pos.x);
 
2101
        if (err)
 
2102
            display_pad_out("?         ");
 
2103
        else if (global_enable)
 
2104
            display_pad_out("enabled");
 
2105
        else
 
2106
            display_pad_out("disabled");
 
2107
        
 
2108
        wmove(display_pad, scanning_pos.y, scanning_pos.x);
 
2109
        if (err)
 
2110
            display_pad_out("?         ");
 
2111
        else if (scanning_enable)
 
2112
            display_pad_out("enabled");
 
2113
        else
 
2114
            display_pad_out("disabled");
 
2115
        
 
2116
        if (ipmi_sensor_get_event_support(sensor)
 
2117
            != IPMI_EVENT_SUPPORT_PER_STATE)
 
2118
            goto out;
 
2119
        
 
2120
        if (err) {
 
2121
            wmove(display_pad, discr_assert_enab.y, discr_assert_enab.x);
 
2122
            display_pad_out("?");
 
2123
            wmove(display_pad, discr_deassert_enab.y, discr_deassert_enab.x);
 
2124
            display_pad_out("?");
 
2125
        } else {
 
2126
            wmove(display_pad, discr_assert_enab.y, discr_assert_enab.x);
 
2127
            for (i=0; i<15; i++) {
 
2128
                val = ipmi_is_discrete_event_set(states, i, IPMI_ASSERTION);
 
2129
                display_pad_out("%d", val != 0);
 
2130
            }    
 
2131
            wmove(display_pad, discr_deassert_enab.y, discr_deassert_enab.x);
 
2132
            for (i=0; i<15; i++) {
 
2133
                val = ipmi_is_discrete_event_set(states, i, IPMI_DEASSERTION);
 
2134
                display_pad_out("%d", val != 0);
 
2135
            }    
 
2136
        }
 
2137
    out:
 
2138
        display_pad_refresh();
 
2139
    } else {
 
2140
        sensor_event_states_err = err;
 
2141
        if (states)
 
2142
            ipmi_copy_event_state(sensor_event_states, states);
 
2143
        display_sensor(ipmi_sensor_get_entity(sensor), sensor);
 
2144
    }
 
2145
}
 
2146
 
 
2147
static void
 
2148
read_states(ipmi_sensor_t *sensor,
 
2149
            int           err,
 
2150
            ipmi_states_t *states,
 
2151
            void          *cb_data)
 
2152
{
 
2153
    ipmi_sensor_id_t sensor_id;
 
2154
    int              i;
 
2155
    int              val;
 
2156
 
 
2157
    sensor_id = ipmi_sensor_convert_to_id(sensor);
 
2158
    if (!((curr_display_type == DISPLAY_SENSOR)
 
2159
          && (ipmi_cmp_sensor_id(sensor_id, curr_sensor_id) == 0)))
 
2160
        return;
 
2161
 
 
2162
    if (sensor_displayed) {
 
2163
        wmove(display_pad, value_pos.y, value_pos.x);
 
2164
        if (err) {
 
2165
            display_pad_out("?");
 
2166
        } else {
 
2167
            for (i=0; i<15; i++) {
 
2168
                val = ipmi_is_state_set(states, i);
 
2169
                display_pad_out("%d", val != 0);
 
2170
            }    
 
2171
        }
 
2172
        display_pad_refresh();
 
2173
    } else {
 
2174
        sensor_read_err = err;
 
2175
        if (states)
 
2176
            ipmi_copy_states(sensor_states, states);
 
2177
        display_sensor(ipmi_sensor_get_entity(sensor), sensor);
 
2178
    }
 
2179
}
 
2180
 
 
2181
static void
 
2182
redisplay_sensor(ipmi_sensor_t *sensor, void *cb_data)
 
2183
{
 
2184
    int           rv;
 
2185
    ipmi_entity_t *entity;
 
2186
 
 
2187
    entity = ipmi_sensor_get_entity(sensor);
 
2188
    if (!entity)
 
2189
        return;
 
2190
 
 
2191
    if (!ipmi_entity_is_present(entity)
 
2192
        && ipmi_sensor_get_ignore_if_no_entity(sensor))
 
2193
    {
 
2194
        wmove(display_pad, value_pos.y, value_pos.x);
 
2195
        display_pad_out("not present");
 
2196
        return;
 
2197
    }
 
2198
 
 
2199
    if (ipmi_sensor_get_event_reading_type(sensor)
 
2200
        == IPMI_EVENT_READING_TYPE_THRESHOLD)
 
2201
    {
 
2202
        rv = ipmi_sensor_get_reading(sensor, read_sensor, NULL);
 
2203
        if (rv)
 
2204
            ui_log("redisplay_sensor: Unable to get sensor reading: 0x%x\n",
 
2205
                   rv);
 
2206
 
 
2207
        switch (ipmi_sensor_get_threshold_access(sensor))
 
2208
        {
 
2209
        case IPMI_THRESHOLD_ACCESS_SUPPORT_READABLE:
 
2210
        case IPMI_THRESHOLD_ACCESS_SUPPORT_SETTABLE:
 
2211
            rv = ipmi_sensor_get_thresholds(sensor, read_thresholds, NULL);
 
2212
            if (rv)
 
2213
                ui_log("Unable to get threshold values: 0x%x\n", rv);
 
2214
            break;
 
2215
 
 
2216
        default:
 
2217
            break;
 
2218
        }
 
2219
 
 
2220
        switch (ipmi_sensor_get_event_support(sensor))
 
2221
        {
 
2222
        case IPMI_EVENT_SUPPORT_PER_STATE:
 
2223
        case IPMI_EVENT_SUPPORT_ENTIRE_SENSOR:
 
2224
            rv = ipmi_sensor_get_event_enables(sensor,
 
2225
                                               read_thresh_event_enables,
 
2226
                                               NULL);
 
2227
            if (rv)
 
2228
                ui_log("Unable to get event values: 0x%x\n", rv);
 
2229
            break;
 
2230
 
 
2231
        default:
 
2232
            break;
 
2233
        }
 
2234
    } else {
 
2235
        rv = ipmi_sensor_get_states(sensor, read_states, NULL);
 
2236
        if (rv)
 
2237
            ui_log("Unable to get sensor reading: 0x%x\n", rv);
 
2238
        
 
2239
        switch (ipmi_sensor_get_event_support(sensor))
 
2240
        {
 
2241
        case IPMI_EVENT_SUPPORT_PER_STATE:
 
2242
        case IPMI_EVENT_SUPPORT_ENTIRE_SENSOR:
 
2243
            rv = ipmi_sensor_get_event_enables(sensor,
 
2244
                                               read_discrete_event_enables,
 
2245
                                               NULL);
 
2246
            if (rv)
 
2247
                ui_log("Unable to get event values: 0x%x\n", rv);
 
2248
            break;
 
2249
 
 
2250
        default:
 
2251
            break;
 
2252
        }
 
2253
    }
 
2254
}
 
2255
 
 
2256
static void
 
2257
sensor_handler(ipmi_entity_t *entity, ipmi_sensor_t *sensor, void *cb_data)
 
2258
{
 
2259
    char name[33];
 
2260
    struct sensor_info *sinfo = cb_data;
 
2261
    int rv;
 
2262
    int present = 1;
 
2263
 
 
2264
    ipmi_sensor_get_id(sensor, name, 33);
 
2265
    if (strcmp(name, sinfo->name) == 0) {
 
2266
        sinfo->found = 1;
 
2267
        curr_display_type = DISPLAY_SENSOR;
 
2268
        curr_sensor_id = ipmi_sensor_convert_to_id(sensor);
 
2269
 
 
2270
        sensor_displayed = 0;
 
2271
        sensor_ops_to_read_count = 1;
 
2272
        if (! ipmi_entity_is_present(entity)
 
2273
            && ipmi_sensor_get_ignore_if_no_entity(sensor))
 
2274
        {
 
2275
            present = 0;
 
2276
        }
 
2277
        if (ipmi_sensor_get_event_reading_type(sensor)
 
2278
            == IPMI_EVENT_READING_TYPE_THRESHOLD)
 
2279
        {
 
2280
            if (present) {
 
2281
                sensor_ops_to_read_count++;
 
2282
                rv = ipmi_sensor_get_reading(sensor, read_sensor, NULL);
 
2283
                if (rv)
 
2284
                    ui_log("Unable to get sensor reading: 0x%x\n", rv);
 
2285
 
 
2286
                switch (ipmi_sensor_get_threshold_access(sensor))
 
2287
                {
 
2288
                case IPMI_THRESHOLD_ACCESS_SUPPORT_READABLE:
 
2289
                case IPMI_THRESHOLD_ACCESS_SUPPORT_SETTABLE:
 
2290
                    sensor_ops_to_read_count++;
 
2291
                    rv = ipmi_sensor_get_thresholds(sensor, read_thresholds,
 
2292
                                                    NULL);
 
2293
                    if (rv)
 
2294
                        ui_log("Unable to get threshold values: 0x%x\n", rv);
 
2295
                    break;
 
2296
                    
 
2297
                default:
 
2298
                    break;
 
2299
                }
 
2300
 
 
2301
                switch (ipmi_sensor_get_event_support(sensor))
 
2302
                {
 
2303
                case IPMI_EVENT_SUPPORT_PER_STATE:
 
2304
                case IPMI_EVENT_SUPPORT_ENTIRE_SENSOR:
 
2305
                    sensor_ops_to_read_count++;
 
2306
                    rv = ipmi_sensor_get_event_enables
 
2307
                        (sensor,
 
2308
                         read_thresh_event_enables,
 
2309
                         NULL);
 
2310
                    if (rv)
 
2311
                        ui_log("Unable to get event values: 0x%x\n", rv);
 
2312
                    break;
 
2313
                    
 
2314
                default:
 
2315
                    break;
 
2316
                }
 
2317
            }
 
2318
        } else {
 
2319
            if (present) {
 
2320
                sensor_ops_to_read_count++;
 
2321
                rv = ipmi_sensor_get_states(sensor, read_states, NULL);
 
2322
                if (rv)
 
2323
                    ui_log("Unable to get sensor reading: 0x%x\n", rv);
 
2324
 
 
2325
                switch (ipmi_sensor_get_event_support(sensor))
 
2326
                {
 
2327
                case IPMI_EVENT_SUPPORT_PER_STATE:
 
2328
                case IPMI_EVENT_SUPPORT_ENTIRE_SENSOR:
 
2329
                    sensor_ops_to_read_count++;
 
2330
                    rv = ipmi_sensor_get_event_enables
 
2331
                        (sensor,
 
2332
                         read_discrete_event_enables,
 
2333
                         NULL);
 
2334
                    if (rv)
 
2335
                        ui_log("Unable to get event values: 0x%x\n", rv);
 
2336
                    break;
 
2337
                    
 
2338
                default:
 
2339
                    break;
 
2340
                }
 
2341
            }
 
2342
        }
 
2343
        display_sensor(entity, sensor);
 
2344
 
 
2345
        display_pad_refresh();
 
2346
    }
 
2347
}
 
2348
 
 
2349
static void
 
2350
found_entity_for_sensor(ipmi_entity_t *entity,
 
2351
                        char          **toks,
 
2352
                        char          **toks2,
 
2353
                        void          *cb_data)
 
2354
{
 
2355
    struct sensor_info sinfo;
 
2356
 
 
2357
    sinfo.name = strtok_r(NULL, "", toks2);
 
2358
    if (!sinfo.name) {
 
2359
        cmd_win_out("Invalid sensor given\n");
 
2360
        return;
 
2361
    }
 
2362
    conv_to_spaces(sinfo.name);
 
2363
    sinfo.found = 0;
 
2364
 
 
2365
    ipmi_entity_iterate_sensors(entity, sensor_handler, &sinfo);
 
2366
    if (!sinfo.found) {
 
2367
        char loc[MAX_ENTITY_LOC_SIZE];
 
2368
 
 
2369
        conv_from_spaces(sinfo.name);
 
2370
        cmd_win_out("Sensor %s.%s not found\n",
 
2371
                    get_entity_loc(entity, loc, sizeof(loc)),
 
2372
                    sinfo.name);
 
2373
        return;
 
2374
    }
 
2375
}
 
2376
 
 
2377
int
 
2378
sensor_cmd(char *cmd, char **toks, void *cb_data)
 
2379
{
 
2380
    entity_finder(cmd, toks, found_entity_for_sensor, NULL);
 
2381
    return 0;
 
2382
}
 
2383
 
 
2384
typedef struct events_enable_info_s
 
2385
{
 
2386
    ipmi_event_state_t *states;
 
2387
} events_enable_info_t;
 
2388
 
 
2389
void
 
2390
events_enable_done(ipmi_sensor_t *sensor,
 
2391
                   int           err,
 
2392
                   void          *cb_data)
 
2393
{
 
2394
    if (err)
 
2395
        ui_log("Error setting events enable: 0x%x", err);
 
2396
}
 
2397
 
 
2398
static void
 
2399
events_enable(ipmi_sensor_t *sensor, void *cb_data)
 
2400
{
 
2401
    events_enable_info_t *info = cb_data;
 
2402
    int                  rv;
 
2403
 
 
2404
    rv = ipmi_sensor_set_event_enables(sensor, info->states,
 
2405
                                       events_enable_done, NULL);
 
2406
    if (rv)
 
2407
        ui_log("Error sending events enable: 0x%x", rv);
 
2408
    ipmi_mem_free(info);
 
2409
}
 
2410
 
 
2411
static int
 
2412
events_enable_cmd(char *cmd, char **toks, void *cb_data)
 
2413
{
 
2414
    events_enable_info_t *info;    
 
2415
    unsigned char        enable;
 
2416
    int                  i;
 
2417
    char                 *enptr;
 
2418
    int                  rv;
 
2419
    
 
2420
    info = ipmi_mem_alloc(sizeof(*info));
 
2421
    if (!info) {
 
2422
        cmd_win_out("Out of memory\n");
 
2423
        return 0;
 
2424
    }
 
2425
 
 
2426
    info->states = ipmi_mem_alloc(ipmi_event_state_size());
 
2427
    if (!info->states) {
 
2428
        ipmi_mem_free(info);
 
2429
        cmd_win_out("Out of memory\n");
 
2430
        return 0;
 
2431
    }
 
2432
 
 
2433
    ipmi_event_state_init(info->states);
 
2434
 
 
2435
    if (get_uchar(toks, &enable, "events"))
 
2436
        return 0;
 
2437
    ipmi_event_state_set_events_enabled(info->states, enable);
 
2438
 
 
2439
    if (get_uchar(toks, &enable, "scanning"))
 
2440
        return 0;
 
2441
    ipmi_event_state_set_scanning_enabled(info->states, enable);
 
2442
 
 
2443
    enptr = strtok_r(NULL, " \t\n", toks);
 
2444
    if (!enptr) {
 
2445
        cmd_win_out("No assertion mask given\n");
 
2446
        return 0;
 
2447
    }
 
2448
    for (i=0; enptr[i]!='\0'; i++) {
 
2449
        if (enptr[i] == '1')
 
2450
            ipmi_discrete_event_set(info->states, i, IPMI_ASSERTION);
 
2451
        else if (enptr[i] == '0')
 
2452
            ipmi_discrete_event_clear(info->states, i, IPMI_ASSERTION);
 
2453
        else {
 
2454
            cmd_win_out("Invalid assertion value\n");
 
2455
            return 0;
 
2456
        }
 
2457
    }
 
2458
    
 
2459
    enptr = strtok_r(NULL, " \t\n", toks);
 
2460
    if (!enptr) {
 
2461
        cmd_win_out("No deassertion mask given\n");
 
2462
        return 0;
 
2463
    }
 
2464
    for (i=0; enptr[i]!='\0'; i++) {
 
2465
        if (enptr[i] == '1')
 
2466
            ipmi_discrete_event_set(info->states, i, IPMI_DEASSERTION);
 
2467
        else if (enptr[i] == '0')
 
2468
            ipmi_discrete_event_clear(info->states, i, IPMI_DEASSERTION);
 
2469
        else {
 
2470
            cmd_win_out("Invalid deassertion value\n");
 
2471
            return 0;
 
2472
        }
 
2473
    }
 
2474
    
 
2475
    rv = ipmi_sensor_pointer_cb(curr_sensor_id, events_enable, info);
 
2476
    if (rv) {
 
2477
        cmd_win_out("Unable to get sensor pointer: 0x%x\n", rv);
 
2478
        ipmi_mem_free(info);
 
2479
    }
 
2480
    return 0;
 
2481
}
 
2482
 
 
2483
static void
 
2484
controls_handler(ipmi_entity_t *entity, ipmi_control_t *control, void *cb_data)
 
2485
{
 
2486
    char loc[MAX_ENTITY_LOC_SIZE];
 
2487
    char name[33];
 
2488
    char name2[33];
 
2489
 
 
2490
    ipmi_control_get_id(control, name, 33);
 
2491
    strcpy(name2, name);
 
2492
    conv_from_spaces(name2);
 
2493
    display_pad_out("  %s.%s - %s\n",
 
2494
                    get_entity_loc(entity, loc, sizeof(loc)),
 
2495
                    name2, name);
 
2496
}
 
2497
 
 
2498
static void
 
2499
found_entity_for_controls(ipmi_entity_t *entity,
 
2500
                          char          **toks,
 
2501
                          char          **toks2,
 
2502
                          void          *cb_data)
 
2503
{
 
2504
    char loc[MAX_ENTITY_LOC_SIZE];
 
2505
 
 
2506
    curr_display_type = DISPLAY_CONTROLS;
 
2507
    display_pad_clear();
 
2508
    display_pad_out("Controls for entity %s:\n",
 
2509
                    get_entity_loc(entity, loc, sizeof(loc)));
 
2510
    ipmi_entity_iterate_controls(entity, controls_handler, NULL);
 
2511
    display_pad_refresh();
 
2512
}
 
2513
 
 
2514
static int
 
2515
controls_cmd(char *cmd, char **toks, void *cb_data)
 
2516
{
 
2517
    entity_finder(cmd, toks, found_entity_for_controls, NULL);
 
2518
    return 0;
 
2519
}
 
2520
 
 
2521
int control_displayed;
 
2522
int control_ops_to_read_count;
 
2523
int control_read_err;
 
2524
int *normal_control_vals;
 
2525
ipmi_light_setting_t *light_control_val;
 
2526
int id_control_length;
 
2527
unsigned char *id_control_vals;
 
2528
 
 
2529
static void
 
2530
display_control(ipmi_entity_t *entity, ipmi_control_t *control)
 
2531
{
 
2532
    char loc[MAX_ENTITY_LOC_SIZE];
 
2533
    int  control_type;
 
2534
    char name[33];
 
2535
    char cname[IPMI_CONTROL_NAME_LEN];
 
2536
    int  i;
 
2537
    int  num_vals;
 
2538
 
 
2539
    if (control_displayed)
 
2540
        return;
 
2541
 
 
2542
    control_ops_to_read_count--;
 
2543
    if (control_ops_to_read_count > 0)
 
2544
        return;
 
2545
 
 
2546
    control_displayed = 1;
 
2547
 
 
2548
    ipmi_control_get_id(control, name, 33);
 
2549
    curr_control_id = ipmi_control_convert_to_id(control);
 
2550
 
 
2551
    display_pad_clear();
 
2552
 
 
2553
    conv_from_spaces(name);
 
2554
    display_pad_out("Control %s.%s:\n",
 
2555
                    get_entity_loc(entity, loc, sizeof(loc)),
 
2556
                    name);
 
2557
    if (ipmi_control_get_ignore_if_no_entity(control))
 
2558
        display_pad_out("  ignore if entity not present\n");
 
2559
    else
 
2560
        display_pad_out("  still there if entity not present\n");
 
2561
    ipmi_control_get_name(control, cname, sizeof(cname));
 
2562
    display_pad_out("  name = %s\n", cname);
 
2563
    control_type = ipmi_control_get_type(control);
 
2564
    display_pad_out("  type = %s (%d)\n",
 
2565
                    ipmi_control_get_type_string(control), control_type);
 
2566
    num_vals = ipmi_control_get_num_vals(control);
 
2567
    switch (control_type) {
 
2568
        case IPMI_CONTROL_LIGHT:
 
2569
        case IPMI_CONTROL_RELAY:
 
2570
        case IPMI_CONTROL_ALARM:
 
2571
        case IPMI_CONTROL_RESET:
 
2572
        case IPMI_CONTROL_ONE_SHOT_RESET:
 
2573
        case IPMI_CONTROL_POWER:
 
2574
        case IPMI_CONTROL_FAN_SPEED:
 
2575
        case IPMI_CONTROL_OUTPUT:
 
2576
        case IPMI_CONTROL_ONE_SHOT_OUTPUT:
 
2577
            display_pad_out("  num entities = %d\n", num_vals);
 
2578
            break;
 
2579
 
 
2580
        case IPMI_CONTROL_DISPLAY:
 
2581
        case IPMI_CONTROL_IDENTIFIER:
 
2582
            break;
 
2583
    }
 
2584
    display_pad_out("  value = ");
 
2585
    getyx(display_pad, value_pos.y, value_pos.x);
 
2586
 
 
2587
    if (! ipmi_control_is_readable(control)) {
 
2588
        display_pad_out("not readable");
 
2589
    } else if (control_read_err) {
 
2590
        /* Nothing to do. */
 
2591
    } else {
 
2592
        switch (control_type) {
 
2593
            case IPMI_CONTROL_LIGHT:
 
2594
                if (ipmi_control_light_set_with_setting(control)) {
 
2595
                    if (light_control_val) {
 
2596
                        ipmi_light_setting_t *setting = light_control_val;
 
2597
                        for (i=0; i<num_vals; ) {
 
2598
                            int color, on, off, lc;
 
2599
                            ipmi_light_setting_get_color(setting, i, &color);
 
2600
                            ipmi_light_setting_get_on_time(setting, i, &on);
 
2601
                            ipmi_light_setting_get_off_time(setting, i, &off);
 
2602
                            ipmi_light_setting_in_local_control(setting, i,
 
2603
                                                                &lc);
 
2604
                            wmove(display_pad, value_pos.y+i, value_pos.x);
 
2605
                            display_pad_out("0x%x 0x%x 0x%x %s",
 
2606
                                            color, on, off,
 
2607
                                            lc ? "local cnt": "         ");
 
2608
                            i++;
 
2609
                            if (i < num_vals)
 
2610
                                display_pad_out("\n          ");
 
2611
                        }
 
2612
                        ipmi_free_light_settings(light_control_val);
 
2613
                        light_control_val = NULL;
 
2614
                    } else {
 
2615
                        display_pad_out("error reading values");
 
2616
                    }
 
2617
                    break;
 
2618
                }
 
2619
                /* FALLTHRU */
 
2620
 
 
2621
            case IPMI_CONTROL_RELAY:
 
2622
            case IPMI_CONTROL_ALARM:
 
2623
            case IPMI_CONTROL_RESET:
 
2624
            case IPMI_CONTROL_ONE_SHOT_RESET:
 
2625
            case IPMI_CONTROL_POWER:
 
2626
            case IPMI_CONTROL_FAN_SPEED:
 
2627
            case IPMI_CONTROL_OUTPUT:
 
2628
            case IPMI_CONTROL_ONE_SHOT_OUTPUT:
 
2629
                if (normal_control_vals) {
 
2630
                    for (i=0; i<num_vals; ) {
 
2631
                        display_pad_out("%d (0x%x)", normal_control_vals[i],
 
2632
                                        normal_control_vals[i]);
 
2633
                        i++;
 
2634
                        if (i < num_vals)
 
2635
                            display_pad_out("\n          ");
 
2636
                    }
 
2637
                    ipmi_mem_free(normal_control_vals);
 
2638
                    normal_control_vals = NULL;
 
2639
                } else {
 
2640
                    display_pad_out("error reading values");
 
2641
                }
 
2642
                break;
 
2643
                
 
2644
            case IPMI_CONTROL_DISPLAY:
 
2645
                break;
 
2646
                
 
2647
            case IPMI_CONTROL_IDENTIFIER:
 
2648
                if (id_control_vals) {
 
2649
                    for (i=0; i<id_control_length;) {
 
2650
                        display_pad_out("0x%2.2x\n", id_control_vals[i]);
 
2651
                        i++;
 
2652
                        if (i < num_vals)
 
2653
                            display_pad_out("\n          ");
 
2654
                    }
 
2655
                    ipmi_mem_free(id_control_vals);
 
2656
                    id_control_vals = NULL;
 
2657
                } else {
 
2658
                    display_pad_out("error reading values");
 
2659
                }
 
2660
                break;
 
2661
        }
 
2662
    }
 
2663
    display_pad_out("\n");
 
2664
 
 
2665
    display_pad_refresh();
 
2666
}
 
2667
 
 
2668
static void
 
2669
light_control_val_read(ipmi_control_t       *control,
 
2670
                       int                  err,
 
2671
                       ipmi_light_setting_t *setting,
 
2672
                       void                 *cb_data)
 
2673
{
 
2674
    ipmi_control_id_t control_id;
 
2675
    int               num_vals;
 
2676
    int               i;
 
2677
 
 
2678
    if (control == NULL) {
 
2679
        /* The control went away, stop the operation. */
 
2680
        wmove(display_pad, value_pos.y, value_pos.x);
 
2681
        display_pad_out("invalid");
 
2682
        curr_display_type = DISPLAY_NONE;
 
2683
        return;
 
2684
    }
 
2685
    control_id = ipmi_control_convert_to_id(control);
 
2686
    if (!((curr_display_type == DISPLAY_CONTROL)
 
2687
          && (ipmi_cmp_control_id(control_id, curr_control_id) == 0)))
 
2688
        return;
 
2689
 
 
2690
    num_vals = ipmi_control_get_num_vals(control);
 
2691
 
 
2692
    if (control_displayed) {
 
2693
        if (err) {
 
2694
            wmove(display_pad, value_pos.y, value_pos.x);
 
2695
            display_pad_out("?");
 
2696
        } else {
 
2697
            for (i=0; i<num_vals; i++) {
 
2698
                int color, on, off, lc;
 
2699
                ipmi_light_setting_get_color(setting, i, &color);
 
2700
                ipmi_light_setting_get_on_time(setting, i, &on);
 
2701
                ipmi_light_setting_get_off_time(setting, i, &off);
 
2702
                ipmi_light_setting_in_local_control(setting, i, &lc);
 
2703
                wmove(display_pad, value_pos.y+i, value_pos.x);
 
2704
                display_pad_out("0x%x 0x%x 0x%x %s",
 
2705
                                color, on, off,
 
2706
                                lc ? "local cnt": "         ");
 
2707
            }
 
2708
        }
 
2709
        display_pad_refresh();
 
2710
    } else {
 
2711
        if (light_control_val)
 
2712
            ipmi_free_light_settings(light_control_val);
 
2713
        if (err) {
 
2714
            light_control_val = NULL;
 
2715
        } else {
 
2716
            light_control_val = ipmi_light_settings_dup(setting);
 
2717
        }
 
2718
        display_control(ipmi_control_get_entity(control), control);
 
2719
    }
 
2720
}
 
2721
 
 
2722
static void
 
2723
normal_control_val_read(ipmi_control_t *control,
 
2724
                        int            err,
 
2725
                        int            *val,
 
2726
                        void           *cb_data)
 
2727
{
 
2728
    ipmi_control_id_t control_id;
 
2729
    int               num_vals;
 
2730
    int               i;
 
2731
 
 
2732
    if (control == NULL) {
 
2733
        /* The control went away, stop the operation. */
 
2734
        wmove(display_pad, value_pos.y, value_pos.x);
 
2735
        display_pad_out("invalid");
 
2736
        curr_display_type = DISPLAY_NONE;
 
2737
        return;
 
2738
    }
 
2739
    control_id = ipmi_control_convert_to_id(control);
 
2740
    if (!((curr_display_type == DISPLAY_CONTROL)
 
2741
          && (ipmi_cmp_control_id(control_id, curr_control_id) == 0)))
 
2742
        return;
 
2743
 
 
2744
    num_vals = ipmi_control_get_num_vals(control);
 
2745
 
 
2746
    if (control_displayed) {
 
2747
        if (err) {
 
2748
            wmove(display_pad, value_pos.y, value_pos.x);
 
2749
            display_pad_out("?");
 
2750
        } else {
 
2751
            for (i=0; i<num_vals; i++) {
 
2752
                wmove(display_pad, value_pos.y+i, value_pos.x);
 
2753
                display_pad_out("%d (0x%x)", val[i], val[i]);
 
2754
            }
 
2755
        }
 
2756
        display_pad_refresh();
 
2757
    } else {
 
2758
        if (err) {
 
2759
            if (normal_control_vals)
 
2760
                ipmi_mem_free(normal_control_vals);
 
2761
            normal_control_vals = NULL;
 
2762
        } else {
 
2763
            normal_control_vals = ipmi_mem_alloc(sizeof(int) * num_vals);
 
2764
            if (normal_control_vals) {
 
2765
                memcpy(normal_control_vals, val, sizeof(int) * num_vals);
 
2766
            }
 
2767
        }
 
2768
        display_control(ipmi_control_get_entity(control), control);
 
2769
    }
 
2770
}
 
2771
 
 
2772
static void
 
2773
identifier_control_val_read(ipmi_control_t *control,
 
2774
                            int            err,
 
2775
                            unsigned char  *val,
 
2776
                            int            length,
 
2777
                            void           *cb_data)
 
2778
{
 
2779
    ipmi_control_id_t control_id;
 
2780
    int               i;
 
2781
 
 
2782
    if (control == NULL) {
 
2783
        /* The control went away, stop the operation. */
 
2784
        wmove(display_pad, value_pos.y, value_pos.x);
 
2785
        display_pad_out("invalid");
 
2786
        curr_display_type = DISPLAY_NONE;
 
2787
        return;
 
2788
    }
 
2789
 
 
2790
    control_id = ipmi_control_convert_to_id(control);
 
2791
    if (!((curr_display_type == DISPLAY_CONTROL)
 
2792
          && (ipmi_cmp_control_id(control_id, curr_control_id) == 0)))
 
2793
        return;
 
2794
 
 
2795
    if (control_displayed) {
 
2796
        if (err) {
 
2797
            wmove(display_pad, value_pos.y, value_pos.x);
 
2798
            display_pad_out("?");
 
2799
        } else {
 
2800
            wmove(display_pad, value_pos.y, value_pos.x);
 
2801
            for (i=0; i<length; i++) {
 
2802
                display_pad_out("0x%2.2x", val[i]);
 
2803
                if (i < length)
 
2804
                    display_pad_out("\n          ");
 
2805
            }
 
2806
        }
 
2807
        display_pad_refresh();
 
2808
    } else {
 
2809
        if (err) {
 
2810
            if (id_control_vals)
 
2811
                ipmi_mem_free(id_control_vals);
 
2812
            id_control_vals = NULL;
 
2813
        } else {
 
2814
            id_control_length = length;
 
2815
            id_control_vals = ipmi_mem_alloc(sizeof(unsigned char) * length);
 
2816
            if (id_control_vals) {
 
2817
                memcpy(id_control_vals, val, sizeof(unsigned char) * length);
 
2818
            }
 
2819
            display_control(ipmi_control_get_entity(control), control);
 
2820
        }
 
2821
    }
 
2822
}
 
2823
 
 
2824
static void
 
2825
redisplay_control(ipmi_control_t *control, void *cb_data)
 
2826
{
 
2827
    int           control_type;
 
2828
    ipmi_entity_t *entity;
 
2829
 
 
2830
    entity = ipmi_control_get_entity(control);
 
2831
    if (!entity)
 
2832
        return;
 
2833
 
 
2834
    if (! ipmi_control_is_readable(control)) {
 
2835
        wmove(display_pad, value_pos.y, value_pos.x);
 
2836
        display_pad_out("not readable");
 
2837
        display_pad_refresh();
 
2838
        return;
 
2839
    }
 
2840
 
 
2841
    if (!ipmi_entity_is_present(entity)
 
2842
        && ipmi_control_get_ignore_if_no_entity(control))
 
2843
    {
 
2844
        wmove(display_pad, value_pos.y, value_pos.x);
 
2845
        display_pad_out("not present");
 
2846
        display_pad_refresh();
 
2847
        return;
 
2848
    }
 
2849
 
 
2850
    control_type = ipmi_control_get_type(control);
 
2851
    switch (control_type) {
 
2852
    case IPMI_CONTROL_LIGHT:
 
2853
        if (ipmi_control_light_set_with_setting(control)) {
 
2854
            ipmi_control_get_light(control, light_control_val_read, NULL);
 
2855
            break;
 
2856
        }
 
2857
        /* FALLTHRU */
 
2858
    case IPMI_CONTROL_RELAY:
 
2859
    case IPMI_CONTROL_ALARM:
 
2860
    case IPMI_CONTROL_RESET:
 
2861
    case IPMI_CONTROL_ONE_SHOT_RESET:
 
2862
    case IPMI_CONTROL_POWER:
 
2863
    case IPMI_CONTROL_FAN_SPEED:
 
2864
    case IPMI_CONTROL_OUTPUT:
 
2865
    case IPMI_CONTROL_ONE_SHOT_OUTPUT:
 
2866
        ipmi_control_get_val(control, normal_control_val_read, NULL);
 
2867
        break;
 
2868
 
 
2869
    case IPMI_CONTROL_DISPLAY:
 
2870
        break;
 
2871
 
 
2872
    case IPMI_CONTROL_IDENTIFIER:
 
2873
        ipmi_control_identifier_get_val(control,
 
2874
                                        identifier_control_val_read,
 
2875
                                        NULL);
 
2876
        break;
 
2877
    }
 
2878
}
 
2879
 
 
2880
struct control_info {
 
2881
    int found;
 
2882
    unsigned char *name;
 
2883
};
 
2884
 
 
2885
static void
 
2886
control_handler(ipmi_entity_t *entity, ipmi_control_t *control, void *cb_data)
 
2887
{
 
2888
    struct control_info *iinfo = cb_data;
 
2889
    char                name[33];
 
2890
    int                 control_type;
 
2891
    int                 rv;
 
2892
 
 
2893
 
 
2894
    ipmi_control_get_id(control, name, 33);
 
2895
    if (strcmp(name, iinfo->name) == 0) {
 
2896
        iinfo->found = 1;
 
2897
        curr_display_type = DISPLAY_CONTROL;
 
2898
 
 
2899
        curr_control_id = ipmi_control_convert_to_id(control);
 
2900
 
 
2901
        control_ops_to_read_count = 1;
 
2902
 
 
2903
        control_displayed = 0;
 
2904
 
 
2905
        if (! ipmi_control_is_readable(control)) {
 
2906
            /* If the control can't be read, then just display it now. */
 
2907
            display_control(entity, control);
 
2908
            return;
 
2909
        }
 
2910
 
 
2911
        control_type = ipmi_control_get_type(control);
 
2912
        switch (control_type) {
 
2913
        case IPMI_CONTROL_LIGHT:
 
2914
            if (ipmi_control_light_set_with_setting(control)) {
 
2915
                control_ops_to_read_count++;
 
2916
                rv = ipmi_control_get_light(control, light_control_val_read,
 
2917
                                            NULL);
 
2918
                if (rv) {
 
2919
                    ui_log("Unable to read light control val: 0x%x\n", rv);
 
2920
                }
 
2921
                break;
 
2922
            }
 
2923
            /* FALLTHRU */
 
2924
        case IPMI_CONTROL_RELAY:
 
2925
        case IPMI_CONTROL_ALARM:
 
2926
        case IPMI_CONTROL_RESET:
 
2927
        case IPMI_CONTROL_ONE_SHOT_RESET:
 
2928
        case IPMI_CONTROL_POWER:
 
2929
        case IPMI_CONTROL_FAN_SPEED:
 
2930
        case IPMI_CONTROL_OUTPUT:
 
2931
        case IPMI_CONTROL_ONE_SHOT_OUTPUT:
 
2932
            control_ops_to_read_count++;
 
2933
            rv = ipmi_control_get_val(control, normal_control_val_read, NULL);
 
2934
            if (rv) {
 
2935
                ui_log("Unable to read control val: 0x%x\n", rv);
 
2936
            }
 
2937
            break;
 
2938
 
 
2939
        case IPMI_CONTROL_DISPLAY:
 
2940
            break;
 
2941
 
 
2942
        case IPMI_CONTROL_IDENTIFIER:
 
2943
            control_ops_to_read_count++;
 
2944
            rv = ipmi_control_identifier_get_val(control,
 
2945
                                                 identifier_control_val_read,
 
2946
                                                 NULL);
 
2947
            if (rv) {
 
2948
                ui_log("Unable to read control val: 0x%x\n", rv);
 
2949
            }
 
2950
            break;
 
2951
        }
 
2952
 
 
2953
        display_control(entity, control);
 
2954
    }
 
2955
}
 
2956
 
 
2957
static void
 
2958
found_entity_for_control(ipmi_entity_t *entity,
 
2959
                         char          **toks,
 
2960
                         char          **toks2,
 
2961
                         void          *cb_data)
 
2962
{
 
2963
    struct control_info iinfo;
 
2964
 
 
2965
    iinfo.name = strtok_r(NULL, "", toks2);
 
2966
    if (!iinfo.name) {
 
2967
        cmd_win_out("Invalid control given\n");
 
2968
        return;
 
2969
    }
 
2970
    conv_to_spaces(iinfo.name);
 
2971
    iinfo.found = 0;
 
2972
 
 
2973
    ipmi_entity_iterate_controls(entity, control_handler, &iinfo);
 
2974
    if (!iinfo.found) {
 
2975
        char loc[MAX_ENTITY_LOC_SIZE];
 
2976
 
 
2977
        conv_from_spaces(iinfo.name);
 
2978
        cmd_win_out("Control %s.%s not found\n",
 
2979
                    get_entity_loc(entity, loc, sizeof(loc)),
 
2980
                    iinfo.name);
 
2981
        return;
 
2982
    }
 
2983
}
 
2984
 
 
2985
int
 
2986
control_cmd(char *cmd, char **toks, void *cb_data)
 
2987
{
 
2988
    entity_finder(cmd, toks, found_entity_for_control, NULL);
 
2989
    return 0;
 
2990
}
 
2991
 
 
2992
typedef struct rearm_info_s
 
2993
{
 
2994
    int                global;
 
2995
    ipmi_event_state_t *states;
 
2996
} rearm_info_t;
 
2997
 
 
2998
void
 
2999
rearm_done(ipmi_sensor_t *sensor,
 
3000
           int           err,
 
3001
           void          *cb_data)
 
3002
{
 
3003
    if (err)
 
3004
        ui_log("Error rearming sensor: 0x%x", err);
 
3005
}
 
3006
 
 
3007
static void
 
3008
rearm(ipmi_sensor_t *sensor, void *cb_data)
 
3009
{
 
3010
    rearm_info_t *info = cb_data;
 
3011
    int          rv;
 
3012
 
 
3013
    rv = ipmi_sensor_rearm(sensor, info->global, info->states,
 
3014
                           rearm_done, NULL);
 
3015
    if (rv)
 
3016
        ui_log("Error sending rearm: 0x%x", rv);
 
3017
    if (info->states)
 
3018
        ipmi_mem_free(info->states);
 
3019
    ipmi_mem_free(info);
 
3020
}
 
3021
 
 
3022
static int
 
3023
rearm_cmd(char *cmd, char **toks, void *cb_data)
 
3024
{
 
3025
    rearm_info_t  *info;    
 
3026
    unsigned char global;
 
3027
    int           i;
 
3028
    char          *enptr;
 
3029
    int           rv;
 
3030
    
 
3031
    info = ipmi_mem_alloc(sizeof(*info));
 
3032
    if (!info) {
 
3033
        cmd_win_out("Out of memory\n");
 
3034
        return 0;
 
3035
    }
 
3036
 
 
3037
    info->states = NULL;
 
3038
 
 
3039
    if (get_uchar(toks, &global, "global rearm"))
 
3040
        goto out_err;
 
3041
    info->global = global;
 
3042
 
 
3043
    if (!global) {
 
3044
        info->states = ipmi_mem_alloc(ipmi_event_state_size());
 
3045
        if (!info->states) {
 
3046
            ipmi_mem_free(info);
 
3047
            cmd_win_out("Out of memory\n");
 
3048
            goto out_err;
 
3049
        }
 
3050
 
 
3051
        ipmi_event_state_init(info->states);
 
3052
 
 
3053
        enptr = strtok_r(NULL, " \t\n", toks);
 
3054
        if (!enptr) {
 
3055
            cmd_win_out("No assertion mask given\n");
 
3056
            goto out_err;
 
3057
        }
 
3058
        for (i=0; enptr[i]!='\0'; i++) {
 
3059
            if (enptr[i] == '1')
 
3060
                ipmi_discrete_event_set(info->states, i, IPMI_ASSERTION);
 
3061
            else if (enptr[i] == '0')
 
3062
                ipmi_discrete_event_clear(info->states, i, IPMI_ASSERTION);
 
3063
            else {
 
3064
                cmd_win_out("Invalid assertion value\n");
 
3065
                goto out_err;
 
3066
            }
 
3067
        }
 
3068
    
 
3069
        enptr = strtok_r(NULL, " \t\n", toks);
 
3070
        if (!enptr) {
 
3071
            cmd_win_out("No deassertion mask given\n");
 
3072
            return 0;
 
3073
        }
 
3074
        for (i=0; enptr[i]!='\0'; i++) {
 
3075
            if (enptr[i] == '1')
 
3076
                ipmi_discrete_event_set(info->states, i, IPMI_DEASSERTION);
 
3077
            else if (enptr[i] == '0')
 
3078
                ipmi_discrete_event_clear(info->states, i, IPMI_DEASSERTION);
 
3079
            else {
 
3080
                cmd_win_out("Invalid deassertion value\n");
 
3081
                goto out_err;
 
3082
            }
 
3083
        }
 
3084
    }
 
3085
    
 
3086
    rv = ipmi_sensor_pointer_cb(curr_sensor_id, rearm, info);
 
3087
    if (rv) {
 
3088
        cmd_win_out("Unable to get sensor pointer: 0x%x\n", rv);
 
3089
        goto out_err;
 
3090
    }
 
3091
    return 0;
 
3092
 
 
3093
 out_err:
 
3094
    if (info) {
 
3095
        if (info->states)
 
3096
            ipmi_mem_free(info->states);
 
3097
        ipmi_mem_free(info);
 
3098
    }
 
3099
    return 0;
 
3100
}
 
3101
 
 
3102
void
 
3103
set_hysteresis_done(ipmi_sensor_t *sensor,
 
3104
                   int           err,
 
3105
                   void          *cb_data)
 
3106
{
 
3107
    if (err)
 
3108
        ui_log("Error setting hysteresis: 0x%x", err);
 
3109
    else
 
3110
        ui_log("Hysteresis set");
 
3111
}
 
3112
 
 
3113
static int
 
3114
set_hysteresis_cmd(char *cmd, char **toks, void *cb_data)
 
3115
{
 
3116
    unsigned char physt, nhyst;
 
3117
    int           rv;
 
3118
    
 
3119
    if (get_uchar(toks, &physt, "positive hysteresis value"))
 
3120
        goto out_err;
 
3121
 
 
3122
    if (get_uchar(toks, &nhyst, "negative hysteresis value"))
 
3123
        goto out_err;
 
3124
 
 
3125
    rv = ipmi_sensor_id_set_hysteresis(curr_sensor_id, physt, nhyst,
 
3126
                                       set_hysteresis_done, NULL);
 
3127
    if (rv) {
 
3128
        cmd_win_out("Unable to set hysteresis: 0x%x\n", rv);
 
3129
        goto out_err;
 
3130
    }
 
3131
 
 
3132
 out_err:
 
3133
    return 0;
 
3134
}
 
3135
 
 
3136
void
 
3137
get_hysteresis_done(ipmi_sensor_t *sensor,
 
3138
                    int           err,
 
3139
                    unsigned int  positive_hysteresis,
 
3140
                    unsigned int  negative_hysteresis,
 
3141
                    void          *cb_data)
 
3142
{
 
3143
    if (err)
 
3144
        ui_log("Error setting hysteresis: 0x%x", err);
 
3145
    else
 
3146
        ui_log("Hysteresis values: positive = 0x%x, negative = 0x%x",
 
3147
               positive_hysteresis, negative_hysteresis);
 
3148
}
 
3149
 
 
3150
static int
 
3151
get_hysteresis_cmd(char *cmd, char **toks, void *cb_data)
 
3152
{
 
3153
    int rv;
 
3154
    
 
3155
    rv = ipmi_sensor_id_get_hysteresis(curr_sensor_id,
 
3156
                                       get_hysteresis_done, NULL);
 
3157
    if (rv) {
 
3158
        cmd_win_out("Unable to get hysteresis: 0x%x\n", rv);
 
3159
        goto out_err;
 
3160
    }
 
3161
 
 
3162
 out_err:
 
3163
    return 0;
 
3164
}
 
3165
 
 
3166
static int
 
3167
dump_fru_str(ipmi_fru_t *fru,
 
3168
             char       *str,
 
3169
             int (*glen)(ipmi_fru_t   *fru,
 
3170
                         unsigned int *length),
 
3171
             int (*gtype)(ipmi_fru_t           *fru,
 
3172
                          enum ipmi_str_type_e *type),
 
3173
             int (*gstr)(ipmi_fru_t   *fru,
 
3174
                         char         *str,
 
3175
                         unsigned int *strlen))
 
3176
{
 
3177
    enum ipmi_str_type_e type;
 
3178
    int rv;
 
3179
    char buf[128];
 
3180
    unsigned int len;
 
3181
 
 
3182
    rv = gtype(fru, &type);
 
3183
    if (rv) {
 
3184
        if (rv != ENOSYS)
 
3185
            display_pad_out("  Error fetching type for %s: %x\n", str, rv);
 
3186
        return rv;
 
3187
    }
 
3188
 
 
3189
    if (type == IPMI_BINARY_STR) {
 
3190
        display_pad_out("  %s is in binary\n", str);
 
3191
        return 0;
 
3192
    } else if (type == IPMI_UNICODE_STR) {
 
3193
        display_pad_out("  %s is in unicode\n", str);
 
3194
        return 0;
 
3195
    } else if (type != IPMI_ASCII_STR) {
 
3196
        display_pad_out("  %s is in unknown format\n", str);
 
3197
        return 0;
 
3198
    }
 
3199
 
 
3200
    len = sizeof(buf);
 
3201
    rv = gstr(fru, buf, &len);
 
3202
    if (rv) {
 
3203
        display_pad_out("  Error fetching string for %s: %x\n", str, rv);
 
3204
        return rv;
 
3205
    }
 
3206
 
 
3207
    display_pad_out("  %s: %s\n", str, buf);
 
3208
    return 0;
 
3209
}
 
3210
 
 
3211
static int
 
3212
dump_fru_custom_str(ipmi_fru_t *fru,
 
3213
                    char       *str,
 
3214
                    int        num,
 
3215
                    int (*glen)(ipmi_fru_t   *fru,
 
3216
                                unsigned int num,
 
3217
                                unsigned int *length),
 
3218
                    int (*gtype)(ipmi_fru_t           *fru,
 
3219
                                 unsigned int         num,
 
3220
                                 enum ipmi_str_type_e *type),
 
3221
                    int (*gstr)(ipmi_fru_t   *fru,
 
3222
                                unsigned int num,
 
3223
                                char         *str,
 
3224
                                unsigned int *strlen))
 
3225
{
 
3226
    enum ipmi_str_type_e type;
 
3227
    int rv;
 
3228
    char buf[128];
 
3229
    unsigned int len;
 
3230
 
 
3231
    rv = gtype(fru, num, &type);
 
3232
    if (rv)
 
3233
        return rv;
 
3234
 
 
3235
    if (type == IPMI_BINARY_STR) {
 
3236
        display_pad_out("  %s custom %d is in binary\n", str, num);
 
3237
        return 0;
 
3238
    } else if (type == IPMI_UNICODE_STR) {
 
3239
        display_pad_out("  %s custom %d is in unicode\n", str, num);
 
3240
        return 0;
 
3241
    } else if (type != IPMI_ASCII_STR) {
 
3242
        display_pad_out("  %s custom %d is in unknown format\n", str, num);
 
3243
        return 0;
 
3244
    }
 
3245
 
 
3246
    len = sizeof(buf);
 
3247
    rv = gstr(fru, num, buf, &len);
 
3248
    if (rv) {
 
3249
        display_pad_out("  Error fetching string for %s custom %d: %x\n",
 
3250
                        str, num, rv);
 
3251
        return rv;
 
3252
    }
 
3253
 
 
3254
    display_pad_out("  %s custom %d: %s\n", str, num, buf);
 
3255
    return 0;
 
3256
}
 
3257
 
 
3258
#define DUMP_FRU_STR(name, str) \
 
3259
dump_fru_str(fru, str, ipmi_fru_get_ ## name ## _len, \
 
3260
             ipmi_fru_get_ ## name ## _type, \
 
3261
             ipmi_fru_get_ ## name)
 
3262
 
 
3263
#define DUMP_FRU_CUSTOM_STR(name, str) \
 
3264
do {                                                                    \
 
3265
    int i, _rv;                                                         \
 
3266
    for (i=0; ; i++) {                                                  \
 
3267
        _rv = dump_fru_custom_str(fru, str, i,                          \
 
3268
                                  ipmi_fru_get_ ## name ## _custom_len, \
 
3269
                                  ipmi_fru_get_ ## name ## _custom_type, \
 
3270
                                  ipmi_fru_get_ ## name ## _custom);    \
 
3271
        if (_rv)                                                        \
 
3272
            break;                                                      \
 
3273
    }                                                                   \
 
3274
} while (0)
 
3275
 
 
3276
static void
 
3277
dump_fru_info(ipmi_fru_t *fru)
 
3278
{
 
3279
    unsigned char ucval;
 
3280
    unsigned int  uival;
 
3281
    time_t        tval;
 
3282
    int           rv;
 
3283
    int           i, num_multi;
 
3284
 
 
3285
    rv = ipmi_fru_get_internal_use_version(fru, &ucval);
 
3286
    if (!rv)
 
3287
        display_pad_out("  internal area version: 0x%2.2x\n", ucval);
 
3288
 
 
3289
    rv = ipmi_fru_get_internal_use_length(fru, &uival);
 
3290
    if (!rv)
 
3291
        display_pad_out("  internal area length: %d\n", uival);
 
3292
 
 
3293
    /* FIXME - dump internal use data. */
 
3294
 
 
3295
    rv = ipmi_fru_get_chassis_info_version(fru, &ucval);
 
3296
    if (!rv)
 
3297
        display_pad_out("  chassis info version: 0x%2.2x\n", ucval);
 
3298
 
 
3299
    rv = ipmi_fru_get_chassis_info_type(fru, &ucval);
 
3300
    if (!rv)
 
3301
        display_pad_out("  chassis info type: 0x%2.2x\n", ucval);
 
3302
 
 
3303
    DUMP_FRU_STR(chassis_info_part_number, "chassis info part number");
 
3304
    DUMP_FRU_STR(chassis_info_serial_number, "chassis info serial number");
 
3305
    DUMP_FRU_CUSTOM_STR(chassis_info, "chassis info");
 
3306
 
 
3307
    rv = ipmi_fru_get_board_info_version(fru, &ucval);
 
3308
    if (!rv)
 
3309
        display_pad_out("  board info version: 0x%2.2x\n", ucval);
 
3310
 
 
3311
    rv = ipmi_fru_get_board_info_lang_code(fru, &ucval);
 
3312
    if (!rv)
 
3313
        display_pad_out("  board info lang code: 0x%2.2x\n", ucval);
 
3314
 
 
3315
    rv = ipmi_fru_get_board_info_mfg_time(fru, &tval);
 
3316
    if (!rv)
 
3317
        display_pad_out("  board info mfg time: %ld\n", (long) tval);
 
3318
 
 
3319
    DUMP_FRU_STR(board_info_board_manufacturer,
 
3320
                 "board info board manufacturer");
 
3321
    DUMP_FRU_STR(board_info_board_product_name,
 
3322
                 "board info board product name");
 
3323
    DUMP_FRU_STR(board_info_board_serial_number,
 
3324
                 "board info board serial number");
 
3325
    DUMP_FRU_STR(board_info_board_part_number,
 
3326
                 "board info board part number");
 
3327
    DUMP_FRU_STR(board_info_fru_file_id, "board info fru file id");
 
3328
    DUMP_FRU_CUSTOM_STR(board_info, "board info");
 
3329
 
 
3330
    rv = ipmi_fru_get_product_info_version(fru, &ucval);
 
3331
    if (!rv)
 
3332
        display_pad_out("  product info version: 0x%2.2x\n", ucval);
 
3333
 
 
3334
    rv = ipmi_fru_get_product_info_lang_code(fru, &ucval);
 
3335
    if (!rv)
 
3336
        display_pad_out("  product info lang code: 0x%2.2x\n", ucval);
 
3337
 
 
3338
    DUMP_FRU_STR(product_info_manufacturer_name,
 
3339
                 "product info manufacturer name");
 
3340
    DUMP_FRU_STR(product_info_product_name, "product info product name");
 
3341
    DUMP_FRU_STR(product_info_product_part_model_number,
 
3342
                 "product info product part model number");
 
3343
    DUMP_FRU_STR(product_info_product_version, "product info product version");
 
3344
    DUMP_FRU_STR(product_info_product_serial_number,
 
3345
                 "product info product serial number");
 
3346
    DUMP_FRU_STR(product_info_asset_tag, "product info asset tag");
 
3347
    DUMP_FRU_STR(product_info_fru_file_id, "product info fru file id");
 
3348
    DUMP_FRU_CUSTOM_STR(product_info, "product info");
 
3349
    num_multi = ipmi_fru_get_num_multi_records(fru);
 
3350
    for (i=0; i<num_multi; i++) {
 
3351
        unsigned char type, ver;
 
3352
        unsigned int  j;
 
3353
        unsigned int  len;
 
3354
        unsigned char *data;
 
3355
 
 
3356
        rv = ipmi_fru_get_multi_record_type(fru, i, &type);
 
3357
        if (rv)
 
3358
            display_pad_out("  multi-record %d, error getting type: %x\n", rv);
 
3359
        rv = ipmi_fru_get_multi_record_format_version(fru, i, &ver);
 
3360
        if (rv)
 
3361
            display_pad_out("  multi-record %d, error getting ver: %x\n", rv);
 
3362
 
 
3363
        display_pad_out("  multi-record %d, type 0x%x, format version 0x%x:",
 
3364
                        i, type, ver);
 
3365
        
 
3366
        rv = ipmi_fru_get_multi_record_data_len(fru, i, &len);
 
3367
        if (rv) {
 
3368
            display_pad_out("\n  multi-record %d, error getting length: %x\n",
 
3369
                            rv);
 
3370
            continue;
 
3371
        }
 
3372
        data = ipmi_mem_alloc(len);
 
3373
        if (!data) {
 
3374
            display_pad_out("\n  multi-record %d, error allocating data\n");
 
3375
            continue;
 
3376
        }
 
3377
        rv = ipmi_fru_get_multi_record_data(fru, i, data, &len);
 
3378
        if (rv) {
 
3379
            display_pad_out("\n  multi-record %d, error getting data: %x\n",
 
3380
                            rv);
 
3381
        } else {
 
3382
            for (j=0; j<len; j++) {
 
3383
                if ((j > 0) && ((j % 16) == 0))
 
3384
                    display_pad_out("\n     ");
 
3385
                display_pad_out(" %2.2x", data[j]);
 
3386
            }
 
3387
            display_pad_out("\n");
 
3388
        }
 
3389
        ipmi_mem_free(data);
 
3390
    }
 
3391
}
 
3392
 
 
3393
static void
 
3394
found_entity_for_fru(ipmi_entity_t *entity,
 
3395
                     char          **toks,
 
3396
                     char          **toks2,
 
3397
                     void          *cb_data)
 
3398
{
 
3399
    char loc[MAX_ENTITY_LOC_SIZE];
 
3400
    ipmi_fru_t *fru = ipmi_entity_get_fru(entity);
 
3401
 
 
3402
    display_pad_clear();
 
3403
 
 
3404
    if (!fru) {
 
3405
        cmd_win_out("No FRU for entity %s\n",
 
3406
                    get_entity_loc(entity, loc, sizeof(loc)));
 
3407
        return;
 
3408
    }
 
3409
 
 
3410
    display_pad_out("FRU for entity %s\n",
 
3411
                    get_entity_loc(entity, loc, sizeof(loc)));
 
3412
 
 
3413
    dump_fru_info(fru);
 
3414
 
 
3415
    display_pad_refresh();
 
3416
}
 
3417
 
 
3418
static int
 
3419
fru_cmd(char *cmd, char **toks, void *cb_data)
 
3420
{
 
3421
    entity_finder(cmd, toks, found_entity_for_fru, NULL);
 
3422
    curr_display_type = DISPLAY_ENTITY;
 
3423
    return 0;
 
3424
}
 
3425
 
 
3426
static void
 
3427
fru_fetched(ipmi_fru_t *fru, int err, void *cb_data)
 
3428
{
 
3429
    display_pad_clear();
 
3430
    if (err)
 
3431
        display_pad_out("Error fetching fru: %x\n", err);
 
3432
    else
 
3433
        dump_fru_info(fru);
 
3434
    display_pad_refresh();
 
3435
    if (err != ECANCELED)
 
3436
        ipmi_fru_destroy(fru, NULL, NULL);
 
3437
}
 
3438
 
 
3439
typedef struct fru_rec_s
 
3440
{
 
3441
    unsigned char is_logical;
 
3442
    unsigned char device_address;
 
3443
    unsigned char device_id;
 
3444
    unsigned char lun;
 
3445
    unsigned char private_bus;
 
3446
    unsigned char channel;
 
3447
} fru_rec_t;
 
3448
 
 
3449
static void
 
3450
dump_fru_cmder(ipmi_domain_t *domain, void *cb_data)
 
3451
{
 
3452
    fru_rec_t *info = cb_data;
 
3453
    int       rv;
 
3454
 
 
3455
    rv = ipmi_fru_alloc(domain,
 
3456
                        info->is_logical,
 
3457
                        info->device_address,
 
3458
                        info->device_id,
 
3459
                        info->lun,
 
3460
                        info->private_bus,
 
3461
                        info->channel,
 
3462
                        fru_fetched,
 
3463
                        NULL,
 
3464
                        NULL);
 
3465
    if (rv)
 
3466
        cmd_win_out("Unable to allocate fru: %x\n", rv);
 
3467
}
 
3468
 
 
3469
static int
 
3470
dump_fru_cmd(char *cmd, char **toks, void *cb_data)
 
3471
{
 
3472
    int rv;
 
3473
    fru_rec_t info;
 
3474
 
 
3475
    if (get_uchar(toks, &info.is_logical, "is_logical"))
 
3476
        return 0;
 
3477
    if (get_uchar(toks, &info.device_address, "device_address"))
 
3478
        return 0;
 
3479
    if (get_uchar(toks, &info.device_id, "device_id"))
 
3480
        return 0;
 
3481
    if (get_uchar(toks, &info.lun, "lun"))
 
3482
        return 0;
 
3483
    if (get_uchar(toks, &info.private_bus, "private_bus"))
 
3484
        return 0;
 
3485
    if (get_uchar(toks, &info.channel, "channel"))
 
3486
        return 0;
 
3487
 
 
3488
    rv = ipmi_domain_pointer_cb(domain_id, dump_fru_cmder, &info);
 
3489
    if (rv)
 
3490
        cmd_win_out("Unable to convert domain id to a pointer\n");
 
3491
    else 
 
3492
        curr_display_type = DISPLAY_ENTITY;
 
3493
 
 
3494
    return 0;
 
3495
}
 
3496
 
 
3497
static char y_or_n(int val)
 
3498
{
 
3499
    if (val)
 
3500
        return 'y';
 
3501
    else
 
3502
        return 'n';
 
3503
}
 
3504
 
 
3505
#define MCCMD_DATA_SIZE 30
 
3506
typedef struct mccmd_info_s
 
3507
{
 
3508
    ipmi_mcid_t   mc_id;
 
3509
    unsigned char lun;
 
3510
    ipmi_msg_t    msg;
 
3511
    int           found;
 
3512
    unsigned char val;
 
3513
} mccmd_info_t;
 
3514
 
 
3515
void mc_handler(ipmi_mc_t *mc, void *cb_data)
 
3516
{
 
3517
    unsigned char vals[4];
 
3518
    mccmd_info_t  *info = cb_data;
 
3519
 
 
3520
    curr_display_type = DISPLAY_MC;
 
3521
    info->found = 1;
 
3522
    display_pad_clear();
 
3523
    display_pad_out("MC (%x %x) - %s\n",
 
3524
                    ipmi_mc_get_channel(mc),
 
3525
                    ipmi_mc_get_address(mc),
 
3526
                    ipmi_mc_is_active(mc) ? "active" : "inactive");
 
3527
    display_pad_out("    provides_device_sdrs: %c\n",
 
3528
                    y_or_n(ipmi_mc_provides_device_sdrs(mc)));
 
3529
    display_pad_out("        device_available: %c\n",
 
3530
                    y_or_n(ipmi_mc_device_available(mc)));
 
3531
    display_pad_out("         chassis_support: %c\n",
 
3532
                    y_or_n(ipmi_mc_chassis_support(mc)));
 
3533
    display_pad_out("          bridge_support: %c\n",
 
3534
                    y_or_n(ipmi_mc_bridge_support(mc)));
 
3535
    display_pad_out("    ipmb_event_generator: %c\n",
 
3536
                    y_or_n(ipmi_mc_ipmb_event_generator_support(mc)));
 
3537
    display_pad_out("     ipmb_event_receiver: %c\n",
 
3538
                    y_or_n(ipmi_mc_ipmb_event_receiver_support(mc)));
 
3539
    display_pad_out("   fru_inventory_support: %c\n",
 
3540
                    y_or_n(ipmi_mc_fru_inventory_support(mc)));
 
3541
    display_pad_out("      sel_device_support: %c\n",
 
3542
                    y_or_n(ipmi_mc_sel_device_support(mc)));
 
3543
    display_pad_out("  sdr_repository_support: %c\n",
 
3544
                    y_or_n(ipmi_mc_sdr_repository_support(mc)));
 
3545
    display_pad_out("   sensor_device_support: %c\n",
 
3546
                    y_or_n(ipmi_mc_sensor_device_support(mc)));
 
3547
    display_pad_out("               device_id: %2.2x\n",
 
3548
                    ipmi_mc_device_id(mc));
 
3549
    display_pad_out("         device_revision: %1.1x\n",
 
3550
                    ipmi_mc_device_revision(mc));
 
3551
    display_pad_out("             fw_revision: %d.%d%d\n",
 
3552
                    ipmi_mc_major_fw_revision(mc),
 
3553
                    ipmi_mc_minor_fw_revision(mc)>>4,
 
3554
                    ipmi_mc_minor_fw_revision(mc)&0xf);
 
3555
    display_pad_out("                 version: %d.%d\n",
 
3556
                    ipmi_mc_major_version(mc),
 
3557
                    ipmi_mc_minor_version(mc));
 
3558
    display_pad_out("         manufacturer_id: %6.6x\n",
 
3559
                    ipmi_mc_manufacturer_id(mc));
 
3560
    display_pad_out("              product_id: %4.4x\n",
 
3561
                    ipmi_mc_product_id(mc));
 
3562
    ipmi_mc_aux_fw_revision(mc, vals);
 
3563
    display_pad_out("         aux_fw_revision: %2.2x %2.2x %2.2x %2.2x\n",
 
3564
                    vals[0], vals[1], vals[2], vals[3]);
 
3565
 
 
3566
    display_pad_out("               SEL count: %d entries, %d slots used\n",
 
3567
                    ipmi_mc_sel_count(mc), ipmi_mc_sel_entries_used(mc));
 
3568
}
 
3569
 
 
3570
int
 
3571
get_mc_id(char **toks, ipmi_mcid_t *mc_id)
 
3572
{
 
3573
    unsigned char val;
 
3574
 
 
3575
    if (get_uchar(toks, &val, "mc channel"))
 
3576
        return 1;
 
3577
    mc_id->channel = val;
 
3578
 
 
3579
    if (get_uchar(toks, &val, "MC num"))
 
3580
        return 1;
 
3581
    mc_id->mc_num = val;
 
3582
 
 
3583
    mc_id->domain_id = domain_id;
 
3584
    return 0;
 
3585
}
 
3586
 
 
3587
int
 
3588
mc_cmd(char *cmd, char **toks, void *cb_data)
 
3589
{
 
3590
    mccmd_info_t  info;
 
3591
    int           rv;
 
3592
 
 
3593
    if (get_mc_id(toks, &info.mc_id))
 
3594
        return 0;
 
3595
 
 
3596
    info.found = 0;
 
3597
    rv = ipmi_mc_pointer_noseq_cb(info.mc_id, mc_handler, &info);
 
3598
    if (rv) {
 
3599
        cmd_win_out("Unable to find MC\n");
 
3600
        return 0;
 
3601
    }
 
3602
    if (!info.found) {
 
3603
        cmd_win_out("Unable to find MC (%d %x)\n",
 
3604
                    info.mc_id.channel, info.mc_id.mc_num);
 
3605
    }
 
3606
    display_pad_refresh();
 
3607
 
 
3608
    return 0;
 
3609
}
 
3610
 
 
3611
void mcs_handler(ipmi_domain_t *domain,
 
3612
                 ipmi_mc_t     *mc,
 
3613
                 void          *cb_data)
 
3614
{
 
3615
    int addr;
 
3616
    int channel;
 
3617
 
 
3618
    addr = ipmi_mc_get_address(mc);
 
3619
    channel = ipmi_mc_get_channel(mc);
 
3620
    display_pad_out("  (%x %x) - %s\n", channel, addr,
 
3621
                    ipmi_mc_is_active(mc) ? "active" : "inactive");
 
3622
}
 
3623
 
 
3624
static void
 
3625
mcs_cmder(ipmi_domain_t *domain, void *cb_data)
 
3626
{
 
3627
    ipmi_domain_iterate_mcs(domain, mcs_handler, NULL);
 
3628
}
 
3629
 
 
3630
int
 
3631
mcs_cmd(char *cmd, char **toks, void *cb_data)
 
3632
{
 
3633
    int rv;
 
3634
 
 
3635
    display_pad_clear();
 
3636
    curr_display_type = DISPLAY_MCS;
 
3637
    display_pad_out("MCs:\n");
 
3638
    rv = ipmi_domain_pointer_cb(domain_id, mcs_cmder, NULL);
 
3639
    if (rv) {
 
3640
        cmd_win_out("Unable to convert domain id to a pointer\n");
 
3641
        return 0;
 
3642
    }
 
3643
    display_pad_refresh();
 
3644
    return 0;
 
3645
}
 
3646
 
 
3647
static void
 
3648
mccmd_rsp_handler(ipmi_mc_t  *src,
 
3649
                  ipmi_msg_t *msg,
 
3650
                  void       *rsp_data)
 
3651
{
 
3652
    unsigned int  i;
 
3653
    unsigned char *data;
 
3654
 
 
3655
    display_pad_clear();
 
3656
    curr_display_type = DISPLAY_RSP;
 
3657
    display_pad_out("Response:\n");
 
3658
    display_pad_out("  NetFN = 0x%2.2x\n", msg->netfn);
 
3659
    display_pad_out("  Command = 0x%2.2x\n", msg->cmd);
 
3660
    display_pad_out("  Completion code = 0x%2.2x\n", msg->data[0]);
 
3661
    display_pad_out("  data =");
 
3662
    data = msg->data + 1;
 
3663
    for (i=0; i+1<msg->data_len; i++) {
 
3664
        if ((i != 0) && ((i % 8) == 0))
 
3665
            display_pad_out("\n        ");
 
3666
        display_pad_out(" %2.2x", data[i]);
 
3667
    }
 
3668
    display_pad_out("\n");
 
3669
    display_pad_refresh();
 
3670
}
 
3671
 
 
3672
void mccmd_handler(ipmi_mc_t *mc,
 
3673
                   void      *cb_data)
 
3674
{
 
3675
    mccmd_info_t *info = cb_data;
 
3676
    int          rv;
 
3677
 
 
3678
    info->found = 1;
 
3679
    rv = ipmi_mc_send_command(mc, info->lun, &(info->msg), mccmd_rsp_handler,
 
3680
                              NULL);
 
3681
    if (rv)
 
3682
        cmd_win_out("Send command failure: %x\n", rv);
 
3683
}
 
3684
 
 
3685
int
 
3686
mccmd_cmd(char *cmd, char **toks, void *cb_data)
 
3687
{
 
3688
    mccmd_info_t  info;
 
3689
    unsigned char data[MCCMD_DATA_SIZE];
 
3690
    unsigned int  data_len;
 
3691
    int           rv;
 
3692
 
 
3693
    
 
3694
    if (get_mc_id(toks, &info.mc_id))
 
3695
        return 0;
 
3696
 
 
3697
    if (get_uchar(toks, &info.lun, "LUN"))
 
3698
        return 0;
 
3699
 
 
3700
    if (get_uchar(toks, &info.msg.netfn, "NetFN"))
 
3701
        return 0;
 
3702
 
 
3703
    if (get_uchar(toks, &info.msg.cmd, "command"))
 
3704
        return 0;
 
3705
 
 
3706
    for (data_len=0; ; data_len++) {
 
3707
        if (get_uchar(toks, data+data_len, NULL))
 
3708
            break;
 
3709
    }
 
3710
 
 
3711
    info.msg.data_len = data_len;
 
3712
    info.msg.data = data;
 
3713
 
 
3714
    info.found = 0;
 
3715
    rv = ipmi_mc_pointer_noseq_cb(info.mc_id, mccmd_handler, &info);
 
3716
    if (rv) {
 
3717
        cmd_win_out("Unable to convert MC id to a pointer\n");
 
3718
        return 0;
 
3719
    }
 
3720
    if (!info.found) {
 
3721
        cmd_win_out("Unable to find MC (%d %x)\n",
 
3722
                    info.mc_id.channel, info.mc_id.mc_num);
 
3723
    }
 
3724
    display_pad_refresh();
 
3725
 
 
3726
    return 0;
 
3727
}
 
3728
 
 
3729
void
 
3730
mc_events_enable_cb(ipmi_mc_t *mc, int err, void *cb_data)
 
3731
{
 
3732
    if (err)
 
3733
        ui_log("Error setting events enable: 0x%x\n", err);
 
3734
    else
 
3735
        ui_log("Events enable set\n");
 
3736
}
 
3737
 
 
3738
void
 
3739
mc_events_enable_handler(ipmi_mc_t *mc,
 
3740
                         void      *cb_data)
 
3741
{
 
3742
    mccmd_info_t *info = cb_data;
 
3743
    int          rv;
 
3744
 
 
3745
    info->found = 1;
 
3746
    rv = ipmi_mc_set_events_enable(mc, info->val, mc_events_enable_cb, NULL);
 
3747
    if (rv)
 
3748
        cmd_win_out("Set events enable failure: %x\n", rv);
 
3749
}
 
3750
 
 
3751
int
 
3752
mc_events_enable_cmd(char *cmd, char **toks, void *cb_data)
 
3753
{
 
3754
    mccmd_info_t  info;
 
3755
    int           rv;
 
3756
 
 
3757
    
 
3758
    if (get_mc_id(toks, &info.mc_id))
 
3759
        return 0;
 
3760
 
 
3761
    if (get_uchar(toks, &info.val, "enabled"))
 
3762
        return 0;
 
3763
 
 
3764
    info.found = 0;
 
3765
    rv = ipmi_mc_pointer_noseq_cb(info.mc_id, mc_events_enable_handler, &info);
 
3766
    if (rv) {
 
3767
        cmd_win_out("Unable to convert MC id to a pointer\n");
 
3768
        return 0;
 
3769
    }
 
3770
    if (!info.found) {
 
3771
        cmd_win_out("Unable to find MC (%d %x)\n",
 
3772
                    info.mc_id.channel, info.mc_id.mc_num);
 
3773
    }
 
3774
    display_pad_refresh();
 
3775
 
 
3776
    return 0;
 
3777
}
 
3778
 
 
3779
void
 
3780
mc_events_enabled_handler(ipmi_mc_t *mc,
 
3781
                          void      *cb_data)
 
3782
{
 
3783
    mccmd_info_t *info = cb_data;
 
3784
 
 
3785
    info->found = 1;
 
3786
    if (ipmi_mc_get_events_enable(mc))
 
3787
        cmd_win_out("Events enabled\n");
 
3788
    else
 
3789
        cmd_win_out("Events not enabled\n");
 
3790
}
 
3791
 
 
3792
int
 
3793
mc_events_enabled_cmd(char *cmd, char **toks, void *cb_data)
 
3794
{
 
3795
    mccmd_info_t  info;
 
3796
    int           rv;
 
3797
 
 
3798
    
 
3799
    if (get_mc_id(toks, &info.mc_id))
 
3800
        return 0;
 
3801
 
 
3802
    info.found = 0;
 
3803
    rv = ipmi_mc_pointer_noseq_cb(info.mc_id, mc_events_enabled_handler, &info);
 
3804
    if (rv) {
 
3805
        cmd_win_out("Unable to convert MC id to a pointer\n");
 
3806
        return 0;
 
3807
    }
 
3808
    if (!info.found) {
 
3809
        cmd_win_out("Unable to find MC (%d %x)\n",
 
3810
                    info.mc_id.channel, info.mc_id.mc_num);
 
3811
    }
 
3812
    display_pad_refresh();
 
3813
 
 
3814
    return 0;
 
3815
}
 
3816
 
 
3817
void
 
3818
display_pef(void)
 
3819
{
 
3820
    if (!pef) {
 
3821
        display_pad_out("No PEF read, use readpef to fetch one\n");
 
3822
        return;
 
3823
    }
 
3824
 
 
3825
    display_pad_out("PEF\n");
 
3826
    display_pad_out(" Version: %d.%d", ipmi_pef_major_version(pef),
 
3827
                    ipmi_pef_minor_version(pef));
 
3828
    display_pad_out(" Supports:");
 
3829
    if (ipmi_pef_supports_diagnostic_interrupt(pef))
 
3830
        display_pad_out(" diagnostic_interrupt");
 
3831
    if (ipmi_pef_supports_oem_action(pef))
 
3832
        display_pad_out(" oem_action");
 
3833
    if (ipmi_pef_supports_power_cycle(pef))
 
3834
        display_pad_out(" power_cycle");
 
3835
    if (ipmi_pef_supports_reset(pef))
 
3836
        display_pad_out(" reset");
 
3837
    if (ipmi_pef_supports_power_down(pef))
 
3838
        display_pad_out(" power_down");
 
3839
    if (ipmi_pef_supports_alert(pef))
 
3840
        display_pad_out(" alert");
 
3841
    display_pad_out("\n");
 
3842
    display_pad_out("  Num event filter table entries: %d\n",
 
3843
                    num_event_filter_table_entries(pef));
 
3844
}
 
3845
 
 
3846
typedef struct pef_table_s
 
3847
{
 
3848
    char *name;
 
3849
    int (*get)(ipmi_pef_config_t *pefc,
 
3850
               unsigned int      sel,
 
3851
               unsigned int      *val);
 
3852
    char *fmt;
 
3853
} pef_table_t;
 
3854
 
 
3855
#define X(n, f) { #n, ipmi_pefconfig_get_##n, f }
 
3856
static pef_table_t eft_table[] =
 
3857
{
 
3858
    X(enable_filter, "%d"),
 
3859
    X(filter_type, "%d"),
 
3860
    X(diagnostic_interrupt, "%d"),
 
3861
    X(oem_action, "%d"),
 
3862
    X(power_cycle, "%d"),
 
3863
    X(reset, "%d"),
 
3864
    X(power_down, "%d"),
 
3865
    X(alert, "%d"),
 
3866
    X(alert_policy_number, "%d"),
 
3867
    X(event_severity, "0x%x"),
 
3868
    X(generator_id_addr, "0x%x"),
 
3869
    X(generator_id_channel_lun, "0x%x"),
 
3870
    X(sensor_type, "0x%x"),
 
3871
    X(sensor_number, "0x%x"),
 
3872
    X(event_trigger, "%d"),
 
3873
    X(data1_offset_mask, "0x%x"),
 
3874
    X(data1_mask, "%d"),
 
3875
    X(data1_compare1, "%d"),
 
3876
    X(data1_compare2, "%d"),
 
3877
    X(data2_mask, "%d"),
 
3878
    X(data2_compare1, "%d"),
 
3879
    X(data2_compare2, "%d"),
 
3880
    X(data3_mask, "%d"),
 
3881
    X(data3_compare1, "%d"),
 
3882
    X(data3_compare2, "%d"),
 
3883
    { NULL }
 
3884
};
 
3885
static pef_table_t apt_table[] =
 
3886
{
 
3887
    X(policy_num, "%d"),
 
3888
    X(enabled, "%d"),
 
3889
    X(policy, "%d"),
 
3890
    X(channel, "0x%x"),
 
3891
    X(destination_selector, "%d"),
 
3892
    X(alert_string_event_specific, "%d"),
 
3893
    X(alert_string_selector, "%d"),
 
3894
    { NULL }
 
3895
};
 
3896
static pef_table_t ask_table[] =
 
3897
{
 
3898
    X(event_filter, "%d"),
 
3899
    X(alert_string_set, "%d"),
 
3900
    { NULL }
 
3901
};
 
3902
 
 
3903
void
 
3904
display_pef_config(void)
 
3905
{
 
3906
    int           i, j;
 
3907
    unsigned int  val;
 
3908
    unsigned int  len;
 
3909
    unsigned char data[128];
 
3910
    int           rv;
 
3911
    unsigned int  count;
 
3912
 
 
3913
    if (!pef_config) {
 
3914
        display_pad_out("No PEF config read, use readpef to fetch one\n");
 
3915
        return;
 
3916
    }
 
3917
 
 
3918
    display_pad_out("  alert_startup_delay_enabled: %d\n",
 
3919
                    ipmi_pefconfig_get_alert_startup_delay_enabled(pef_config));
 
3920
    display_pad_out("  startup_delay_enabled: %d\n",
 
3921
                    ipmi_pefconfig_get_startup_delay_enabled(pef_config));
 
3922
    display_pad_out("  event_messages_enabled: %d\n",
 
3923
                    ipmi_pefconfig_get_event_messages_enabled(pef_config));
 
3924
    display_pad_out("  pef_enabled: %d\n",
 
3925
                    ipmi_pefconfig_get_pef_enabled(pef_config));
 
3926
    display_pad_out("  diagnostic_interrupt_enabled: %d\n",
 
3927
                    ipmi_pefconfig_get_diagnostic_interrupt_enabled(pef_config));
 
3928
    display_pad_out("  oem_action_enabled: %d\n",
 
3929
                    ipmi_pefconfig_get_oem_action_enabled(pef_config));
 
3930
    display_pad_out("  power_cycle_enabled: %d\n",
 
3931
                    ipmi_pefconfig_get_power_cycle_enabled(pef_config));
 
3932
    display_pad_out("  reset_enabled: %d\n",
 
3933
                    ipmi_pefconfig_get_reset_enabled(pef_config));
 
3934
    display_pad_out("  power_down_enabled: %d\n",
 
3935
                    ipmi_pefconfig_get_power_down_enabled(pef_config));
 
3936
    display_pad_out("  alert_enabled: %d\n",
 
3937
                    ipmi_pefconfig_get_alert_enabled(pef_config));
 
3938
 
 
3939
    if (ipmi_pefconfig_get_startup_delay(pef_config, &val) == 0)
 
3940
        display_pad_out("  startup_delay: %d\n", val);
 
3941
    if (ipmi_pefconfig_get_alert_startup_delay(pef_config, &val) == 0)
 
3942
        display_pad_out("  alert_startup_delay: %d\n", val);
 
3943
 
 
3944
    len = sizeof(data);
 
3945
    rv = ipmi_pefconfig_get_guid(pef_config, &val, data, &len);
 
3946
    if (!rv) {
 
3947
        display_pad_out("  guid_enabled: %d\n", val);
 
3948
        display_pad_out("  guid:", val);
 
3949
        for (i=0; i<len; i++)
 
3950
            display_pad_out(" %2.2x", data[i]);
 
3951
        display_pad_out("\n");
 
3952
    }
 
3953
 
 
3954
    count = ipmi_pefconfig_get_num_event_filters(pef_config);
 
3955
    display_pad_out("  num_event_filters: %d\n", count);
 
3956
    for (i=0; i<count; i++) {
 
3957
        display_pad_out("  event filter %d:\n", i+1);
 
3958
        for (j=0; eft_table[j].name != NULL; j++) {
 
3959
            rv = eft_table[j].get(pef_config, i, &val);
 
3960
            display_pad_out("    %s: ", eft_table[j].name);
 
3961
            if (rv)
 
3962
                display_pad_out("error %x", rv);
 
3963
            else
 
3964
                display_pad_out(eft_table[j].fmt, val);
 
3965
            display_pad_out("\n");
 
3966
        }
 
3967
    }
 
3968
 
 
3969
    count = ipmi_pefconfig_get_num_alert_policies(pef_config);
 
3970
    display_pad_out("  num_alert_policies: %d\n", count);
 
3971
    for (i=0; i<count; i++) {
 
3972
        display_pad_out("  alert policy %d:\n", i+1);
 
3973
        for (j=0; apt_table[j].name != NULL; j++) {
 
3974
            rv = apt_table[j].get(pef_config, i, &val);
 
3975
            display_pad_out("    %s: ", apt_table[j].name);
 
3976
            if (rv)
 
3977
                display_pad_out("error %x", rv);
 
3978
            else
 
3979
                display_pad_out(apt_table[j].fmt, val);
 
3980
            display_pad_out("\n");
 
3981
        }
 
3982
    }
 
3983
 
 
3984
    count = ipmi_pefconfig_get_num_alert_strings(pef_config);
 
3985
    display_pad_out("  num_alert_strings: %d\n", count);
 
3986
    for (i=0; i<count; i++) {
 
3987
        display_pad_out("  alert string %d:\n", i);
 
3988
        for (j=0; ask_table[j].name != NULL; j++) {
 
3989
            rv = ask_table[j].get(pef_config, i, &val);
 
3990
            display_pad_out("    %s: ", ask_table[j].name);
 
3991
            if (rv)
 
3992
                display_pad_out("error %x", rv);
 
3993
            else
 
3994
                display_pad_out(ask_table[j].fmt, val);
 
3995
            display_pad_out("\n");
 
3996
        }
 
3997
        len = sizeof(data);
 
3998
        rv = ipmi_pefconfig_get_alert_string(pef_config, i, data, &len);
 
3999
        if (rv)
 
4000
            display_pad_out("    alert_string: error %x\n", rv);
 
4001
        else
 
4002
            display_pad_out("    alert_string: '%s'\n", data);
 
4003
    }
 
4004
}
 
4005
 
 
4006
void
 
4007
readpef_getconf_handler(ipmi_pef_t        *pef,
 
4008
                        int               err,
 
4009
                        ipmi_pef_config_t *config,
 
4010
                        void              *cb_data)
 
4011
{
 
4012
    if (err) {
 
4013
        ui_log("Error reading PEF config: %x\n", err);
 
4014
        return;
 
4015
    }
 
4016
 
 
4017
    pef_config = config;
 
4018
    display_pef_config();
 
4019
    display_pad_refresh();
 
4020
}
 
4021
 
 
4022
void
 
4023
readpef_alloc_handler(ipmi_pef_t *lpef,
 
4024
                      int        err,
 
4025
                      void       *cb_data)
 
4026
{
 
4027
    if (err) {
 
4028
        ui_log("Error allocating PEF: %x\n", err);
 
4029
        return;
 
4030
    }
 
4031
 
 
4032
    if (!ipmi_pef_valid(lpef)) {
 
4033
        display_pad_out("PEF is not valid\n");
 
4034
        ipmi_pef_destroy(pef, NULL, NULL);
 
4035
        pef = NULL;
 
4036
        return;
 
4037
    }
 
4038
 
 
4039
    pef = lpef;
 
4040
    display_pad_clear();
 
4041
    display_pef();
 
4042
 
 
4043
    ipmi_pef_get_config(pef, readpef_getconf_handler, NULL);
 
4044
}
 
4045
 
 
4046
void
 
4047
readpef_mc_handler(ipmi_mc_t *mc, void *cb_data)
 
4048
{
 
4049
    int          rv;
 
4050
    mccmd_info_t *info = cb_data;
 
4051
 
 
4052
    info->found = 1;
 
4053
 
 
4054
    if (pef) {
 
4055
        ipmi_pef_destroy(pef, NULL, NULL);
 
4056
        pef = NULL;
 
4057
    }
 
4058
    if (pef_config) {
 
4059
        ipmi_pef_free_config(pef_config);
 
4060
        pef_config = NULL;
 
4061
    }
 
4062
 
 
4063
    rv = ipmi_pef_alloc(mc, readpef_alloc_handler, NULL, NULL);
 
4064
    if (rv)
 
4065
        cmd_win_out("Error allocating PEF");
 
4066
}
 
4067
 
 
4068
int
 
4069
readpef_cmd(char *cmd, char **toks, void *cb_data)
 
4070
{
 
4071
    mccmd_info_t  info;
 
4072
    int           rv;
 
4073
 
 
4074
    if (get_mc_id(toks, &info.mc_id))
 
4075
        return 0;
 
4076
 
 
4077
    info.found = 0;
 
4078
    rv = ipmi_mc_pointer_noseq_cb(info.mc_id, readpef_mc_handler, &info);
 
4079
    if (rv) {
 
4080
        cmd_win_out("Unable to find MC\n");
 
4081
        return 0;
 
4082
    }
 
4083
    if (!info.found) {
 
4084
        cmd_win_out("Unable to find MC (%d %x)\n",
 
4085
                    info.mc_id.channel, info.mc_id.mc_num);
 
4086
    }
 
4087
    display_pad_refresh();
 
4088
 
 
4089
    return 0;
 
4090
}
 
4091
 
 
4092
int
 
4093
viewpef_cmd(char *cmd, char **toks, void *cb_data)
 
4094
{
 
4095
    display_pad_clear();
 
4096
    display_pef();
 
4097
    display_pef_config();
 
4098
    display_pad_refresh();
 
4099
    
 
4100
    return 0;
 
4101
}
 
4102
 
 
4103
void writepef_done(ipmi_pef_t *pef,
 
4104
                   int        err,
 
4105
                   void       *cb_data)
 
4106
{
 
4107
    if (err)
 
4108
        ui_log("Error writing PEF: %x\n", err);
 
4109
    else
 
4110
        ui_log("PEF written\n");
 
4111
}
 
4112
 
 
4113
int
 
4114
writepef_cmd(char *cmd, char **toks, void *cb_data)
 
4115
{
 
4116
    int rv;
 
4117
 
 
4118
    if (!pef) {
 
4119
        cmd_win_out("No PEF to write\n");
 
4120
        return 0;
 
4121
    }
 
4122
    if (!pef_config) {
 
4123
        cmd_win_out("No PEF config to write\n");
 
4124
        return 0;
 
4125
    }
 
4126
 
 
4127
    rv = ipmi_pef_set_config(pef, pef_config, writepef_done, NULL);
 
4128
    if (rv) {
 
4129
        cmd_win_out("Error writing pef parms: %x\n", rv);
 
4130
    }
 
4131
    return 0;
 
4132
}
 
4133
 
 
4134
void clearpeflock_done(ipmi_pef_t *pef,
 
4135
                       int        err,
 
4136
                       void       *cb_data)
 
4137
{
 
4138
    if (err)
 
4139
        ui_log("Error clearing PEF lock: %x\n", err);
 
4140
    else
 
4141
        ui_log("PEF lock cleared\n");
 
4142
}
 
4143
 
 
4144
static void
 
4145
clearpeflock_rsp_handler(ipmi_mc_t  *src,
 
4146
                         ipmi_msg_t *msg,
 
4147
                         void       *rsp_data)
 
4148
{
 
4149
    if (msg->data[0])
 
4150
        ui_log("Error clearing PEF lock: %x\n",
 
4151
               IPMI_IPMI_ERR_VAL(msg->data[0]));
 
4152
    else
 
4153
        ui_log("PEF lock cleared\n");
 
4154
}
 
4155
 
 
4156
void
 
4157
clearpeflock_mc_handler(ipmi_mc_t *mc, void *cb_data)
 
4158
{
 
4159
    mccmd_info_t *info = cb_data;
 
4160
    unsigned char data[2];
 
4161
    ipmi_msg_t    msg;
 
4162
    int           rv;
 
4163
 
 
4164
    info->found = 1;
 
4165
 
 
4166
    data[0] = 0;
 
4167
    data[1] = 0;
 
4168
    msg.netfn = IPMI_SENSOR_EVENT_NETFN;
 
4169
    msg.cmd = IPMI_SET_PEF_CONFIG_PARMS_CMD;
 
4170
    msg.data = data;
 
4171
    msg.data_len = 2;
 
4172
    rv = ipmi_mc_send_command(mc, 0, &msg, clearpeflock_rsp_handler,
 
4173
                              NULL);
 
4174
    if (rv)
 
4175
        cmd_win_out("Send PEF clear lock failure: %x\n", rv);
 
4176
}
 
4177
 
 
4178
int
 
4179
clearpeflock_cmd(char *cmd, char **toks, void *cb_data)
 
4180
{
 
4181
    mccmd_info_t  info;
 
4182
    int           rv;
 
4183
    char          *mc_toks;
 
4184
    char          buf[100];
 
4185
    char          *ntoks;
 
4186
 
 
4187
    mc_toks = strtok_r(NULL, "", toks);
 
4188
    if (mc_toks) {
 
4189
        strncpy(buf+2, mc_toks, sizeof(buf)-2);
 
4190
        buf[0] = 'a';
 
4191
        buf[1] = ' ';
 
4192
        strtok_r(buf, " ", &ntoks);
 
4193
        if (get_mc_id(&ntoks, &info.mc_id))
 
4194
            return 0;
 
4195
 
 
4196
        info.found = 0;
 
4197
        rv = ipmi_mc_pointer_noseq_cb(info.mc_id, clearpeflock_mc_handler,
 
4198
                                      &info);
 
4199
        if (rv) {
 
4200
            cmd_win_out("Unable to find MC\n");
 
4201
            return 0;
 
4202
        }
 
4203
        if (!info.found) {
 
4204
            cmd_win_out("Unable to find MC (%d %x)\n",
 
4205
                        info.mc_id.channel, info.mc_id.mc_num);
 
4206
        }
 
4207
        display_pad_refresh();
 
4208
    } else {
 
4209
        if (!pef) {
 
4210
            ui_log("No PEF to write\n");
 
4211
            return 0;
 
4212
        }
 
4213
 
 
4214
        ipmi_pef_clear_lock(pef, pef_config, clearpeflock_done, NULL);
 
4215
    }
 
4216
 
 
4217
    return 0;
 
4218
}
 
4219
 
 
4220
typedef struct setpef_parm_s
 
4221
{
 
4222
    char *name;
 
4223
    int (*set_val)(ipmi_pef_config_t *, unsigned int);
 
4224
    int (*set_data)(ipmi_pef_config_t *, unsigned char *, unsigned int);
 
4225
    int (*set_val_sel)(ipmi_pef_config_t *, unsigned int, unsigned int);
 
4226
    int (*set_data_sel)(ipmi_pef_config_t *, unsigned int,
 
4227
                        unsigned char *, unsigned int);
 
4228
} setpef_parm_t;
 
4229
 
 
4230
#define N NULL
 
4231
#define D(x) #x
 
4232
#define C(x) D(x)
 
4233
#define H(x) ipmi_pefconfig_set_ ## x
 
4234
#define G(x) H(x)
 
4235
static setpef_parm_t pef_conf[] =
 
4236
{
 
4237
#undef V
 
4238
#define V startup_delay_enabled
 
4239
    { C(V), G(V),    N,    N,    N },
 
4240
#undef V
 
4241
#define V alert_startup_delay_enabled
 
4242
    { C(V), G(V),    N,    N,    N },
 
4243
#undef V
 
4244
#define V event_messages_enabled
 
4245
    { C(V), G(V),    N,    N,    N },
 
4246
#undef V
 
4247
#define V pef_enabled
 
4248
    { C(V), G(V),    N,    N,    N },
 
4249
#undef V
 
4250
#define V diagnostic_interrupt_enabled
 
4251
    { C(V), G(V),    N,    N,    N },
 
4252
#undef V
 
4253
#define V oem_action_enabled
 
4254
    { C(V), G(V),    N,    N,    N },
 
4255
#undef V
 
4256
#define V power_cycle_enabled
 
4257
    { C(V), G(V),    N,    N,    N },
 
4258
#undef V
 
4259
#define V reset_enabled
 
4260
    { C(V), G(V),    N,    N,    N },
 
4261
#undef V
 
4262
#define V power_down_enabled
 
4263
    { C(V), G(V),    N,    N,    N },
 
4264
#undef V
 
4265
#define V alert_enabled
 
4266
    { C(V), G(V),    N,    N,    N },
 
4267
#undef V
 
4268
#define V startup_delay
 
4269
    { C(V), G(V),    N,    N,    N },
 
4270
#undef V
 
4271
#define V alert_startup_delay
 
4272
    { C(V), G(V),    N,    N,    N },
 
4273
#undef V
 
4274
#define V enable_filter
 
4275
    { C(V),    N,    N, G(V),    N },
 
4276
#undef V
 
4277
#define V filter_type
 
4278
    { C(V),    N,    N, G(V),    N },
 
4279
#undef V
 
4280
#define V diagnostic_interrupt
 
4281
    { C(V),    N,    N, G(V),    N },
 
4282
#undef V
 
4283
#define V oem_action
 
4284
    { C(V),    N,    N, G(V),    N },
 
4285
#undef V
 
4286
#define V power_cycle
 
4287
    { C(V),    N,    N, G(V),    N },
 
4288
#undef V
 
4289
#define V reset
 
4290
    { C(V),    N,    N, G(V),    N },
 
4291
#undef V
 
4292
#define V power_down
 
4293
    { C(V),    N,    N, G(V),    N },
 
4294
#undef V
 
4295
#define V alert
 
4296
    { C(V),    N,    N, G(V),    N },
 
4297
#undef V
 
4298
#define V alert_policy_number
 
4299
    { C(V),    N,    N, G(V),    N },
 
4300
#undef V
 
4301
#define V event_severity
 
4302
    { C(V),    N,    N, G(V),    N },
 
4303
#undef V
 
4304
#define V generator_id_addr
 
4305
    { C(V),    N,    N, G(V),    N },
 
4306
#undef V
 
4307
#define V generator_id_channel_lun
 
4308
    { C(V),    N,    N, G(V),    N },
 
4309
#undef V
 
4310
#define V sensor_type
 
4311
    { C(V),    N,    N, G(V),    N },
 
4312
#undef V
 
4313
#define V sensor_number
 
4314
    { C(V),    N,    N, G(V),    N },
 
4315
#undef V
 
4316
#define V event_trigger
 
4317
    { C(V),    N,    N, G(V),    N },
 
4318
#undef V
 
4319
#define V data1_offset_mask
 
4320
    { C(V),    N,    N, G(V),    N },
 
4321
#undef V
 
4322
#define V data1_mask
 
4323
    { C(V),    N,    N, G(V),    N },
 
4324
#undef V
 
4325
#define V data1_compare1
 
4326
    { C(V),    N,    N, G(V),    N },
 
4327
#undef V
 
4328
#define V data1_compare2
 
4329
    { C(V),    N,    N, G(V),    N },
 
4330
#undef V
 
4331
#define V data2_mask
 
4332
    { C(V),    N,    N, G(V),    N },
 
4333
#undef V
 
4334
#define V data2_compare1
 
4335
    { C(V),    N,    N, G(V),    N },
 
4336
#undef V
 
4337
#define V data2_compare2
 
4338
    { C(V),    N,    N, G(V),    N },
 
4339
#undef V
 
4340
#define V data3_mask
 
4341
    { C(V),    N,    N, G(V),    N },
 
4342
#undef V
 
4343
#define V data3_compare1
 
4344
    { C(V),    N,    N, G(V),    N },
 
4345
#undef V
 
4346
#define V data3_compare2
 
4347
    { C(V),    N,    N, G(V),    N },
 
4348
#undef V
 
4349
#define V policy_num
 
4350
    { C(V),    N,    N, G(V),    N },
 
4351
#undef V
 
4352
#define V enabled
 
4353
    { C(V),    N,    N, G(V),    N },
 
4354
#undef V
 
4355
#define V channel
 
4356
    { C(V),    N,    N, G(V),    N },
 
4357
#undef V
 
4358
#define V destination_selector
 
4359
    { C(V),    N,    N, G(V),    N },
 
4360
#undef V
 
4361
#define V alert_string_event_specific
 
4362
    { C(V),    N,    N, G(V),    N },
 
4363
#undef V
 
4364
#define V alert_string_selector
 
4365
    { C(V),    N,    N, G(V),    N },
 
4366
#undef V
 
4367
#define V event_filter
 
4368
    { C(V),    N,    N, G(V),    N },
 
4369
#undef V
 
4370
#define V alert_string_set
 
4371
    { C(V),    N,    N, G(V),    N },
 
4372
    { NULL }
 
4373
};
 
4374
 
 
4375
 
 
4376
static int
 
4377
setpef_cmd(char *cmd, char **toks, void *cb_data)
 
4378
{
 
4379
    unsigned int  sel;
 
4380
    unsigned int  val;
 
4381
    unsigned char data[30];
 
4382
    char          *name;
 
4383
    char          *str;
 
4384
    int           i;
 
4385
    int           rv = 0;
 
4386
 
 
4387
    if (!pef_config) {
 
4388
        cmd_win_out("No PEF config read, use readpef to fetch one\n");
 
4389
        return 0;
 
4390
    }
 
4391
 
 
4392
    name = strtok_r(NULL, " \t\n", toks);
 
4393
    if (!name) {
 
4394
        cmd_win_out("No PEF config name given\n");
 
4395
        return 0;
 
4396
    }
 
4397
 
 
4398
    for (i=0; pef_conf[i].name != NULL; i++) {
 
4399
        if (strcmp(pef_conf[i].name, name) == 0)
 
4400
            break;
 
4401
    }
 
4402
 
 
4403
    if (pef_conf[i].name == NULL) {
 
4404
        if (strcmp(name, "guid") == 0) {
 
4405
            for (i=0; i<sizeof(data); i++) {
 
4406
                if (get_uchar(toks, data+i, NULL))
 
4407
                    break;
 
4408
            }
 
4409
            rv = ipmi_pefconfig_set_guid(pef_config, (i != 0), data, i);
 
4410
        } else if (strcmp(name, "alert_string") == 0) {
 
4411
            if (get_uint(toks, &sel, "selector"))
 
4412
                return 0;
 
4413
            str = strtok_r(NULL, "", toks);
 
4414
            rv = ipmi_pefconfig_set_alert_string(pef_config, sel, str);
 
4415
        } else {
 
4416
            cmd_win_out("Invalid PEF config name: '%s'\n", name);
 
4417
            return 0;
 
4418
        }
 
4419
    } else if (pef_conf[i].set_val) {
 
4420
        if (get_uint(toks, &val, "value"))
 
4421
            return 0;
 
4422
        rv = pef_conf[i].set_val(pef_config, val);
 
4423
    } else if (pef_conf[i].set_data) {
 
4424
        for (i=0; i<sizeof(data); i++) {
 
4425
            if (get_uchar(toks, data+i, NULL))
 
4426
                break;
 
4427
        }
 
4428
        rv = pef_conf[i].set_data(pef_config, data, i);
 
4429
    } else if (pef_conf[i].set_val_sel) {
 
4430
        if (get_uint(toks, &sel, "selector"))
 
4431
            return 0;
 
4432
        if (get_uint(toks, &val, "value"))
 
4433
            return 0;
 
4434
        rv = pef_conf[i].set_val_sel(pef_config, sel, val);
 
4435
    } else if (pef_conf[i].set_data_sel) {
 
4436
        if (get_uint(toks, &sel, "selector"))
 
4437
            return 0;
 
4438
        for (i=0; i<sizeof(data); i++) {
 
4439
            if (get_uchar(toks, data+i, NULL))
 
4440
                break;
 
4441
        }
 
4442
        rv = pef_conf[i].set_data_sel(pef_config, sel, data, i);
 
4443
    }
 
4444
    if (rv)
 
4445
        cmd_win_out("Error setting parm: 0x%x\n", rv);
 
4446
    return 0;
 
4447
}
 
4448
 
 
4449
static void
 
4450
lanparm_out_val(char *name, int rv, char *fmt, unsigned int val)
 
4451
{
 
4452
    if (rv == ENOTSUP)
 
4453
        return;
 
4454
    display_pad_out("  %s: ", name);
 
4455
    if (rv)
 
4456
        display_pad_out("err %x", rv);
 
4457
    else
 
4458
        display_pad_out(fmt, val);
 
4459
    display_pad_out("\n");
 
4460
}
 
4461
 
 
4462
static void
 
4463
lanparm_out_data(char *name, int rv, unsigned char *data, int len)
 
4464
{
 
4465
    int i;
 
4466
    if (rv == ENOTSUP)
 
4467
        return;
 
4468
    display_pad_out("  %s: ", name);
 
4469
    if (rv)
 
4470
        display_pad_out("err %x\n", rv);
 
4471
    else {
 
4472
        for (i=0; i<len; i++)
 
4473
            display_pad_out("%2.2x", data[i]);
 
4474
        display_pad_out("\n");
 
4475
    }
 
4476
}
 
4477
 
 
4478
void
 
4479
display_lanparm_config(void)
 
4480
{
 
4481
    int           i;
 
4482
    unsigned int  val;
 
4483
    unsigned int  len;
 
4484
    unsigned char data[128];
 
4485
    int           rv;
 
4486
    unsigned int  count;
 
4487
 
 
4488
    if (!lanparm_config) {
 
4489
        display_pad_out("No LANPARM config read, use readlanparm to fetch one\n");
 
4490
        return;
 
4491
    }
 
4492
 
 
4493
    display_pad_out("LAN parameters:");
 
4494
    display_pad_out("  auth supported:");
 
4495
    if (ipmi_lanconfig_get_support_auth_oem(lanparm_config))
 
4496
        display_pad_out(" oem");
 
4497
    if (ipmi_lanconfig_get_support_auth_straight(lanparm_config))
 
4498
        display_pad_out(" straight");
 
4499
    if (ipmi_lanconfig_get_support_auth_md5(lanparm_config))
 
4500
        display_pad_out(" md5");
 
4501
    if (ipmi_lanconfig_get_support_auth_md2(lanparm_config))
 
4502
        display_pad_out(" md2");
 
4503
    if (ipmi_lanconfig_get_support_auth_none(lanparm_config))
 
4504
        display_pad_out(" none");
 
4505
    display_pad_out("\n");
 
4506
 
 
4507
    display_pad_out("  ip_addr_source: %d\n",
 
4508
                    ipmi_lanconfig_get_ip_addr_source(lanparm_config));
 
4509
    rv = ipmi_lanconfig_get_ipv4_ttl(lanparm_config, &val);
 
4510
    lanparm_out_val("ipv4_ttl", rv, "%d", val);
 
4511
    rv = ipmi_lanconfig_get_ipv4_flags(lanparm_config, &val);
 
4512
    lanparm_out_val("ipv4_flags", rv, "%d", val);
 
4513
    rv = ipmi_lanconfig_get_ipv4_precedence(lanparm_config, &val);
 
4514
    lanparm_out_val("ipv4_precedence", rv, "%d", val);
 
4515
    rv = ipmi_lanconfig_get_ipv4_tos(lanparm_config, &val);
 
4516
    lanparm_out_val("ipv4_tos", rv, "%d", val);
 
4517
 
 
4518
    for (i=0; i<5; i++) {
 
4519
        display_pad_out("  auth enabled (%d):", i);
 
4520
        rv = ipmi_lanconfig_get_enable_auth_oem(lanparm_config, i, &val);
 
4521
        if (rv)
 
4522
            display_pad_out(" oemerr%x", rv);
 
4523
        else if (val)
 
4524
            display_pad_out(" oem");
 
4525
        rv = ipmi_lanconfig_get_enable_auth_straight(lanparm_config, i, &val);
 
4526
        if (rv)
 
4527
            display_pad_out(" straighterr%x", rv);
 
4528
        else if (val)
 
4529
            display_pad_out(" straight");
 
4530
        rv = ipmi_lanconfig_get_enable_auth_md5(lanparm_config, i, &val);
 
4531
        if (rv)
 
4532
            display_pad_out(" md5err%x", rv);
 
4533
        else if (val)
 
4534
            display_pad_out(" md5");
 
4535
        rv = ipmi_lanconfig_get_enable_auth_md2(lanparm_config, i, &val);
 
4536
        if (rv)
 
4537
            display_pad_out(" md2err%x", rv);
 
4538
        else if (val)
 
4539
            display_pad_out(" md2");
 
4540
        rv = ipmi_lanconfig_get_enable_auth_none(lanparm_config, i, &val);
 
4541
        if (rv)
 
4542
            display_pad_out(" noneerr%x", rv);
 
4543
        else if (val)
 
4544
            display_pad_out(" none");
 
4545
        display_pad_out("\n");
 
4546
    }
 
4547
 
 
4548
    len = 4;
 
4549
    rv = ipmi_lanconfig_get_ip_addr(lanparm_config, data, &len);
 
4550
    lanparm_out_data("ip_addr", rv, data, len);
 
4551
    len = 6;
 
4552
    rv = ipmi_lanconfig_get_mac_addr(lanparm_config, data, &len);
 
4553
    lanparm_out_data("mac_addr", rv, data, len);
 
4554
    len = 4;
 
4555
    rv = ipmi_lanconfig_get_subnet_mask(lanparm_config, data, &len);
 
4556
    lanparm_out_data("subnet_mask", rv, data, len);
 
4557
    len = 2;
 
4558
    rv = ipmi_lanconfig_get_primary_rmcp_port(lanparm_config, data, &len);
 
4559
    lanparm_out_data("primary_rmcp_port", rv, data, len);
 
4560
    len = 2;
 
4561
    rv = ipmi_lanconfig_get_secondary_rmcp_port(lanparm_config, data, &len);
 
4562
    lanparm_out_data("secondary_rmcp_port", rv, data, len);
 
4563
 
 
4564
    rv = ipmi_lanconfig_get_bmc_generated_arps(lanparm_config, &val);
 
4565
    lanparm_out_val("bmc_generated_arps", rv, "%d", val);
 
4566
    rv = ipmi_lanconfig_get_bmc_generated_garps(lanparm_config, &val);
 
4567
    lanparm_out_val("bmc_generated_garps", rv, "%d", val);
 
4568
    rv = ipmi_lanconfig_get_garp_interval(lanparm_config, &val);
 
4569
    lanparm_out_val("garp_interval", rv, "%d", val);
 
4570
 
 
4571
    len = 4;
 
4572
    rv = ipmi_lanconfig_get_default_gateway_ip_addr(lanparm_config, data, &len);
 
4573
    lanparm_out_data("default_gateway_ip_addr", rv, data, len);
 
4574
    len = 6;
 
4575
    rv = ipmi_lanconfig_get_default_gateway_mac_addr(lanparm_config, data, &len);
 
4576
    lanparm_out_data("default_gateway_mac_addr", rv, data, len);
 
4577
    len = 4;
 
4578
    rv = ipmi_lanconfig_get_backup_gateway_ip_addr(lanparm_config, data, &len);
 
4579
    lanparm_out_data("backup_gateway_ip_addr", rv, data, len);
 
4580
    len = 6;
 
4581
    rv = ipmi_lanconfig_get_backup_gateway_mac_addr(lanparm_config, data, &len);
 
4582
    lanparm_out_data("backup_gateway_mac_addr", rv, data, len);
 
4583
 
 
4584
    len = 18;
 
4585
    rv = ipmi_lanconfig_get_community_string(lanparm_config, data, &len);
 
4586
    display_pad_out("  community_string: ");
 
4587
    if (rv)
 
4588
        display_pad_out("err: %x\n", rv);
 
4589
    else
 
4590
        display_pad_out("%s\n", data);
 
4591
 
 
4592
    count = ipmi_lanconfig_get_num_alert_destinations(lanparm_config);
 
4593
    display_pad_out("  num_alert_destinations: %d\n", count);
 
4594
    for (i=0; i<count; i++) {
 
4595
        display_pad_out("  destination %d:\n", i);
 
4596
        rv = ipmi_lanconfig_get_alert_ack(lanparm_config, i, &val);
 
4597
        lanparm_out_val("  alert_ack", rv, "%d", val);
 
4598
        rv = ipmi_lanconfig_get_dest_type(lanparm_config, i, &val);
 
4599
        lanparm_out_val("  dest_type", rv, "%d", val);
 
4600
        rv = ipmi_lanconfig_get_alert_retry_interval(lanparm_config, i, &val);
 
4601
        lanparm_out_val("  alert_retry_interval", rv, "%d", val);
 
4602
        rv = ipmi_lanconfig_get_max_alert_retries(lanparm_config, i, &val);
 
4603
        lanparm_out_val("  max_alert_retries", rv, "%d", val);
 
4604
        rv = ipmi_lanconfig_get_dest_format(lanparm_config, i, &val);
 
4605
        lanparm_out_val("  dest_format", rv, "%d", val);
 
4606
        rv = ipmi_lanconfig_get_gw_to_use(lanparm_config, i, &val);
 
4607
        lanparm_out_val("  gw_to_use", rv, "%d", val);
 
4608
        len = 4;
 
4609
        rv = ipmi_lanconfig_get_dest_ip_addr(lanparm_config, i, data, &len);
 
4610
        lanparm_out_data("  dest_ip_addr", rv, data, len);
 
4611
        len = 6;
 
4612
        rv = ipmi_lanconfig_get_dest_mac_addr(lanparm_config, i, data, &len);
 
4613
        lanparm_out_data("  dest_mac_addr", rv, data, len);
 
4614
    }
 
4615
}
 
4616
 
 
4617
typedef struct lanparm_info_s
 
4618
{
 
4619
    ipmi_mcid_t   mc_id;
 
4620
    unsigned char lun;
 
4621
    unsigned char channel;
 
4622
    ipmi_msg_t    msg;
 
4623
    int           found;
 
4624
} lanparm_info_t;
 
4625
 
 
4626
void
 
4627
readlanparm_getconf_handler(ipmi_lanparm_t    *lanparm,
 
4628
                            int               err,
 
4629
                            ipmi_lan_config_t *config,
 
4630
                            void              *cb_data)
 
4631
{
 
4632
    if (err) {
 
4633
        ui_log("Error reading LANPARM config: %x\n", err);
 
4634
        return;
 
4635
    }
 
4636
 
 
4637
    lanparm_config = config;
 
4638
    display_pad_clear();
 
4639
    display_lanparm_config();
 
4640
    display_pad_refresh();
 
4641
}
 
4642
 
 
4643
void
 
4644
readlanparm_mc_handler(ipmi_mc_t *mc, void *cb_data)
 
4645
{
 
4646
    int            rv;
 
4647
    lanparm_info_t *info = cb_data;
 
4648
 
 
4649
    info->found = 1;
 
4650
 
 
4651
    if (lanparm) {
 
4652
        ipmi_lanparm_destroy(lanparm, NULL, NULL);
 
4653
        lanparm = NULL;
 
4654
    }
 
4655
    if (lanparm_config) {
 
4656
        ipmi_lan_free_config(lanparm_config);
 
4657
        lanparm_config = NULL;
 
4658
    }
 
4659
 
 
4660
    rv = ipmi_lanparm_alloc(mc, info->channel, &lanparm);
 
4661
    if (rv) {
 
4662
        cmd_win_out("failed lanparm allocation: %x\n", rv);
 
4663
        return;
 
4664
    }
 
4665
 
 
4666
    rv = ipmi_lan_get_config(lanparm, readlanparm_getconf_handler, NULL);
 
4667
}
 
4668
 
 
4669
int
 
4670
readlanparm_cmd(char *cmd, char **toks, void *cb_data)
 
4671
{
 
4672
    lanparm_info_t info;
 
4673
    int            rv;
 
4674
    unsigned char  val;
 
4675
 
 
4676
    if (get_mc_id(toks, &info.mc_id))
 
4677
        return 0;
 
4678
 
 
4679
    if (get_uchar(toks, &val, "lanparm channel"))
 
4680
        return 0;
 
4681
    info.channel = val;
 
4682
 
 
4683
    info.found = 0;
 
4684
    rv = ipmi_mc_pointer_noseq_cb(info.mc_id, readlanparm_mc_handler, &info);
 
4685
    if (rv) {
 
4686
        cmd_win_out("Unable to find MC\n");
 
4687
        return 0;
 
4688
    }
 
4689
    if (!info.found) {
 
4690
        cmd_win_out("Unable to find MC (%d %x)\n",
 
4691
                    info.mc_id.channel, info.mc_id.mc_num);
 
4692
    }
 
4693
    display_pad_refresh();
 
4694
 
 
4695
    return 0;
 
4696
}
 
4697
 
 
4698
int
 
4699
viewlanparm_cmd(char *cmd, char **toks, void *cb_data)
 
4700
{
 
4701
    display_pad_clear();
 
4702
    display_lanparm_config();
 
4703
    display_pad_refresh();
 
4704
    
 
4705
    return 0;
 
4706
}
 
4707
 
 
4708
void writelanparm_done(ipmi_lanparm_t *lanparm,
 
4709
                       int            err,
 
4710
                       void           *cb_data)
 
4711
{
 
4712
    if (err)
 
4713
        ui_log("Error writing LANPARM: %x\n", err);
 
4714
    else
 
4715
        ui_log("LANPARM written\n");
 
4716
}
 
4717
 
 
4718
int
 
4719
writelanparm_cmd(char *cmd, char **toks, void *cb_data)
 
4720
{
 
4721
    int rv;
 
4722
 
 
4723
    if (!lanparm) {
 
4724
        cmd_win_out("No LANPARM to write\n");
 
4725
        return 0;
 
4726
    }
 
4727
    if (!lanparm_config) {
 
4728
        cmd_win_out("No LANPARM config to write\n");
 
4729
        return 0;
 
4730
    }
 
4731
 
 
4732
    rv = ipmi_lan_set_config(lanparm, lanparm_config, writelanparm_done, NULL);
 
4733
    if (rv) {
 
4734
        cmd_win_out("Error writing lan parms: %x\n", rv);
 
4735
    }
 
4736
    return 0;
 
4737
}
 
4738
 
 
4739
void clearlanparmlock_done(ipmi_lanparm_t *lanparm,
 
4740
                           int            err,
 
4741
                           void           *cb_data)
 
4742
{
 
4743
    if (err)
 
4744
        ui_log("Error clearing LANPARM lock: %x\n", err);
 
4745
    else
 
4746
        ui_log("LANPARM lock cleared\n");
 
4747
}
 
4748
 
 
4749
static void
 
4750
clearlanparmlock_rsp_handler(ipmi_mc_t  *src,
 
4751
                             ipmi_msg_t *msg,
 
4752
                             void       *rsp_data)
 
4753
{
 
4754
    if (msg->data[0])
 
4755
        ui_log("Error clearing LANPARM lock: %x\n",
 
4756
               IPMI_IPMI_ERR_VAL(msg->data[0]));
 
4757
    else
 
4758
        ui_log("LANPARM lock cleared\n");
 
4759
}
 
4760
 
 
4761
void
 
4762
clearlanparmlock_mc_handler(ipmi_mc_t *mc, void *cb_data)
 
4763
{
 
4764
    lanparm_info_t *info = cb_data;
 
4765
    unsigned char  data[3];
 
4766
    ipmi_msg_t     msg;
 
4767
    int            rv;
 
4768
 
 
4769
    info->found = 1;
 
4770
 
 
4771
    data[0] = info->channel;
 
4772
    data[1] = 0;
 
4773
    data[2] = 0;
 
4774
    msg.netfn = IPMI_TRANSPORT_NETFN;
 
4775
    msg.cmd = IPMI_SET_LAN_CONFIG_PARMS_CMD;
 
4776
    msg.data = data;
 
4777
    msg.data_len = 3;
 
4778
    rv = ipmi_mc_send_command(mc, 0, &msg, clearlanparmlock_rsp_handler,
 
4779
                              NULL);
 
4780
    if (rv)
 
4781
        cmd_win_out("Send LANPARM clear lock failure: %x\n", rv);
 
4782
}
 
4783
 
 
4784
int
 
4785
clearlanparmlock_cmd(char *cmd, char **toks, void *cb_data)
 
4786
{
 
4787
    lanparm_info_t info;
 
4788
    int            rv;
 
4789
    char           *mc_toks;
 
4790
    char           buf[100];
 
4791
    char           *ntoks;
 
4792
    unsigned char  val;
 
4793
 
 
4794
    mc_toks = strtok_r(NULL, "", toks);
 
4795
    if (mc_toks) {
 
4796
        strncpy(buf+2, mc_toks, sizeof(buf)-2);
 
4797
        buf[0] = 'a';
 
4798
        buf[1] = ' ';
 
4799
        strtok_r(buf, " ", &ntoks);
 
4800
        if (get_mc_id(&ntoks, &info.mc_id))
 
4801
            return 0;
 
4802
 
 
4803
        if (get_uchar(&ntoks, &val, "lanparm channel"))
 
4804
            return 0;
 
4805
        info.channel = val;
 
4806
 
 
4807
        info.found = 0;
 
4808
        rv = ipmi_mc_pointer_noseq_cb(info.mc_id, clearlanparmlock_mc_handler,
 
4809
                                      &info);
 
4810
        if (rv) {
 
4811
            cmd_win_out("Unable to find MC\n");
 
4812
            return 0;
 
4813
        }
 
4814
        if (!info.found) {
 
4815
            cmd_win_out("Unable to find MC (%d %x)\n",
 
4816
                        info.mc_id.channel, info.mc_id.mc_num);
 
4817
        }
 
4818
        display_pad_refresh();
 
4819
    } else {
 
4820
        if (!lanparm) {
 
4821
            ui_log("No LANPARM to write\n");
 
4822
            return 0;
 
4823
        }
 
4824
 
 
4825
        ipmi_lan_clear_lock(lanparm, lanparm_config,
 
4826
                            clearlanparmlock_done, NULL);
 
4827
    }
 
4828
 
 
4829
    return 0;
 
4830
}
 
4831
 
 
4832
typedef struct setlan_parm_s
 
4833
{
 
4834
    char *name;
 
4835
    int (*set_val)(ipmi_lan_config_t *, unsigned int);
 
4836
    int (*set_data)(ipmi_lan_config_t *, unsigned char *, unsigned int);
 
4837
    int (*set_val_sel)(ipmi_lan_config_t *, unsigned int, unsigned int);
 
4838
    int (*set_data_sel)(ipmi_lan_config_t *, unsigned int,
 
4839
                        unsigned char *, unsigned int);
 
4840
} setlan_parm_t;
 
4841
 
 
4842
#undef N
 
4843
#define N NULL
 
4844
#undef D
 
4845
#define D(x) #x
 
4846
#undef C
 
4847
#define C(x) D(x)
 
4848
#undef H
 
4849
#define H(x) ipmi_lanconfig_set_ ## x
 
4850
#undef G
 
4851
#define G(x) H(x)
 
4852
static setlan_parm_t lan_conf[] =
 
4853
{
 
4854
#undef V
 
4855
#define V ip_addr_source
 
4856
    { C(V), G(V),    N,    N,    N },
 
4857
#undef V
 
4858
#define V ipv4_ttl
 
4859
    { C(V), G(V),    N,    N,    N },
 
4860
#undef V
 
4861
#define V ipv4_flags
 
4862
    { C(V), G(V),    N,    N,    N },
 
4863
#undef V
 
4864
#define V ipv4_precedence
 
4865
    { C(V), G(V),    N,    N,    N },
 
4866
#undef V
 
4867
#define V ipv4_tos
 
4868
    { C(V), G(V),    N,    N,    N },
 
4869
#undef V
 
4870
#define V enable_auth_oem
 
4871
    { C(V),    N,    N, G(V),    N },
 
4872
#undef V
 
4873
#define V enable_auth_straight
 
4874
    { C(V),    N,    N, G(V),    N },
 
4875
#undef V
 
4876
#define V enable_auth_md5
 
4877
    { C(V),    N,    N, G(V),    N },
 
4878
#undef V
 
4879
#define V enable_auth_md2
 
4880
    { C(V),    N,    N, G(V),    N },
 
4881
#undef V
 
4882
#define V enable_auth_none
 
4883
    { C(V),    N,    N, G(V),    N },
 
4884
#undef V
 
4885
#define V ip_addr
 
4886
    { C(V),    N, G(V),    N,    N },
 
4887
#undef V
 
4888
#define V mac_addr
 
4889
    { C(V),    N, G(V),    N,    N },
 
4890
#undef V
 
4891
#define V subnet_mask
 
4892
    { C(V),    N, G(V),    N,    N },
 
4893
#undef V
 
4894
#define V primary_rmcp_port
 
4895
    { C(V),    N, G(V),    N,    N },
 
4896
#undef V
 
4897
#define V secondary_rmcp_port
 
4898
    { C(V),    N, G(V),    N,    N },
 
4899
#undef V
 
4900
#define V bmc_generated_arps
 
4901
    { C(V), G(V),    N,    N,    N },
 
4902
#undef V
 
4903
#define V bmc_generated_garps
 
4904
    { C(V), G(V),    N,    N,    N },
 
4905
#undef V
 
4906
#define V garp_interval
 
4907
    { C(V), G(V),    N,    N,    N },
 
4908
#undef V
 
4909
#define V default_gateway_ip_addr
 
4910
    { C(V),    N, G(V),    N,    N },
 
4911
#undef V
 
4912
#define V default_gateway_mac_addr
 
4913
    { C(V),    N, G(V),    N,    N },
 
4914
#undef V
 
4915
#define V backup_gateway_ip_addr
 
4916
    { C(V),    N, G(V),    N,    N },
 
4917
#undef V
 
4918
#define V backup_gateway_mac_addr
 
4919
    { C(V),    N, G(V),    N,    N },
 
4920
#undef V
 
4921
#define V alert_ack
 
4922
    { C(V),    N,    N, G(V),    N },
 
4923
#undef V
 
4924
#define V dest_type
 
4925
    { C(V),    N,    N, G(V),    N },
 
4926
#undef V
 
4927
#define V alert_retry_interval
 
4928
    { C(V),    N,    N, G(V),    N },
 
4929
#undef V
 
4930
#define V max_alert_retries
 
4931
    { C(V),    N,    N, G(V),    N },
 
4932
#undef V
 
4933
#define V dest_format
 
4934
    { C(V),    N,    N, G(V),    N },
 
4935
#undef V
 
4936
#define V gw_to_use
 
4937
    { C(V),    N,    N, G(V),    N },
 
4938
#undef V
 
4939
#define V dest_ip_addr
 
4940
    { C(V),    N,    N,    N, G(V) },
 
4941
#undef V
 
4942
#define V dest_mac_addr
 
4943
    { C(V),    N,    N,    N, G(V) },
 
4944
};
 
4945
 
 
4946
 
 
4947
static int
 
4948
setlanparm_cmd(char *cmd, char **toks, void *cb_data)
 
4949
{
 
4950
    unsigned int  sel;
 
4951
    unsigned int  val;
 
4952
    unsigned char data[30];
 
4953
    char          *name;
 
4954
    char          *str;
 
4955
    int           i, j;
 
4956
    int           rv = 0;
 
4957
 
 
4958
    if (!lanparm_config) {
 
4959
        cmd_win_out("No LAN config read, use readlan to fetch one\n");
 
4960
        return 0;
 
4961
    }
 
4962
 
 
4963
    name = strtok_r(NULL, " \t\n", toks);
 
4964
    if (!name) {
 
4965
        cmd_win_out("No LAN config name given\n");
 
4966
        return 0;
 
4967
    }
 
4968
 
 
4969
    for (i=0; lan_conf[i].name != NULL; i++) {
 
4970
        if (strcmp(lan_conf[i].name, name) == 0)
 
4971
            break;
 
4972
    }
 
4973
 
 
4974
    if (lan_conf[i].name == NULL) {
 
4975
        if (strcmp(name, "community_string") == 0) {
 
4976
            if (get_uint(toks, &sel, "selector"))
 
4977
                return 0;
 
4978
            str = strtok_r(NULL, "", toks);
 
4979
            rv = ipmi_lanconfig_set_community_string(lanparm_config,
 
4980
                                                     str, strlen(str));
 
4981
        } else {
 
4982
            cmd_win_out("Invalid LAN config name: '%s'\n", name);
 
4983
            return 0;
 
4984
        }
 
4985
    } else if (lan_conf[i].set_val) {
 
4986
        if (get_uint(toks, &val, "value"))
 
4987
            return 0;
 
4988
        rv = lan_conf[i].set_val(lanparm_config, val);
 
4989
    } else if (lan_conf[i].set_data) {
 
4990
        for (j=0; j<sizeof(data); j++) {
 
4991
            if (get_uchar(toks, data+j, NULL))
 
4992
                break;
 
4993
        }
 
4994
        rv = lan_conf[i].set_data(lanparm_config, data, j);
 
4995
    } else if (lan_conf[i].set_val_sel) {
 
4996
        if (get_uint(toks, &sel, "selector"))
 
4997
            return 0;
 
4998
        if (get_uint(toks, &val, "value"))
 
4999
            return 0;
 
5000
        rv = lan_conf[i].set_val_sel(lanparm_config, sel, val);
 
5001
    } else if (lan_conf[i].set_data_sel) {
 
5002
        if (get_uint(toks, &sel, "selector"))
 
5003
            return 0;
 
5004
        for (j=0; j<sizeof(data); j++) {
 
5005
            if (get_uchar(toks, data+j, NULL))
 
5006
                break;
 
5007
        }
 
5008
        rv = lan_conf[i].set_data_sel(lanparm_config, sel, data, j);
 
5009
    }
 
5010
    if (rv)
 
5011
        cmd_win_out("Error setting parm: 0x%x\n", rv);
 
5012
    return 0;
 
5013
}
 
5014
 
 
5015
static ipmi_pet_t *pet;
 
5016
 
 
5017
typedef struct pet_info_s
 
5018
{
 
5019
    unsigned int   connection;
 
5020
    unsigned int   channel;
 
5021
    struct in_addr ip_addr;
 
5022
    unsigned char  mac_addr[6];
 
5023
    unsigned int   eft_sel;
 
5024
    unsigned int   policy_num;
 
5025
    unsigned int   apt_sel;
 
5026
    unsigned int   lan_dest_sel;
 
5027
} pet_info_t;
 
5028
 
 
5029
static void
 
5030
pet_done(ipmi_pet_t *pet, int err, void *cb_data)
 
5031
{
 
5032
    if (err)
 
5033
        ui_log("Error setting pet: %x\n", err);
 
5034
    else
 
5035
        ui_log("PET set");      
 
5036
}
 
5037
 
 
5038
static void
 
5039
pet_domain_cb(ipmi_domain_t *domain, void *cb_data)
 
5040
{
 
5041
    pet_info_t *info = cb_data;
 
5042
    int        rv;
 
5043
 
 
5044
    rv = ipmi_pet_create(domain,
 
5045
                         info->connection,
 
5046
                         info->channel,
 
5047
                         info->ip_addr,
 
5048
                         info->mac_addr,
 
5049
                         info->eft_sel,
 
5050
                         info->policy_num,
 
5051
                         info->apt_sel,
 
5052
                         info->lan_dest_sel,
 
5053
                         pet_done,
 
5054
                         NULL,
 
5055
                         &pet);
 
5056
    if (rv)
 
5057
        cmd_win_out("Error creating PET: %x\n", rv);
 
5058
}
 
5059
 
 
5060
static int
 
5061
pet_cmd(char *cmd, char **toks, void *cb_data)
 
5062
{
 
5063
    pet_info_t info;
 
5064
    int        rv;
 
5065
 
 
5066
    if (pet) {
 
5067
        ipmi_pet_destroy(pet, NULL, NULL);
 
5068
        pet = NULL;
 
5069
    }
 
5070
 
 
5071
    if (get_uint(toks, &info.connection, "connection"))
 
5072
        return 0;
 
5073
    if (get_uint(toks, &info.channel, "channel"))
 
5074
        return 0;
 
5075
    if (get_ip_addr(toks, &info.ip_addr, "IP address"))
 
5076
        return 0;
 
5077
    if (get_mac_addr(toks, info.mac_addr, "MAC address"))
 
5078
        return 0;
 
5079
    if (get_uint(toks, &info.eft_sel, "eft selector"))
 
5080
        return 0;
 
5081
    if (get_uint(toks, &info.policy_num, "policy_num"))
 
5082
        return 0;
 
5083
    if (get_uint(toks, &info.apt_sel, "apt selector"))
 
5084
        return 0;
 
5085
    if (get_uint(toks, &info.lan_dest_sel, "LAN dest selector"))
 
5086
        return 0;
 
5087
 
 
5088
    rv = ipmi_domain_pointer_cb(domain_id, pet_domain_cb, &info);
 
5089
    if (rv)
 
5090
        cmd_win_out("Error converting domain");
 
5091
    return 0;
 
5092
}
 
5093
 
 
5094
typedef struct msg_cmd_data_s
 
5095
{
 
5096
    unsigned char    data[MCCMD_DATA_SIZE];
 
5097
    unsigned int     data_len;
 
5098
    ipmi_ipmb_addr_t addr;
 
5099
    ipmi_msg_t       msg;
 
5100
} msg_cmd_data_t;
 
5101
 
 
5102
static int
 
5103
mccmd_addr_rsp_handler(ipmi_domain_t *domain, ipmi_msgi_t *rspi)
 
5104
{
 
5105
    ipmi_msg_t    *msg = &rspi->msg;
 
5106
    unsigned int  i;
 
5107
    unsigned char *data;
 
5108
 
 
5109
    display_pad_clear();
 
5110
    curr_display_type = DISPLAY_RSP;
 
5111
    display_pad_out("Response:\n");
 
5112
    display_pad_out("  NetFN = 0x%2.2x\n", msg->netfn);
 
5113
    display_pad_out("  Command = 0x%2.2x\n", msg->cmd);
 
5114
    display_pad_out("  Completion code = 0x%2.2x\n", msg->data[0]);
 
5115
    display_pad_out("  data =");
 
5116
    data = msg->data + 1;
 
5117
    for (i=0; i+1<msg->data_len; i++) {
 
5118
        if ((i != 0) && ((i % 8) == 0))
 
5119
            display_pad_out("\n        ");
 
5120
        display_pad_out(" %2.2x", data[i]);
 
5121
    }
 
5122
    display_pad_out("\n");
 
5123
    display_pad_refresh();
 
5124
    return IPMI_MSG_ITEM_NOT_USED;
 
5125
}
 
5126
 
 
5127
static void
 
5128
msg_cmder(ipmi_domain_t *domain, void *cb_data)
 
5129
{
 
5130
    msg_cmd_data_t *info = cb_data;
 
5131
    int            rv;
 
5132
 
 
5133
    rv = ipmi_send_command_addr(domain,
 
5134
                                (ipmi_addr_t *) &(info->addr),
 
5135
                                sizeof(info->addr),
 
5136
                                &info->msg,
 
5137
                                mccmd_addr_rsp_handler,
 
5138
                                NULL, NULL);
 
5139
    if (rv)
 
5140
        cmd_win_out("Send command failure: %x\n", rv);
 
5141
}
 
5142
 
 
5143
static int
 
5144
msg_cmd(char *cmd, char **toks, void *cb_data)
 
5145
{
 
5146
    msg_cmd_data_t info;
 
5147
    unsigned int   channel;
 
5148
    int            rv;
 
5149
    
 
5150
    info.addr.addr_type = IPMI_IPMB_ADDR_TYPE;
 
5151
    if (get_uint(toks, &channel, "channel"))
 
5152
        return 0;
 
5153
    info.addr.channel = channel;
 
5154
 
 
5155
    if (get_uchar(toks, &info.addr.slave_addr, "slave address"))
 
5156
        return 0;
 
5157
 
 
5158
    if (info.addr.slave_addr == 0) {
 
5159
        info.addr.addr_type = IPMI_IPMB_BROADCAST_ADDR_TYPE;
 
5160
        if (get_uchar(toks, &info.addr.slave_addr, "slave address"))
 
5161
            return 0;
 
5162
    }
 
5163
 
 
5164
    if (get_uchar(toks, &info.addr.lun, "LUN"))
 
5165
        return 0;
 
5166
 
 
5167
    if (get_uchar(toks, &info.msg.netfn, "NetFN"))
 
5168
        return 0;
 
5169
 
 
5170
    if (get_uchar(toks, &info.msg.cmd, "command"))
 
5171
        return 0;
 
5172
 
 
5173
    for (info.data_len=0; ; info.data_len++) {
 
5174
        if (get_uchar(toks, info.data+info.data_len, NULL))
 
5175
            break;
 
5176
    }
 
5177
 
 
5178
    info.msg.data_len = info.data_len;
 
5179
    info.msg.data = info.data;
 
5180
 
 
5181
    rv = ipmi_domain_pointer_cb(domain_id, msg_cmder, &info);
 
5182
    if (rv) {
 
5183
        cmd_win_out("Unable to convert domain id to a pointer\n");
 
5184
        return 0;
 
5185
    }
 
5186
 
 
5187
    display_pad_refresh();
 
5188
 
 
5189
    return 0;
 
5190
}
 
5191
 
 
5192
static void
 
5193
set_control(ipmi_control_t *control, void *cb_data)
 
5194
{
 
5195
    char          **toks = cb_data;
 
5196
    int           num_vals;
 
5197
    int           i;
 
5198
    int           *vals = NULL;
 
5199
    unsigned char *cvals = NULL;
 
5200
    char          *tok;
 
5201
    char          *estr;
 
5202
    int           rv;
 
5203
    int           control_type;
 
5204
 
 
5205
    control_type = ipmi_control_get_type(control);
 
5206
    switch (control_type) {
 
5207
        case IPMI_CONTROL_LIGHT:
 
5208
            if (ipmi_control_light_set_with_setting(control)) {
 
5209
                ipmi_light_setting_t *setting;
 
5210
 
 
5211
                num_vals = ipmi_control_get_num_vals(control);
 
5212
                setting = ipmi_alloc_light_settings(num_vals);
 
5213
                if (!setting) {
 
5214
                    cmd_win_out("set_control: out of memory\n");
 
5215
                    goto out;
 
5216
                }
 
5217
 
 
5218
                for (i=0; i<num_vals; i++) {
 
5219
                    unsigned int val;
 
5220
 
 
5221
                    if (get_uint(toks, &val, "light color"))
 
5222
                        goto out_free_light;
 
5223
                    ipmi_light_setting_set_color(setting, i, val);
 
5224
 
 
5225
                    if (get_uint(toks, &val, "light on time"))
 
5226
                        goto out_free_light;
 
5227
                    ipmi_light_setting_set_on_time(setting, i, val);
 
5228
 
 
5229
                    if (get_uint(toks, &val, "light off time"))
 
5230
                        goto out_free_light;
 
5231
                    ipmi_light_setting_set_off_time(setting, i, val);
 
5232
 
 
5233
                    if (get_uint(toks, &val, "local control"))
 
5234
                        goto out_free_light;
 
5235
                    ipmi_light_setting_set_local_control(setting, i, val);
 
5236
                }
 
5237
 
 
5238
                rv = ipmi_control_set_light(control, setting, NULL, NULL);
 
5239
                if (rv) {
 
5240
                    cmd_win_out("set_control: Returned error 0x%x\n", rv);
 
5241
                }
 
5242
            out_free_light:
 
5243
                ipmi_free_light_settings(setting);
 
5244
                break;
 
5245
            }
 
5246
            /* FALLTHRU */
 
5247
        case IPMI_CONTROL_RELAY:
 
5248
        case IPMI_CONTROL_ALARM:
 
5249
        case IPMI_CONTROL_RESET:
 
5250
        case IPMI_CONTROL_ONE_SHOT_RESET:
 
5251
        case IPMI_CONTROL_POWER:
 
5252
        case IPMI_CONTROL_FAN_SPEED:
 
5253
        case IPMI_CONTROL_OUTPUT:
 
5254
        case IPMI_CONTROL_ONE_SHOT_OUTPUT:
 
5255
            num_vals = ipmi_control_get_num_vals(control);
 
5256
            vals = ipmi_mem_alloc(sizeof(*vals) * num_vals);
 
5257
            if (!vals) {
 
5258
                cmd_win_out("set_control: out of memory\n");
 
5259
                goto out;
 
5260
            }
 
5261
        
 
5262
            for (i=0; i<num_vals; i++) {
 
5263
                tok = strtok_r(NULL, " \t\n", toks);
 
5264
                if (!tok) {
 
5265
                    cmd_win_out("set_control: Value %d is not present\n", i);
 
5266
                    goto out_bcon;
 
5267
                }
 
5268
                vals[i] = strtol(tok, &estr, 0);
 
5269
                if (*estr != '\0') {
 
5270
                    cmd_win_out("set_control: Value %d is invalid\n", i);
 
5271
                    goto out_bcon;
 
5272
                }
 
5273
            }
 
5274
 
 
5275
            rv = ipmi_control_set_val(control, vals, NULL, NULL);
 
5276
            if (rv) {
 
5277
                cmd_win_out("set_control: Returned error 0x%x\n", rv);
 
5278
            }
 
5279
    out_bcon:
 
5280
            break;
 
5281
 
 
5282
        case IPMI_CONTROL_DISPLAY:
 
5283
            break;
 
5284
 
 
5285
        case IPMI_CONTROL_IDENTIFIER:
 
5286
            num_vals = ipmi_control_identifier_get_max_length(control);
 
5287
            cvals = ipmi_mem_alloc(sizeof(*cvals) * num_vals);
 
5288
            if (!cvals) {
 
5289
                cmd_win_out("set_control: out of memory\n");
 
5290
                goto out;
 
5291
            }
 
5292
        
 
5293
            for (i=0; i<num_vals; i++) {
 
5294
                tok = strtok_r(NULL, " \t\n", toks);
 
5295
                if (!tok) {
 
5296
                    cmd_win_out("set_control: Value %d is not present\n", i);
 
5297
                    goto out;
 
5298
                }
 
5299
                cvals[i] = strtol(tok, &estr, 0);
 
5300
                if (*estr != '\0') {
 
5301
                    cmd_win_out("set_control: Value %d is invalid\n", i);
 
5302
                    goto out;
 
5303
                }
 
5304
            }
 
5305
 
 
5306
            rv = ipmi_control_identifier_set_val(control, cvals, num_vals,
 
5307
                                                 NULL, NULL);
 
5308
            if (rv) {
 
5309
                cmd_win_out("set_control: Returned error 0x%x\n", rv);
 
5310
            }
 
5311
            break;
 
5312
    }
 
5313
 out:
 
5314
    if (vals)
 
5315
        ipmi_mem_free(vals);
 
5316
    if (cvals)
 
5317
        ipmi_mem_free(cvals);
 
5318
}
 
5319
 
 
5320
static int
 
5321
set_control_cmd(char *cmd, char **toks, void *cb_data)
 
5322
{
 
5323
    int rv;
 
5324
 
 
5325
    if (curr_display_type != DISPLAY_CONTROL) {
 
5326
        cmd_win_out("The current displayed item is not a control\n");
 
5327
        goto out;
 
5328
    }
 
5329
 
 
5330
    rv = ipmi_control_pointer_cb(curr_control_id, set_control, toks);
 
5331
    if (rv)
 
5332
        cmd_win_out("set_control: Unable to get control pointer: 0x%x\n", rv);
 
5333
 
 
5334
 out:
 
5335
    return 0;
 
5336
}
 
5337
 
 
5338
static void
 
5339
delevent_cb(ipmi_domain_t *domain, int err, void *cb_data)
 
5340
{
 
5341
    if (err)
 
5342
        ui_log("Error deleting log: %x\n", err);
 
5343
    else
 
5344
        ui_log("log deleted\n");
 
5345
}
 
5346
 
 
5347
typedef struct delevent_info_s
 
5348
{
 
5349
    ipmi_mcid_t mc_id;
 
5350
    int         record_id;
 
5351
    int         rv;
 
5352
} delevent_info_t;
 
5353
 
 
5354
static void
 
5355
delevent_cmder(ipmi_domain_t *domain, void *cb_data)
 
5356
{
 
5357
    int             rv;
 
5358
    delevent_info_t *info = cb_data;
 
5359
    ipmi_event_t    *event, *n;
 
5360
    int             found = 0;
 
5361
 
 
5362
    info->mc_id.domain_id = domain_id;
 
5363
 
 
5364
    event = ipmi_domain_first_event(domain);
 
5365
    while (event) {
 
5366
        if ((ipmi_cmp_mc_id_noseq(ipmi_event_get_mcid(event),info->mc_id) == 0)
 
5367
            && (ipmi_event_get_record_id(event) == info->record_id))
 
5368
        {
 
5369
            rv = ipmi_domain_del_event(domain, event, delevent_cb, NULL);
 
5370
            if (rv)
 
5371
                cmd_win_out("error deleting log: %x\n", rv);
 
5372
            ipmi_event_free(event);
 
5373
            found = 1;
 
5374
            break;
 
5375
        } else {
 
5376
            n = ipmi_domain_next_event(domain, event);
 
5377
            ipmi_event_free(event);
 
5378
            event = n;
 
5379
        }
 
5380
    }
 
5381
    if (!found)
 
5382
        cmd_win_out("log not found\n");
 
5383
}
 
5384
 
 
5385
static int
 
5386
delevent_cmd(char *cmd, char **toks, void *cb_data)
 
5387
{
 
5388
    delevent_info_t info;
 
5389
    int             rv;
 
5390
 
 
5391
    if (get_mc_id(toks, &info.mc_id))
 
5392
        return 0;
 
5393
 
 
5394
    if (get_uint(toks, &info.record_id, "record id"))
 
5395
        return 0;
 
5396
 
 
5397
    rv = ipmi_domain_pointer_cb(domain_id, delevent_cmder, &info);
 
5398
    if (rv) {
 
5399
        cmd_win_out("Unable to convert domain id to a pointer\n");
 
5400
        return 0;
 
5401
    }
 
5402
    return 0;
 
5403
}
 
5404
 
 
5405
static void
 
5406
addevent_cb(ipmi_mc_t *mc, unsigned int record_id, int err, void *cb_data)
 
5407
{
 
5408
    if (err)
 
5409
        ui_log("Error adding event: %x\n", err);
 
5410
    else
 
5411
        ui_log("event 0x%4.4x added\n", record_id);
 
5412
}
 
5413
 
 
5414
typedef struct addevent_info_s
 
5415
{
 
5416
    ipmi_mcid_t   mc_id;
 
5417
    unsigned int  record_id;
 
5418
    unsigned int  type;
 
5419
    ipmi_time_t   timestamp;
 
5420
    unsigned char data[13];
 
5421
} addevent_info_t;
 
5422
 
 
5423
static void
 
5424
addevent_cmder(ipmi_mc_t *mc, void *cb_data)
 
5425
{
 
5426
    int             rv;
 
5427
    addevent_info_t *info = cb_data;
 
5428
    ipmi_event_t    *event;
 
5429
 
 
5430
    event = ipmi_event_alloc(ipmi_mc_convert_to_id(mc),
 
5431
                             info->record_id,
 
5432
                             info->type,
 
5433
                             info->timestamp,
 
5434
                             info->data,
 
5435
                             13);
 
5436
    if (!event) {
 
5437
        cmd_win_out("Could not allocate event\n");
 
5438
        return;
 
5439
    }
 
5440
                             
 
5441
    rv = ipmi_mc_add_event_to_sel(mc, event, addevent_cb, NULL);
 
5442
    if (rv)
 
5443
        cmd_win_out("Unable to send add event: %x\n", rv);
 
5444
    ipmi_event_free(event);
 
5445
}
 
5446
 
 
5447
static int
 
5448
addevent_cmd(char *cmd, char **toks, void *cb_data)
 
5449
{
 
5450
    addevent_info_t info;
 
5451
    int             rv;
 
5452
    int             i;
 
5453
    struct timeval  time;
 
5454
 
 
5455
    if (get_mc_id(toks, &info.mc_id))
 
5456
        return 0;
 
5457
 
 
5458
    if (get_uint(toks, &info.record_id, "record id"))
 
5459
        return 0;
 
5460
 
 
5461
    if (get_uint(toks, &info.type, "record type"))
 
5462
        return 0;
 
5463
 
 
5464
    for (i=0; i<13; i++) {
 
5465
        if (get_uchar(toks, &info.data[i], "data"))
 
5466
            return 0;
 
5467
    }
 
5468
 
 
5469
    gettimeofday(&time, NULL);
 
5470
    info.timestamp = time.tv_sec * 1000000000;
 
5471
 
 
5472
    rv = ipmi_mc_pointer_noseq_cb(info.mc_id, addevent_cmder, &info);
 
5473
    if (rv) {
 
5474
        cmd_win_out("Unable to convert domain id to a pointer\n");
 
5475
        return 0;
 
5476
    }
 
5477
    return 0;
 
5478
}
 
5479
 
 
5480
static int
 
5481
debug_cmd(char *cmd, char **toks, void *cb_data)
 
5482
{
 
5483
    char         *type;
 
5484
    char         *on_off;
 
5485
    int          val;
 
5486
 
 
5487
    type = strtok_r(NULL, " \t\n", toks);
 
5488
    if (!type) {
 
5489
        cmd_win_out("No debug type specified\n");
 
5490
        goto out;
 
5491
    }
 
5492
 
 
5493
    on_off = strtok_r(NULL, " \t\n", toks);
 
5494
    if (!on_off) {
 
5495
        cmd_win_out("on or off not specified\n");
 
5496
        goto out;
 
5497
    } else if (strcmp(on_off, "on") == 0) {
 
5498
        val = 1;
 
5499
    } else if (strcmp(on_off, "off") == 0) {
 
5500
        val = 0;
 
5501
    } else {
 
5502
        cmd_win_out("on or off not specified, got '%s'\n", on_off);
 
5503
        goto out;
 
5504
    }
 
5505
 
 
5506
    if (strcmp(type, "msg") == 0) {
 
5507
        if (val) DEBUG_MSG_ENABLE(); else DEBUG_MSG_DISABLE();
 
5508
    } else if (strcmp(type, "rawmsg") == 0) {
 
5509
        if (val) DEBUG_RAWMSG_ENABLE(); else DEBUG_RAWMSG_DISABLE();
 
5510
    } else if (strcmp(type, "locks") == 0) {
 
5511
        if (val) DEBUG_LOCKS_ENABLE(); else DEBUG_LOCKS_DISABLE();
 
5512
    } else if (strcmp(type, "events") == 0) {
 
5513
        if (val) DEBUG_EVENTS_ENABLE(); else DEBUG_EVENTS_DISABLE();
 
5514
    } else if (strcmp(type, "con0") == 0) {
 
5515
        if (val) DEBUG_CON_FAIL_ENABLE(0); else DEBUG_CON_FAIL_DISABLE(0);
 
5516
    } else if (strcmp(type, "con1") == 0) {
 
5517
        if (val) DEBUG_CON_FAIL_ENABLE(1); else DEBUG_CON_FAIL_DISABLE(1);
 
5518
    } else if (strcmp(type, "con2") == 0) {
 
5519
        if (val) DEBUG_CON_FAIL_ENABLE(2); else DEBUG_CON_FAIL_DISABLE(2);
 
5520
    } else if (strcmp(type, "con3") == 0) {
 
5521
        if (val) DEBUG_CON_FAIL_ENABLE(3); else DEBUG_CON_FAIL_DISABLE(3);
 
5522
    } else {
 
5523
        cmd_win_out("Invalid debug type specified: '%s'\n", type);
 
5524
        goto out;
 
5525
    }
 
5526
 
 
5527
 out:
 
5528
    return 0;
 
5529
}
 
5530
 
 
5531
static void
 
5532
clear_sel_cmder(ipmi_domain_t *domain, void *cb_data)
 
5533
{
 
5534
    ipmi_event_t *event, *event2;
 
5535
 
 
5536
    event = ipmi_domain_first_event(domain);
 
5537
    while (event) {
 
5538
        event2 = event;
 
5539
        event = ipmi_domain_next_event(domain, event2);
 
5540
        ipmi_domain_del_event(domain, event2, NULL, NULL);
 
5541
        ipmi_event_free(event2);
 
5542
    }
 
5543
}
 
5544
 
 
5545
static int
 
5546
clear_sel_cmd(char *cmd, char **toks, void *cb_data)
 
5547
{
 
5548
    int rv;
 
5549
 
 
5550
    rv = ipmi_domain_pointer_cb(domain_id, clear_sel_cmder, NULL);
 
5551
    if (rv) {
 
5552
        cmd_win_out("Unable to convert domain id to a pointer\n");
 
5553
        return 0;
 
5554
    }
 
5555
    return 0;
 
5556
}
 
5557
 
 
5558
static void
 
5559
list_sel_cmder(ipmi_domain_t *domain, void *cb_data)
 
5560
{
 
5561
    int          rv;
 
5562
    ipmi_event_t *event, *event2;
 
5563
    unsigned int count1, count2;
 
5564
 
 
5565
    curr_display_type = EVENTS;
 
5566
    display_pad_clear();
 
5567
    rv = ipmi_domain_sel_count(domain, &count1);
 
5568
    if (rv)
 
5569
      count1 = -1;
 
5570
    rv = ipmi_domain_sel_entries_used(domain, &count2);
 
5571
    if (rv)
 
5572
      count2 = -1;
 
5573
    display_pad_out("Event counts: %d entries, %d slots used\n",
 
5574
                    count1, count2);
 
5575
    display_pad_out("Events:\n");
 
5576
    event = ipmi_domain_first_event(domain);
 
5577
    while (event) {
 
5578
        ipmi_mcid_t   mcid = ipmi_event_get_mcid(event);
 
5579
        unsigned int  record_id = ipmi_event_get_record_id(event);
 
5580
        unsigned int  type = ipmi_event_get_type(event);
 
5581
        ipmi_time_t   timestamp = ipmi_event_get_timestamp(event);
 
5582
        unsigned int  data_len = ipmi_event_get_data_len(event);
 
5583
        unsigned char *data = ipmi_event_get_data_ptr(event);
 
5584
        int           i;
 
5585
 
 
5586
        display_pad_out("  (%x %x) %4.4x:%2.2x %lld:",
 
5587
                        mcid.channel, mcid.mc_num, record_id, type, timestamp);
 
5588
        for (i=0; i<data_len; i++)
 
5589
            display_pad_out(" %2.2x", data[i]);
 
5590
        display_pad_out("\n");
 
5591
        event2 = ipmi_domain_next_event(domain, event);
 
5592
        ipmi_event_free(event);
 
5593
        event = event2;
 
5594
    }
 
5595
    display_pad_refresh();
 
5596
}
 
5597
 
 
5598
static int
 
5599
list_sel_cmd(char *cmd, char **toks, void *cb_data)
 
5600
{
 
5601
    int rv;
 
5602
 
 
5603
    rv = ipmi_domain_pointer_cb(domain_id, list_sel_cmder, NULL);
 
5604
    if (rv) {
 
5605
        cmd_win_out("Unable to convert domain id to a pointer\n");
 
5606
        return 0;
 
5607
    }
 
5608
    return 0;
 
5609
}
 
5610
 
 
5611
void
 
5612
sel_time_fetched(ipmi_mc_t     *mc,
 
5613
                 int           err,
 
5614
                 unsigned long time,
 
5615
                 void          *cb_data)
 
5616
{
 
5617
    if (!mc) {
 
5618
        display_pad_out("MC went away while fetching SEL time\n");
 
5619
        goto out;
 
5620
    }
 
5621
 
 
5622
    if (err) {
 
5623
        display_pad_out("Error fetching SEL time: %x\n", err);
 
5624
        goto out;
 
5625
    }
 
5626
 
 
5627
    display_pad_out("SEL time is 0x%x\n", time);
 
5628
 
 
5629
 out:
 
5630
    display_pad_refresh();
 
5631
}
 
5632
 
 
5633
void get_sel_time_handler(ipmi_mc_t *mc, void *cb_data)
 
5634
{
 
5635
    mccmd_info_t *info = cb_data;
 
5636
    int          rv;
 
5637
 
 
5638
    info->found = 1;
 
5639
    rv = ipmi_mc_get_current_sel_time(mc, sel_time_fetched, NULL);
 
5640
    if (rv)
 
5641
        cmd_win_out("Error sending SEL time fetch: %x\n", rv);
 
5642
}
 
5643
 
 
5644
int
 
5645
get_sel_time_cmd(char *cmd, char **toks, void *cb_data)
 
5646
{
 
5647
    mccmd_info_t  info;
 
5648
    int           rv;
 
5649
 
 
5650
    if (get_mc_id(toks, &info.mc_id))
 
5651
        return 0;
 
5652
 
 
5653
    info.found = 0;
 
5654
    rv = ipmi_mc_pointer_noseq_cb(info.mc_id, get_sel_time_handler, &info);
 
5655
    if (rv) {
 
5656
        cmd_win_out("Unable to find MC\n");
 
5657
        return 0;
 
5658
    }
 
5659
    if (!info.found) {
 
5660
        cmd_win_out("Unable to find MC (%d %x)\n",
 
5661
                    info.mc_id.channel, info.mc_id.mc_num);
 
5662
    }
 
5663
    display_pad_refresh();
 
5664
 
 
5665
    return 0;
 
5666
}
 
5667
 
 
5668
static void
 
5669
mc_reset_done(ipmi_mc_t *mc, int err, void *cb_data)
 
5670
{
 
5671
    if (err)
 
5672
        ui_log("Error resetting mc: %x", err);
 
5673
    else
 
5674
        ui_log("MC reset");
 
5675
}
 
5676
 
 
5677
static void
 
5678
mc_reset_handler(ipmi_mc_t *mc, void *cb_data)
 
5679
{
 
5680
    mccmd_info_t *info = cb_data;
 
5681
    int          rv;
 
5682
 
 
5683
    info->found = 1;
 
5684
    rv = ipmi_mc_reset(mc, info->msg.cmd, mc_reset_done, NULL);
 
5685
    if (rv)
 
5686
        cmd_win_out("Error sending MC reset: %x\n", rv);
 
5687
}
 
5688
 
 
5689
static int
 
5690
mc_reset_cmd(char *cmd, char **toks, void *cb_data)
 
5691
{
 
5692
    mccmd_info_t  info;
 
5693
    int           rv;
 
5694
    char          *type;
 
5695
 
 
5696
    if (get_mc_id(toks, &info.mc_id))
 
5697
        return 0;
 
5698
 
 
5699
    type = strtok_r(NULL, " \n\t", toks);
 
5700
    if (!type) {
 
5701
        cmd_win_out("No reset type given, must be 'cold' or 'warm'\n");
 
5702
        return 0;
 
5703
    }
 
5704
 
 
5705
    if (strcmp(type, "warm") == 0) {
 
5706
        info.msg.cmd = IPMI_MC_RESET_WARM;
 
5707
    } else if (strcmp(type, "cold") == 0) {
 
5708
        info.msg.cmd = IPMI_MC_RESET_COLD;
 
5709
    } else {
 
5710
        cmd_win_out("Invalid reset type given, must be 'cold' or 'warm'\n");
 
5711
        return 0;
 
5712
    }
 
5713
 
 
5714
    info.found = 0;
 
5715
    rv = ipmi_mc_pointer_noseq_cb(info.mc_id, mc_reset_handler, &info);
 
5716
    if (rv) {
 
5717
        cmd_win_out("Unable to find MC\n");
 
5718
        return 0;
 
5719
    }
 
5720
    if (!info.found) {
 
5721
        cmd_win_out("Unable to find MC (%d %x)\n",
 
5722
                    info.mc_id.channel, info.mc_id.mc_num);
 
5723
    }
 
5724
    display_pad_refresh();
 
5725
 
 
5726
    return 0;
 
5727
}
 
5728
 
 
5729
typedef struct sdrs_info_s
 
5730
{
 
5731
    int           found;
 
5732
    ipmi_mcid_t   mc_id;
 
5733
    unsigned char do_sensors;
 
5734
} sdrs_info_t;
 
5735
 
 
5736
void sdrs_fetched(ipmi_sdr_info_t *sdrs,
 
5737
                  int             err,
 
5738
                  int             changed,
 
5739
                  unsigned int    count,
 
5740
                  void            *cb_data)
 
5741
{
 
5742
    sdrs_info_t *info = cb_data;
 
5743
    int         i;
 
5744
    int         rv;
 
5745
    int         total_size = 0;
 
5746
 
 
5747
    if (err) {
 
5748
        ui_log("Error fetching sdrs: %x\n", err);
 
5749
        goto out;
 
5750
    }
 
5751
 
 
5752
    if (!sdrs) {
 
5753
        ui_log("sdrs went away during fetch\n");
 
5754
        goto out;
 
5755
    }
 
5756
 
 
5757
    display_pad_clear();
 
5758
    curr_display_type = DISPLAY_SDRS;
 
5759
 
 
5760
    display_pad_out("%s SDRs for MC (%x %x)\n",
 
5761
            info->do_sensors ? "device" : "main",
 
5762
            info->mc_id.channel, info->mc_id.mc_num);
 
5763
    for (i=0; i<count; i++) {
 
5764
        ipmi_sdr_t sdr;
 
5765
        int        j;
 
5766
 
 
5767
        rv = ipmi_get_sdr_by_index(sdrs, i, &sdr);
 
5768
        if (rv) {
 
5769
            display_pad_out("*could not get index %d\n", i);
 
5770
            continue;
 
5771
        }
 
5772
        total_size += sdr.length+5;
 
5773
        display_pad_out("%4.4x: type %x, version %d.%d",
 
5774
                sdr.record_id, sdr.type, sdr.major_version, sdr.minor_version);
 
5775
        for (j=0; j<sdr.length; j++) {
 
5776
            if ((j % 8) == 0)
 
5777
                display_pad_out("\n ");
 
5778
            display_pad_out(" %2.2x", sdr.data[j]);
 
5779
        }
 
5780
        display_pad_out("\n");
 
5781
    }
 
5782
    display_pad_out("total bytes in SDRs: %d\n", total_size);
 
5783
    display_pad_refresh();
 
5784
 
 
5785
 out:
 
5786
    ipmi_sdr_info_destroy(sdrs, NULL, NULL);
 
5787
    ipmi_mem_free(info);
 
5788
}
 
5789
 
 
5790
void
 
5791
start_sdr_dump(ipmi_mc_t *mc, sdrs_info_t *info)
 
5792
{
 
5793
    ipmi_sdr_info_t *sdrs;
 
5794
    int             rv;
 
5795
 
 
5796
    rv = ipmi_sdr_info_alloc(ipmi_mc_get_domain(mc),
 
5797
                             mc, 0, info->do_sensors, &sdrs);
 
5798
    if (rv) {
 
5799
        cmd_win_out("Unable to alloc sdr info: %x\n", rv);
 
5800
        ipmi_mem_free(info);
 
5801
        return;
 
5802
    }
 
5803
 
 
5804
    rv = ipmi_sdr_fetch(sdrs, sdrs_fetched, info);
 
5805
    if (rv) {
 
5806
        cmd_win_out("Unable to start SDR fetch: %x\n", rv);
 
5807
        ipmi_sdr_info_destroy(sdrs, NULL, NULL);
 
5808
        ipmi_mem_free(info);
 
5809
        return;
 
5810
    }
 
5811
}
 
5812
 
 
5813
void
 
5814
sdrs_mcs_handler(ipmi_mc_t *mc,
 
5815
                 void      *cb_data)
 
5816
{
 
5817
    sdrs_info_t *info = cb_data;
 
5818
 
 
5819
    info->found = 1;
 
5820
    start_sdr_dump(mc, info);
 
5821
}
 
5822
 
 
5823
static int
 
5824
sdrs_cmd(char *cmd, char **toks, void *cb_data)
 
5825
{
 
5826
    int           rv;
 
5827
    sdrs_info_t   *info;
 
5828
 
 
5829
    info = ipmi_mem_alloc(sizeof(*info));
 
5830
    if (!info) {
 
5831
        ui_log("Could not allocate memory for SDR fetch\n");
 
5832
        return 0;
 
5833
    }
 
5834
 
 
5835
    if (get_mc_id(toks, &info->mc_id)) {
 
5836
        ipmi_mem_free(info);
 
5837
        return 0;
 
5838
    }
 
5839
 
 
5840
    if (get_uchar(toks, &info->do_sensors, "do_sensors")) {
 
5841
        ipmi_mem_free(info);
 
5842
        return 0;
 
5843
    }
 
5844
 
 
5845
    info->found = 0;
 
5846
 
 
5847
    rv = ipmi_mc_pointer_noseq_cb(info->mc_id, sdrs_mcs_handler, info);
 
5848
    if (rv) {
 
5849
        cmd_win_out("Unable to find MC\n");
 
5850
        ipmi_mem_free(info);
 
5851
    } else {
 
5852
        if (!info->found) {
 
5853
            cmd_win_out("Unable to find that mc\n");
 
5854
            ipmi_mem_free(info);
 
5855
        }
 
5856
    }
 
5857
    return 0;
 
5858
}
 
5859
 
 
5860
typedef struct scan_cmd_info_s
 
5861
{
 
5862
    unsigned char addr;
 
5863
    unsigned char channel;
 
5864
} scan_cmd_info_t;
 
5865
 
 
5866
void scan_done(ipmi_domain_t *domain, int err, void *cb_data)
 
5867
{
 
5868
    log_pad_out("Bus scan done\n");
 
5869
}
 
5870
 
 
5871
static void
 
5872
scan_cmder(ipmi_domain_t *domain, void *cb_data)
 
5873
{
 
5874
    scan_cmd_info_t *info = cb_data;
 
5875
 
 
5876
    ipmi_start_ipmb_mc_scan(domain, info->channel,
 
5877
                            info->addr, info->addr,
 
5878
                            scan_done, NULL);
 
5879
}
 
5880
 
 
5881
static int
 
5882
scan_cmd(char *cmd, char **toks, void *cb_data)
 
5883
{
 
5884
    int             rv;
 
5885
    scan_cmd_info_t info;
 
5886
 
 
5887
    if (get_uchar(toks, &info.channel, "channel"))
 
5888
        return 0;
 
5889
 
 
5890
    if (get_uchar(toks, &info.addr, "IPMB address"))
 
5891
        return 0;
 
5892
 
 
5893
    rv = ipmi_domain_pointer_cb(domain_id, scan_cmder, &info);
 
5894
    if (rv) {
 
5895
        cmd_win_out("Unable to convert domain id to a pointer\n");
 
5896
    }
 
5897
    return 0;
 
5898
}
 
5899
 
 
5900
static void
 
5901
presence_cmder(ipmi_domain_t *domain, void *cb_data)
 
5902
{
 
5903
    int rv;
 
5904
 
 
5905
    rv = ipmi_detect_domain_presence_changes(domain, 1);
 
5906
    if (rv)
 
5907
        cmd_win_out("domain presence detect error: %x\n", rv);
 
5908
}
 
5909
 
 
5910
int
 
5911
presence_cmd(char *cmd, char **toks, void *cb_data)
 
5912
{
 
5913
    int rv;
 
5914
 
 
5915
    rv = ipmi_domain_pointer_cb(domain_id, presence_cmder, NULL);
 
5916
    if (rv) {
 
5917
        cmd_win_out("Unable to convert domain id to a pointer\n");
 
5918
        return 0;
 
5919
    }
 
5920
    
 
5921
    return 0;
 
5922
}
 
5923
 
 
5924
static void
 
5925
is_con_active_cmder(ipmi_domain_t *domain, void *cb_data)
 
5926
{
 
5927
    int          rv;
 
5928
    unsigned int *connection = cb_data;
 
5929
    unsigned int val;
 
5930
 
 
5931
    rv = ipmi_domain_is_connection_active(domain, *connection, &val);
 
5932
    if (rv)
 
5933
        cmd_win_out("Invalid connection number %d: %x\n", *connection, rv);
 
5934
    else
 
5935
        cmd_win_out("Connection %d is%s active\n",
 
5936
                    *connection, val ? "" : " not");
 
5937
}
 
5938
 
 
5939
static int
 
5940
is_con_active_cmd(char *cmd, char **toks, void *cb_data)
 
5941
{
 
5942
    int          rv;
 
5943
    unsigned int connection;
 
5944
 
 
5945
    if (get_uint(toks, &connection, "connection"))
 
5946
        return 0;
 
5947
 
 
5948
    rv = ipmi_domain_pointer_cb(domain_id, is_con_active_cmder, &connection);
 
5949
    if (rv) {
 
5950
        cmd_win_out("Unable to convert domain id to a pointer\n");
 
5951
        return 0;
 
5952
    }
 
5953
    
 
5954
    return 0;
 
5955
}
 
5956
 
 
5957
static void
 
5958
activate_con_cmder(ipmi_domain_t *domain, void *cb_data)
 
5959
{
 
5960
    int          rv;
 
5961
    unsigned int *connection = cb_data;
 
5962
 
 
5963
    rv = ipmi_domain_activate_connection(domain, *connection);
 
5964
    if (rv)
 
5965
        cmd_win_out("Invalid connection number %d: %x\n", *connection, rv);
 
5966
}
 
5967
 
 
5968
static int
 
5969
activate_con_cmd(char *cmd, char **toks, void *cb_data)
 
5970
{
 
5971
    int          rv;
 
5972
    unsigned int connection;
 
5973
 
 
5974
    if (get_uint(toks, &connection, "connection"))
 
5975
        return 0;
 
5976
 
 
5977
    rv = ipmi_domain_pointer_cb(domain_id, activate_con_cmder, &connection);
 
5978
    if (rv) {
 
5979
        cmd_win_out("Unable to convert domain id to a pointer\n");
 
5980
        return 0;
 
5981
    }
 
5982
    
 
5983
    return 0;
 
5984
}
 
5985
 
 
5986
static int
 
5987
quit_cmd(char *cmd, char **toks, void *cb_data)
 
5988
{
 
5989
    int rv;
 
5990
 
 
5991
    rv = ipmi_domain_pointer_cb(domain_id, leave_cmder, NULL);
 
5992
    if (rv) {
 
5993
        leave(0, "");
 
5994
    }
 
5995
    return 0;
 
5996
}
 
5997
 
 
5998
static int
 
5999
display_win_cmd(char *cmd, char **toks, void *cb_data)
 
6000
{
 
6001
    curr_win = DISPLAY_WIN_SCROLL;
 
6002
    return 0;
 
6003
}
 
6004
 
 
6005
static int
 
6006
log_win_cmd(char *cmd, char **toks, void *cb_data)
 
6007
{
 
6008
    curr_win = LOG_WIN_SCROLL;
 
6009
    return 0;
 
6010
}
 
6011
 
 
6012
static int
 
6013
new_domain_cmd(char *cmd, char **toks, void *cb_data)
 
6014
{
 
6015
    char         *parms[30];
 
6016
    int          num_parms;
 
6017
    unsigned int curr_parm;
 
6018
    ipmi_args_t  *con_parms[2];
 
6019
    int          set = 0;
 
6020
    int          i;
 
6021
    ipmi_con_t   *con[2];
 
6022
    int          rv;
 
6023
 
 
6024
    for (num_parms=0; num_parms<30; num_parms++) {
 
6025
        parms[num_parms] = strtok_r(NULL, " \t\n", toks);
 
6026
        if (!parms[num_parms])
 
6027
            break;
 
6028
        /* Remove surrounding quotes, if any. */
 
6029
        if (parms[num_parms][0] == '"') {
 
6030
            (parms[num_parms])++;
 
6031
            if (parms[num_parms][0])
 
6032
                parms[num_parms][strlen(parms[num_parms])-1] = '\0';
 
6033
        }
 
6034
    }
 
6035
 
 
6036
    if (num_parms < 2) {
 
6037
        cmd_win_out("Not enough parms given\n");
 
6038
        return 0;
 
6039
    }
 
6040
 
 
6041
    curr_parm = 1;
 
6042
    rv = ipmi_parse_args(&curr_parm, num_parms, parms, &con_parms[set]);
 
6043
    if (rv) {
 
6044
        cmd_win_out("First connection parms are invalid\n");
 
6045
        return 0;
 
6046
    }
 
6047
    set++;
 
6048
 
 
6049
    if (curr_parm > num_parms) {
 
6050
        rv = ipmi_parse_args(&curr_parm, num_parms, parms, &con_parms[set]);
 
6051
        if (rv) {
 
6052
            ipmi_free_args(con_parms[0]);
 
6053
            cmd_win_out("Second connection parms are invalid\n");
 
6054
            goto out;
 
6055
        }
 
6056
        set++;
 
6057
    }
 
6058
 
 
6059
    for (i=0; i<set; i++) {
 
6060
        rv = ipmi_args_setup_con(con_parms[i],
 
6061
                                 &ipmi_ui_cb_handlers,
 
6062
                                 ui_sel,
 
6063
                                 &con[i]);
 
6064
        if (rv) {
 
6065
            cmd_win_out("ipmi_ip_setup_con: %s\n", strerror(rv));
 
6066
            goto out;
 
6067
        }
 
6068
    }
 
6069
 
 
6070
    rv = ipmi_open_domain(parms[0], con, set, ipmi_ui_setup_done,
 
6071
                          NULL, NULL, NULL, NULL, 0, NULL);
 
6072
    if (rv) {
 
6073
        cmd_win_out("ipmi_open_domain: %s\n", strerror(rv));
 
6074
        for (i=0; i<set; i++)
 
6075
            con[i]->close_connection(con[i]);
 
6076
        goto out;
 
6077
    }
 
6078
 
 
6079
    cmd_win_out("Domain started\n");
 
6080
 out:
 
6081
    for (i=0; i<set; i++)
 
6082
        ipmi_free_args(con_parms[i]);
 
6083
 
 
6084
    return 0;
 
6085
 
 
6086
}
 
6087
 
 
6088
static void
 
6089
final_close(void *cb_data)
 
6090
{
 
6091
    ui_log("Domain close");
 
6092
}
 
6093
 
 
6094
typedef struct domain_scan_s
 
6095
{
 
6096
    int  err;
 
6097
    char *name;
 
6098
} domain_scan_t;
 
6099
 
 
6100
static void
 
6101
close_domain_handler(ipmi_domain_t *domain, void *cb_data)
 
6102
{
 
6103
    domain_scan_t *info = cb_data;
 
6104
    char name[IPMI_DOMAIN_NAME_LEN];
 
6105
 
 
6106
    ipmi_domain_get_name(domain, name, sizeof(name));
 
6107
    if (strcmp(name, info->name) == 0) {
 
6108
        /* Found it. */
 
6109
        info->err = ipmi_domain_close(domain, final_close, NULL);
 
6110
        if (info->err)
 
6111
            cmd_win_out("Could not close connection\n");
 
6112
    }
 
6113
}
 
6114
 
 
6115
 
 
6116
static int
 
6117
close_domain_cmd(char *cmd, char **toks, void *cb_data)
 
6118
{
 
6119
    domain_scan_t info;
 
6120
 
 
6121
    info.err = ENODEV;
 
6122
    info.name = strtok_r(NULL, " \t\n", toks);
 
6123
    if (!info.name) {
 
6124
        cmd_win_out("No domain given\n");
 
6125
        return 0;
 
6126
    }
 
6127
 
 
6128
    ipmi_domain_iterate_domains(close_domain_handler, &info);
 
6129
 
 
6130
    return 0;
 
6131
}
 
6132
 
 
6133
static void
 
6134
set_domain_handler(ipmi_domain_t *domain, void *cb_data)
 
6135
{
 
6136
    domain_scan_t *info = cb_data;
 
6137
    char name[IPMI_DOMAIN_NAME_LEN];
 
6138
 
 
6139
    ipmi_domain_get_name(domain, name, sizeof(name));
 
6140
    if (strcmp(name, info->name) == 0) {
 
6141
        /* Found it. */
 
6142
        info->err = 0;
 
6143
        domain_id = ipmi_domain_convert_to_id(domain);
 
6144
    }
 
6145
}
 
6146
 
 
6147
static int
 
6148
set_domain_cmd(char *cmd, char **toks, void *cb_data)
 
6149
{
 
6150
    domain_scan_t info;
 
6151
 
 
6152
    info.err = ENODEV;
 
6153
    info.name = strtok_r(NULL, " \t\n", toks);
 
6154
    if (!info.name) {
 
6155
        cmd_win_out("No domain given\n");
 
6156
        return 0;
 
6157
    }
 
6158
 
 
6159
    ipmi_domain_iterate_domains(set_domain_handler, &info);
 
6160
    if (info.err)
 
6161
        cmd_win_out("Error setting domain: 0x%x\n", info.err);
 
6162
 
 
6163
    return 0;
 
6164
}
 
6165
 
 
6166
static void
 
6167
domains_handler(ipmi_domain_t *domain, void *cb_data)
 
6168
{
 
6169
    char name[IPMI_DOMAIN_NAME_LEN];
 
6170
 
 
6171
    ipmi_domain_get_name(domain, name, sizeof(name));
 
6172
    display_pad_out("  %s\n", name);
 
6173
}
 
6174
 
 
6175
static int
 
6176
domains_cmd(char *cmd, char **toks, void *cb_data)
 
6177
{
 
6178
    display_pad_clear();
 
6179
    display_pad_out("Domains:\n");
 
6180
    ipmi_domain_iterate_domains(domains_handler, NULL);
 
6181
    display_pad_refresh();
 
6182
    
 
6183
    return 0;
 
6184
}
 
6185
 
 
6186
static int help_cmd(char *cmd, char **toks, void *cb_data);
 
6187
 
 
6188
static struct {
 
6189
    char          *name;
 
6190
    cmd_handler_t handler;
 
6191
    char          *help;
 
6192
} cmd_list[] =
 
6193
{
 
6194
    { "display_win",  display_win_cmd,
 
6195
      " - Sets the display window (left window) for scrolling" },
 
6196
    { "log_win",  log_win_cmd,
 
6197
      " - Sets the log window (right window) for scrolling" },
 
6198
    { "entities",       entities_cmd,
 
6199
      " - list all the entities the UI knows about" },
 
6200
    { "entity",         entity_cmd,
 
6201
      " <entity name> - list all the info about an entity" },
 
6202
    { "hs_get_act_time", hs_get_act_time,
 
6203
      " <entity name>"
 
6204
      " - Get the host-swap auto-activate time" },
 
6205
    { "hs_set_act_time", hs_set_act_time,
 
6206
      " <entity name> <time in nanoseconds>"
 
6207
      " - Set the host-swap auto-activate time" },
 
6208
    { "hs_get_deact_time", hs_get_deact_time,
 
6209
      " <entity name>"
 
6210
      " - Get the host-swap auto-deactivate time" },
 
6211
    { "hs_set_deact_time", hs_set_deact_time,
 
6212
      " <entity name> <time in nanoseconds>"
 
6213
      " - Set the host-swap auto-deactivate time" },
 
6214
    { "hs_activation_request", hs_activation_request,
 
6215
      " <entity name> - Act like a user requested an activation of the"
 
6216
      " entity.  This is generally equivalent to closing the handle"
 
6217
      " latch or something like that." },
 
6218
    { "hs_activate", hs_activate,
 
6219
      " <entity name> - activate the given entity" },
 
6220
    { "hs_deactivate", hs_deactivate,
 
6221
      " <entity name> - deactivate the given entity" },
 
6222
    { "hs_state", hs_state,
 
6223
      " <entity name> - Return the current hot-swap state" },
 
6224
    { "hs_check", hs_check_cmd,
 
6225
      " - Check all the entities hot-swap states" },
 
6226
    { "sensors",        sensors_cmd,
 
6227
      " <entity name> - list all the sensors that monitor the entity" },
 
6228
    { "sensor",         sensor_cmd,
 
6229
      " <sensor name> - Pull up all the information on the sensor and start"
 
6230
      " monitoring it" },
 
6231
    { "fru",            fru_cmd,
 
6232
      " <entity name> - dump fru information" },
 
6233
    { "dump_fru",       dump_fru_cmd,
 
6234
      " <is_logical> <device_address> <device_id> <lun> <private_bus>"
 
6235
      "  <channel> - dump a fru given all it's insundry information" },
 
6236
    { "rearm",          rearm_cmd,
 
6237
      " - rearm the current sensor" },
 
6238
    { "set_hysteresis", set_hysteresis_cmd,
 
6239
      " <val> - Sets the hysteresis for the current sensor" },
 
6240
    { "get_hysteresis", get_hysteresis_cmd,
 
6241
      " - Gets the hysteresis for the current sensor" },
 
6242
    { "controls",       controls_cmd,
 
6243
      " <entity name> - list all the controls attached to the entity" },
 
6244
    { "control",        control_cmd,
 
6245
      " <control name> - Pull up all the information on the control and start"
 
6246
      " monitoring it" },
 
6247
    { "set_control",    set_control_cmd,
 
6248
      " <val1> [<val2> ...] - set the value(s) for the control" },
 
6249
    { "mcs",            mcs_cmd,
 
6250
      " - List all the management controllers in the system.  They"
 
6251
      " are listed (<channel>, <mc num>)" },
 
6252
    { "mc",             mc_cmd,
 
6253
      " <channel> <mc num>"
 
6254
      " - Dump info on the given MC"},
 
6255
    { "mc_reset",       mc_reset_cmd,
 
6256
      " <channel> <mc num> [warm | cold]"
 
6257
      " - Do a warm or cold reset on the given MC"},
 
6258
    { "mccmd",          mccmd_cmd,
 
6259
      " <channel> <mc num> <LUN> <NetFN> <Cmd> [data...]"
 
6260
      " - Send the given command"
 
6261
      " to the management controller and display the response" },
 
6262
    { "mc_events_enable", mc_events_enable_cmd,
 
6263
      " <channel> <mc num> <enabled> - set enabled to 0 to disable events,"
 
6264
      " 1 to enable them.  This is the global event enable on the MC." },
 
6265
    { "mc_events_enabled", mc_events_enabled_cmd,
 
6266
      " <channel> <mc num> - Prints out if the events are enabled for"
 
6267
      " the given MC." },
 
6268
    { "msg",            msg_cmd,
 
6269
      " <channel> <IPMB addr> <LUN> <NetFN> <Cmd> [data...] - Send a command"
 
6270
      " to the given IPMB address on the given channel and display the"
 
6271
      " response" },
 
6272
    { "readpef",        readpef_cmd,
 
6273
      " <channel> <mc num>"
 
6274
      " - read pef information from an MC" },
 
6275
    { "clearpeflock",   clearpeflock_cmd,
 
6276
      " [<channel> <mc num>]"
 
6277
      " - Clear a PEF lock.  If the MC is given, then the PEF is directly"
 
6278
      " cleared.  If not given, then the current PEF is cleared" },
 
6279
    { "viewpef",        viewpef_cmd,
 
6280
      " - show current pef information " },
 
6281
    { "writepef",       writepef_cmd,
 
6282
      " <channel> <mc num>"
 
6283
      " - write the current PEF information to an MC" },
 
6284
    { "setpef",         setpef_cmd,
 
6285
      " <config> [<selector>] <value>"
 
6286
      " - Set the given config item to the value.  The optional selector"
 
6287
      " is used for items that take a selector" },
 
6288
    { "readlanparm",    readlanparm_cmd,
 
6289
      " <channel> <mc num> <channel>"
 
6290
      " - read lanparm information from an MC" },
 
6291
    { "viewlanparm",    viewlanparm_cmd,
 
6292
      " - show current lanparm information " },
 
6293
    { "writelanparm",   writelanparm_cmd,
 
6294
      " <channel> <mc num> <channel>"
 
6295
      " - write the current LANPARM information to an MC" },
 
6296
    { "clearlanparmlock",       clearlanparmlock_cmd,
 
6297
      " [<channel> <mc num> <channel>]"
 
6298
      " - Clear a LANPARM lock.  If the MC is given, then the LANPARM is"
 
6299
      " directly"
 
6300
      " cleared.  If not given, then the current LANPARM is cleared" },
 
6301
    { "setlanparm",     setlanparm_cmd,
 
6302
      " <config> [<selector>] <value>"
 
6303
      " - Set the given config item to the value.  The optional selector"
 
6304
      " is used for items that take a selector" },
 
6305
    { "pet",            pet_cmd,
 
6306
      " <connection> <channel> <ip addr> <mac_addr> <eft selector>"
 
6307
      " <policy num> <apt selector>"
 
6308
      " <lan dest selector> - "
 
6309
      "Set up the domain to send PET traps from the given connection"
 
6310
      " to the given IP/MAC address over the given channel" },
 
6311
    { "delevent",       delevent_cmd,
 
6312
      " <channel> <mc num> <log number> - "
 
6313
      "Delete the given event number from the SEL" },
 
6314
    { "addevent",       addevent_cmd,
 
6315
      " <channel> <mc num> <record id> <type> <13 bytes of data> - "
 
6316
      "Add the event data to the SEL" },
 
6317
    { "debug",          debug_cmd,
 
6318
      " <type> on|off - Turn the given debugging type on or off." },
 
6319
    { "clear_sel",      clear_sel_cmd,
 
6320
      " - clear the system event log" },
 
6321
    { "list_sel",       list_sel_cmd,
 
6322
      " - list the local copy of the system event log" },
 
6323
    { "get_sel_time",   get_sel_time_cmd,
 
6324
      " <channel> <mc num> - Get the time in the SEL for the given MC" },
 
6325
    { "sdrs",           sdrs_cmd,
 
6326
      " <channel> <mc num> <do_sensors> - list the SDRs for the mc."
 
6327
      "  If do_sensors is"
 
6328
      " 1, then the device SDRs are fetched.  Otherwise the main SDRs are"
 
6329
      " fetched." },
 
6330
    { "events_enable",  events_enable_cmd,
 
6331
      " <events> <scanning> <assertion bitmask> <deassertion bitmask>"
 
6332
      " - set the events enable data for the sensor" },
 
6333
    { "scan",  scan_cmd,
 
6334
      " <ipmb addr> - scan an IPMB to add or remove it" },
 
6335
    { "is_con_active",  is_con_active_cmd,
 
6336
      " <connection> - print out if the given connection is active or not" },
 
6337
    { "activate_con",  activate_con_cmd,
 
6338
      " <connection> - Activate the given connection" },
 
6339
    { "quit",  quit_cmd,
 
6340
      " - leave the program" },
 
6341
    { "check_presence", presence_cmd,
 
6342
      " - Check the presence of entities" },
 
6343
    { "new_domain", new_domain_cmd,
 
6344
      " <domain name> <parms...> - Open a connection to a new domain" },
 
6345
    { "close_domain", close_domain_cmd,
 
6346
      " <num> - close the given domain number" },
 
6347
    { "set_domain", set_domain_cmd,
 
6348
      " <num> - Use the given domain number" },
 
6349
    { "domains", domains_cmd,
 
6350
      " - List all the domains" },
 
6351
    { "help",           help_cmd,
 
6352
      " - This output"},
 
6353
    { NULL,             NULL}
 
6354
};
 
6355
int
 
6356
init_commands(void)
 
6357
{
 
6358
    int err;
 
6359
    int i;
 
6360
 
 
6361
    commands = command_alloc();
 
6362
    if (!commands)
 
6363
        return ENOMEM;
 
6364
 
 
6365
    for (i=0; cmd_list[i].name != NULL; i++) {
 
6366
        err = command_bind(commands, cmd_list[i].name, cmd_list[i].handler);
 
6367
        if (err)
 
6368
            goto out_err;
 
6369
    }
 
6370
 
 
6371
    return 0;
 
6372
 
 
6373
 out_err:
 
6374
    command_free(commands);
 
6375
    return err;
 
6376
}
 
6377
 
 
6378
static int
 
6379
help_cmd(char *cmd, char **toks, void *cb_data)
 
6380
{
 
6381
    int i;
 
6382
 
 
6383
    display_pad_clear();
 
6384
    curr_display_type = HELP;
 
6385
    display_pad_out("Welcome to the IPMI UI version %s\n", OPENIPMI_VERSION);
 
6386
    for (i=0; cmd_list[i].name != NULL; i++) {
 
6387
        display_pad_out("  %s%s\n", cmd_list[i].name, cmd_list[i].help);
 
6388
    }
 
6389
    display_pad_refresh();
 
6390
 
 
6391
    return 0;
 
6392
}
 
6393
 
 
6394
int
 
6395
init_keypad(void)
 
6396
{
 
6397
    int i;
 
6398
    int err = 0;
 
6399
 
 
6400
    keymap = keypad_alloc();
 
6401
    if (!keymap)
 
6402
        return ENOMEM;
 
6403
 
 
6404
    for (i=0x20; i<0x7f; i++) {
 
6405
        err = keypad_bind_key(keymap, i, normal_char);
 
6406
        if (err)
 
6407
            goto out_err;
 
6408
    }
 
6409
 
 
6410
    err = keypad_bind_key(keymap, 0x7f, backspace);
 
6411
    if (!err)
 
6412
      err = keypad_bind_key(keymap, 9, normal_char);
 
6413
    if (!err)
 
6414
      err = keypad_bind_key(keymap, 8, backspace);
 
6415
    if (!err)
 
6416
        err = keypad_bind_key(keymap, 4, key_leave);
 
6417
    if (!err)
 
6418
        err = keypad_bind_key(keymap, 10, end_of_line);
 
6419
    if (!err)
 
6420
        err = keypad_bind_key(keymap, 13, end_of_line);
 
6421
    if (full_screen) {
 
6422
        if (!err)
 
6423
            err = keypad_bind_key(keymap, KEY_BACKSPACE, backspace);
 
6424
        if (!err)
 
6425
            err = keypad_bind_key(keymap, KEY_DC, backspace);
 
6426
        if (!err)
 
6427
            err = keypad_bind_key(keymap, KEY_UP, key_up);
 
6428
        if (!err)
 
6429
            err = keypad_bind_key(keymap, KEY_DOWN, key_down);
 
6430
        if (!err)
 
6431
            err = keypad_bind_key(keymap, KEY_RIGHT, key_right);
 
6432
        if (!err)
 
6433
            err = keypad_bind_key(keymap, KEY_LEFT, key_left);
 
6434
        if (!err)
 
6435
            err = keypad_bind_key(keymap, KEY_NPAGE, key_npage);
 
6436
        if (!err)
 
6437
            err = keypad_bind_key(keymap, KEY_PPAGE, key_ppage);
 
6438
        if (!err)
 
6439
            err = keypad_bind_key(keymap, KEY_RESIZE, key_resize);
 
6440
        if (!err)
 
6441
            err = keypad_bind_key(keymap, KEY_F(1), key_set_display);
 
6442
        if (!err)
 
6443
            err = keypad_bind_key(keymap, KEY_F(2), key_set_log);
 
6444
    } else {
 
6445
        if (!err)
 
6446
            err = keypad_bind_key(keymap, -1, key_leave);
 
6447
    }
 
6448
    if (err)
 
6449
        goto out_err;
 
6450
 
 
6451
    return 0;
 
6452
 
 
6453
 out_err:
 
6454
    keypad_free(keymap);
 
6455
    return err;
 
6456
}
 
6457
 
 
6458
int
 
6459
init_win(void)
 
6460
{
 
6461
    main_win = initscr();
 
6462
    if (!main_win)
 
6463
        exit(1);
 
6464
 
 
6465
    raw();
 
6466
    noecho();
 
6467
 
 
6468
    stat_win = newwin(STATUS_WIN_LINES, STATUS_WIN_COLS,
 
6469
                      STATUS_WIN_TOP, STATUS_WIN_LEFT);
 
6470
    if (!stat_win)
 
6471
        leave(1, "Could not allocate stat window\n");
 
6472
 
 
6473
    display_pad = newpad(NUM_DISPLAY_LINES, DISPLAY_WIN_COLS);
 
6474
    if (!display_pad)
 
6475
        leave(1, "Could not allocate display window\n");
 
6476
 
 
6477
    log_pad = newpad(NUM_LOG_LINES, LOG_WIN_COLS);
 
6478
    if (!log_pad)
 
6479
        leave(1, "Could not allocate log window\n");
 
6480
    scrollok(log_pad, TRUE);
 
6481
    wmove(log_pad, NUM_LOG_LINES-1, 0);
 
6482
    log_pad_top_line = NUM_LOG_LINES-LOG_WIN_LINES;
 
6483
 
 
6484
    dummy_pad = newpad(NUM_LOG_LINES, LOG_WIN_COLS);
 
6485
    if (!dummy_pad)
 
6486
        leave(1, "Could not allocate dummy pad\n");
 
6487
    wmove(dummy_pad, 0, 0);
 
6488
 
 
6489
    cmd_win = newwin(CMD_WIN_LINES, CMD_WIN_COLS, CMD_WIN_TOP, CMD_WIN_LEFT);
 
6490
    if (!cmd_win)
 
6491
        leave(1, "Could not allocate command window\n");
 
6492
 
 
6493
    keypad(cmd_win, TRUE);
 
6494
    meta(cmd_win, TRUE);
 
6495
    nodelay(cmd_win, TRUE);
 
6496
    scrollok(cmd_win, TRUE);
 
6497
 
 
6498
    draw_lines();
 
6499
 
 
6500
    display_pad_refresh();
 
6501
 
 
6502
    cmd_win_out("> ");
 
6503
    cmd_win_refresh();
 
6504
 
 
6505
    return 0;
 
6506
}
 
6507
 
 
6508
static void
 
6509
report_error(char *str, int err)
 
6510
{
 
6511
    if (IPMI_IS_OS_ERR(err)) {
 
6512
        ui_log("%s: %s\n", str, strerror(IPMI_GET_OS_ERR(err)));
 
6513
    } else {
 
6514
        ui_log("%s: IPMI Error %2.2x\n",
 
6515
               str, IPMI_GET_IPMI_ERR(err));
 
6516
    }
 
6517
}
 
6518
 
 
6519
static int
 
6520
sensor_threshold_event_handler(ipmi_sensor_t               *sensor,
 
6521
                               enum ipmi_event_dir_e       dir,
 
6522
                               enum ipmi_thresh_e          threshold,
 
6523
                               enum ipmi_event_value_dir_e high_low,
 
6524
                               enum ipmi_value_present_e   value_present,
 
6525
                               unsigned int                raw_value,
 
6526
                               double                      value,
 
6527
                               void                        *cb_data,
 
6528
                               ipmi_event_t                *event)
 
6529
{
 
6530
    ipmi_entity_t *entity = ipmi_sensor_get_entity(sensor);
 
6531
    char          loc[MAX_ENTITY_LOC_SIZE];
 
6532
    char          name[33];
 
6533
 
 
6534
    ipmi_sensor_get_id(sensor, name, 33);
 
6535
    ui_log("Sensor %s.%s: %s %s %s\n",
 
6536
           get_entity_loc(entity, loc, sizeof(loc)),
 
6537
           name,
 
6538
           ipmi_get_threshold_string(threshold),
 
6539
           ipmi_get_value_dir_string(high_low),
 
6540
           ipmi_get_event_dir_string(dir));
 
6541
    if (value_present == IPMI_BOTH_VALUES_PRESENT) {
 
6542
        ui_log("  value is %f (%2.2x)\n", value, raw_value);
 
6543
    } else if (value_present == IPMI_RAW_VALUE_PRESENT) {
 
6544
        ui_log("  raw value is 0x%x\n", raw_value);
 
6545
    }
 
6546
    if (event)
 
6547
        ui_log("Due to event 0x%4.4x\n", ipmi_event_get_record_id(event));
 
6548
    return IPMI_EVENT_NOT_HANDLED;
 
6549
}
 
6550
 
 
6551
static int
 
6552
sensor_discrete_event_handler(ipmi_sensor_t         *sensor,
 
6553
                              enum ipmi_event_dir_e dir,
 
6554
                              int                   offset,
 
6555
                              int                   severity,
 
6556
                              int                   prev_severity,
 
6557
                              void                  *cb_data,
 
6558
                              ipmi_event_t          *event)
 
6559
{
 
6560
    ipmi_entity_t *entity = ipmi_sensor_get_entity(sensor);
 
6561
    char          loc[MAX_ENTITY_LOC_SIZE];
 
6562
    char          name[33];
 
6563
 
 
6564
    ipmi_sensor_get_id(sensor, name, 33);
 
6565
    ui_log("Sensor %s.%s: %d %s\n",
 
6566
           get_entity_loc(entity, loc, sizeof(loc)),
 
6567
           name,
 
6568
           offset,
 
6569
           ipmi_get_event_dir_string(dir));
 
6570
    if (severity != -1)
 
6571
        ui_log("  severity is %d\n", severity);
 
6572
    if (prev_severity != -1)
 
6573
        ui_log("  prev severity is %d\n", prev_severity);
 
6574
    if (event)
 
6575
        ui_log("Due to event 0x%4.4x\n", ipmi_event_get_record_id(event));
 
6576
    return IPMI_EVENT_NOT_HANDLED;
 
6577
}
 
6578
 
 
6579
static void
 
6580
sensor_change(enum ipmi_update_e op,
 
6581
              ipmi_entity_t      *ent,
 
6582
              ipmi_sensor_t      *sensor,
 
6583
              void               *cb_data)
 
6584
{
 
6585
    ipmi_entity_t *entity = ipmi_sensor_get_entity(sensor);
 
6586
    char          loc[MAX_ENTITY_LOC_SIZE];
 
6587
    char          name[33];
 
6588
    char          name2[33];
 
6589
    int           rv;
 
6590
 
 
6591
    ipmi_sensor_get_id(sensor, name, 32);
 
6592
    strcpy(name2, name);
 
6593
    conv_from_spaces(name2);
 
6594
    switch (op) {
 
6595
        case IPMI_ADDED:
 
6596
            ui_log("Sensor added: %s.%s (%s)\n",
 
6597
                   get_entity_loc(entity, loc, sizeof(loc)),
 
6598
                   name2, name);
 
6599
            if (ipmi_sensor_get_event_reading_type(sensor)
 
6600
                == IPMI_EVENT_READING_TYPE_THRESHOLD)
 
6601
                rv = ipmi_sensor_add_threshold_event_handler(
 
6602
                    sensor,
 
6603
                    sensor_threshold_event_handler,
 
6604
                    NULL);
 
6605
            else
 
6606
                rv = ipmi_sensor_add_discrete_event_handler(
 
6607
                    sensor,
 
6608
                    sensor_discrete_event_handler,
 
6609
                    NULL);
 
6610
            if (rv)
 
6611
                ui_log("Unable to register sensor event handler: 0x%x\n", rv);
 
6612
            break;
 
6613
        case IPMI_DELETED:
 
6614
            ui_log("Sensor deleted: %s.%s (%s)\n",
 
6615
                   get_entity_loc(entity, loc, sizeof(loc)),
 
6616
                   name2, name);
 
6617
            break;
 
6618
        case IPMI_CHANGED:
 
6619
            ui_log("Sensor changed: %s.%s (%s)\n",
 
6620
                   get_entity_loc(entity, loc, sizeof(loc)),
 
6621
                   name2, name);
 
6622
            break;
 
6623
    }
 
6624
}
 
6625
 
 
6626
static void
 
6627
control_change(enum ipmi_update_e op,
 
6628
               ipmi_entity_t      *ent,
 
6629
               ipmi_control_t     *control,
 
6630
               void               *cb_data)
 
6631
{
 
6632
    ipmi_entity_t *entity = ipmi_control_get_entity(control);
 
6633
    char          loc[MAX_ENTITY_LOC_SIZE];
 
6634
    char          name[33];
 
6635
    char          name2[33];
 
6636
 
 
6637
    ipmi_control_get_id(control, name, 32);
 
6638
    strcpy(name2, name);
 
6639
    conv_from_spaces(name2);
 
6640
    switch (op) {
 
6641
        case IPMI_ADDED:
 
6642
            ui_log("Control added: %s.%s (%s)\n",
 
6643
                   get_entity_loc(entity, loc, sizeof(loc)),
 
6644
                   name2, name);
 
6645
            break;
 
6646
        case IPMI_DELETED:
 
6647
            ui_log("Control deleted: %s.%s (%s)\n",
 
6648
                   get_entity_loc(entity, loc, sizeof(loc)),
 
6649
                   name2, name);
 
6650
            break;
 
6651
        case IPMI_CHANGED:
 
6652
            ui_log("Control changed: %s.%s (%s)\n",
 
6653
                   get_entity_loc(entity, loc, sizeof(loc)),
 
6654
                   name2, name);
 
6655
            break;
 
6656
    }
 
6657
}
 
6658
 
 
6659
static int
 
6660
entity_presence_handler(ipmi_entity_t *entity,
 
6661
                        int           present,
 
6662
                        void          *cb_data,
 
6663
                        ipmi_event_t  *event)
 
6664
{
 
6665
    char loc[MAX_ENTITY_LOC_SIZE];
 
6666
 
 
6667
    ui_log("Entity %s, presence is %d\n",
 
6668
           get_entity_loc(entity, loc, sizeof(loc)),
 
6669
           present);
 
6670
    if (event)
 
6671
        ui_log("Due to event 0x%4.4x\n", ipmi_event_get_record_id(event));
 
6672
    return IPMI_EVENT_NOT_HANDLED;
 
6673
}
 
6674
 
 
6675
void fru_change(enum ipmi_update_e op,
 
6676
                ipmi_entity_t      *entity,
 
6677
                void               *cb_data)
 
6678
{
 
6679
    char loc[MAX_ENTITY_LOC_SIZE];
 
6680
 
 
6681
    switch (op) {
 
6682
        case IPMI_ADDED:
 
6683
            ui_log("FRU added for %s\n",
 
6684
                   get_entity_loc(entity, loc, sizeof(loc)));
 
6685
            break;
 
6686
        case IPMI_DELETED:
 
6687
            ui_log("FRU deleted for %s\n",
 
6688
                   get_entity_loc(entity, loc, sizeof(loc)));
 
6689
            break;
 
6690
        case IPMI_CHANGED:
 
6691
            ui_log("FRU changed for %s\n",
 
6692
                   get_entity_loc(entity, loc, sizeof(loc)));
 
6693
            break;
 
6694
    }
 
6695
}
 
6696
 
 
6697
static int
 
6698
entity_hot_swap_handler(ipmi_entity_t             *ent,
 
6699
                        enum ipmi_hot_swap_states last_state,
 
6700
                        enum ipmi_hot_swap_states curr_state,
 
6701
                        void                      *cb_data,
 
6702
                        ipmi_event_t              *event)
 
6703
{
 
6704
    char loc[MAX_ENTITY_LOC_SIZE];
 
6705
 
 
6706
    ui_log("Entity hot swap state changed for %s, was %s, now %s\n",
 
6707
           get_entity_loc(ent, loc, sizeof(loc)),
 
6708
           ipmi_hot_swap_state_name(last_state),
 
6709
           ipmi_hot_swap_state_name(curr_state));
 
6710
    return IPMI_EVENT_NOT_HANDLED;
 
6711
}
 
6712
 
 
6713
static void
 
6714
entity_change(enum ipmi_update_e op,
 
6715
              ipmi_domain_t      *domain,
 
6716
              ipmi_entity_t      *entity,
 
6717
              void               *cb_data)
 
6718
{
 
6719
    int rv;
 
6720
    char loc[MAX_ENTITY_LOC_SIZE];
 
6721
 
 
6722
    switch (op) {
 
6723
        case IPMI_ADDED:
 
6724
            ui_log("Entity added: %s\n",
 
6725
                   get_entity_loc(entity, loc, sizeof(loc)));
 
6726
            rv = ipmi_entity_add_sensor_update_handler(entity,
 
6727
                                                       sensor_change,
 
6728
                                                       entity);
 
6729
            if (rv) {
 
6730
                report_error("ipmi_entity_add_sensor_update_handler", rv);
 
6731
                break;
 
6732
            }
 
6733
            rv = ipmi_entity_add_control_update_handler(entity,
 
6734
                                                        control_change,
 
6735
                                                        entity);
 
6736
            if (rv) {
 
6737
                report_error("ipmi_entity_add_control_update_handler", rv);
 
6738
                break;
 
6739
            }
 
6740
            rv = ipmi_entity_add_fru_update_handler(entity,
 
6741
                                                    fru_change,
 
6742
                                                    entity);
 
6743
            if (rv) {
 
6744
                report_error("ipmi_entity_add_control_fru_handler", rv);
 
6745
                break;
 
6746
            }
 
6747
            rv = ipmi_entity_add_presence_handler(entity,
 
6748
                                                  entity_presence_handler,
 
6749
                                                  NULL);
 
6750
            if (rv) {
 
6751
                report_error("ipmi_entity_add_presence_handler", rv);
 
6752
            }
 
6753
            rv = ipmi_entity_add_hot_swap_handler(entity,
 
6754
                                                  entity_hot_swap_handler,
 
6755
                                                  NULL);
 
6756
            if (rv) {
 
6757
                report_error("ipmi_entity_add_hot_swap_handler", rv);
 
6758
            }
 
6759
            break;
 
6760
        case IPMI_DELETED:
 
6761
            ui_log("Entity deleted: %s\n",
 
6762
                   get_entity_loc(entity, loc, sizeof(loc)));
 
6763
            break;
 
6764
        case IPMI_CHANGED:
 
6765
            ui_log("Entity changed: %s\n",
 
6766
                   get_entity_loc(entity, loc, sizeof(loc)));
 
6767
            break;
 
6768
    }
 
6769
 
 
6770
    if (ipmi_entity_hot_swappable(entity))
 
6771
        ui_log("Entity is hot swappable\n");
 
6772
    else
 
6773
        ui_log("Entity is not hot swappable\n");
 
6774
}
 
6775
 
 
6776
static void
 
6777
mc_sels_read(ipmi_mc_t *mc, void *cb_data)
 
6778
{
 
6779
    int addr = ipmi_mc_get_address(mc);
 
6780
    int channel = ipmi_mc_get_channel(mc);
 
6781
 
 
6782
    ui_log("MC (%d %x) SELs read\n", channel, addr);
 
6783
}
 
6784
 
 
6785
static void
 
6786
mc_sdrs_read(ipmi_mc_t *mc, void *cb_data)
 
6787
{
 
6788
    int addr = ipmi_mc_get_address(mc);
 
6789
    int channel = ipmi_mc_get_channel(mc);
 
6790
 
 
6791
    ui_log("MC (%d %x) SDRs read\n", channel, addr);
 
6792
}
 
6793
 
 
6794
static void
 
6795
mc_active(ipmi_mc_t *mc, int active, void *cb_data)
 
6796
{
 
6797
    int addr = ipmi_mc_get_address(mc);
 
6798
    int channel = ipmi_mc_get_channel(mc);
 
6799
 
 
6800
    ui_log("MC is %s: (%d %x)\n",
 
6801
           active ? "active" : "inactive",
 
6802
           channel, addr);
 
6803
    ipmi_mc_set_sdrs_first_read_handler(mc, mc_sdrs_read, NULL);
 
6804
    ipmi_mc_set_sels_first_read_handler(mc, mc_sels_read, NULL);
 
6805
}
 
6806
 
 
6807
static void
 
6808
mc_change(enum ipmi_update_e op,
 
6809
          ipmi_domain_t      *domain,
 
6810
          ipmi_mc_t          *mc,
 
6811
          void               *cb_data)
 
6812
{
 
6813
    int addr = ipmi_mc_get_address(mc);
 
6814
    int channel = ipmi_mc_get_channel(mc);
 
6815
    int rv;
 
6816
 
 
6817
    switch (op) {
 
6818
        case IPMI_ADDED:
 
6819
            rv = ipmi_mc_add_active_handler(mc, mc_active, NULL);
 
6820
            if (rv)
 
6821
                ui_log("Unable to add MC active handler: 0x%x\n", rv);
 
6822
            if (ipmi_mc_is_active(mc)) {
 
6823
                ipmi_mc_set_sdrs_first_read_handler(mc, mc_sdrs_read, NULL);
 
6824
                ipmi_mc_set_sels_first_read_handler(mc, mc_sels_read, NULL);
 
6825
                ui_log("MC added: (%d %x) - (active)\n", channel, addr);
 
6826
            } else {
 
6827
                ui_log("MC added: (%d %x) - (inactive)\n", channel, addr);
 
6828
            }
 
6829
            break;
 
6830
        case IPMI_DELETED:
 
6831
            ui_log("MC deleted: (%d %x)\n", channel, addr);
 
6832
            break;
 
6833
        case IPMI_CHANGED:
 
6834
            ui_log("MC changed: (%d %x)\n", channel, addr);
 
6835
            break;
 
6836
    }
 
6837
}
 
6838
 
 
6839
static void
 
6840
event_handler(ipmi_domain_t *domain,
 
6841
              ipmi_event_t  *event,
 
6842
              void          *event_data)
 
6843
{
 
6844
    ipmi_mcid_t   mcid = ipmi_event_get_mcid(event);
 
6845
    unsigned int  record_id = ipmi_event_get_record_id(event);
 
6846
    unsigned int  type = ipmi_event_get_type(event);
 
6847
    ipmi_time_t   timestamp = ipmi_event_get_timestamp(event);
 
6848
    unsigned int  data_len = ipmi_event_get_data_len(event);
 
6849
    unsigned char *data = ipmi_event_get_data_ptr(event);
 
6850
    int           i;
 
6851
    char          str[200];
 
6852
    int           pos;
 
6853
 
 
6854
    pos = 0;
 
6855
    for (i=0; i<data_len; i++)
 
6856
        pos += snprintf(str+pos, 200-pos, " %2.2x", data[i]);
 
6857
 
 
6858
    ui_log("Unknown event from mc (%x %x)\n"
 
6859
           "%4.4x:%2.2x %lld: %s\n",
 
6860
           mcid.channel, mcid.mc_num, record_id, type, (int64_t) timestamp,
 
6861
           str); 
 
6862
}
 
6863
 
 
6864
static void
 
6865
redisplay_timeout(selector_t  *sel,
 
6866
                  sel_timer_t *timer,
 
6867
                  void        *data)
 
6868
{
 
6869
    struct timeval now;
 
6870
    int            rv;
 
6871
 
 
6872
    if (!full_screen)
 
6873
        return;
 
6874
 
 
6875
    if (curr_display_type == DISPLAY_ENTITIES) {
 
6876
        rv = ipmi_domain_pointer_cb(domain_id, entities_cmder, &rv);
 
6877
        if (rv)
 
6878
            ui_log("redisplay_timeout:"
 
6879
                   " Unable to convert BMC id to a pointer\n");
 
6880
    } else if (curr_display_type == DISPLAY_SENSOR) {
 
6881
        rv = ipmi_sensor_pointer_cb(curr_sensor_id, redisplay_sensor, NULL);
 
6882
        if (rv)
 
6883
            ui_log("redisplay_timeout: Unable to get sensor pointer: 0x%x\n",
 
6884
                   rv);
 
6885
    } else if (curr_display_type == DISPLAY_CONTROL) {
 
6886
        rv = ipmi_control_pointer_cb(curr_control_id, redisplay_control, NULL);
 
6887
        if (rv)
 
6888
            ui_log("redisplay_timeout: Unable to get sensor pointer: 0x%x\n",
 
6889
                   rv);
 
6890
    }
 
6891
 
 
6892
    gettimeofday(&now, NULL);
 
6893
    now.tv_sec += 1;
 
6894
    rv = sel_start_timer(timer, &now);
 
6895
    if (rv)
 
6896
        ui_log("Unable to restart redisplay timer: 0x%x\n", rv);
 
6897
}
 
6898
 
 
6899
void
 
6900
ipmi_ui_setup_done(ipmi_domain_t *domain,
 
6901
                   int           err,
 
6902
                   unsigned int  conn_num,
 
6903
                   unsigned int  port_num,
 
6904
                   int           still_connected,
 
6905
                   void          *cb_data)
 
6906
{
 
6907
    int rv;
 
6908
 
 
6909
    if (err)
 
6910
        ui_log("IPMI connection to con.port %d.%d is down"
 
6911
               "  due to error 0x%x\n",
 
6912
               conn_num, port_num, err);
 
6913
    else
 
6914
        ui_log("IPMI connection to con.port %d.%d is up\n",
 
6915
               conn_num, port_num);
 
6916
 
 
6917
    if (!still_connected) {
 
6918
        ui_log("All IPMI connections down\n");
 
6919
        return;
 
6920
    }
 
6921
 
 
6922
    domain_id = ipmi_domain_convert_to_id(domain);
 
6923
 
 
6924
    rv = ipmi_domain_add_event_handler(domain, event_handler, NULL);
 
6925
    if (rv)
 
6926
        leave_err(rv, "ipmi_register_for_events");
 
6927
 
 
6928
    rv = ipmi_domain_enable_events(domain);
 
6929
    if (rv)
 
6930
        leave_err(rv, "ipmi_domain_enable_events");
 
6931
 
 
6932
    rv = ipmi_domain_add_entity_update_handler(domain, entity_change, domain);
 
6933
    if (rv)
 
6934
        leave_err(rv, "ipmi_bmc_set_entity_update_handler");
 
6935
 
 
6936
    rv = ipmi_domain_add_mc_updated_handler(domain, mc_change, domain);
 
6937
    if (rv)
 
6938
        leave_err(rv, "ipmi_bmc_set_entity_update_handler");
 
6939
    pef = NULL;
 
6940
    lanparm = NULL;
 
6941
}
 
6942
 
 
6943
void
 
6944
ipmi_ui_domain_ready(ipmi_domain_t *domain,
 
6945
                     int           err,
 
6946
                     unsigned int  conn_num,
 
6947
                     unsigned int  port_num,
 
6948
                     int           still_connected,
 
6949
                     void          *user_data)
 
6950
{
 
6951
}
 
6952
 
 
6953
int
 
6954
ipmi_ui_init(selector_t **selector, int do_full_screen)
 
6955
{
 
6956
    int rv;
 
6957
 
 
6958
    full_screen = do_full_screen;
 
6959
 
 
6960
    rv = sel_alloc_selector(&ipmi_ui_cb_handlers, &ui_sel);
 
6961
    if (rv) {
 
6962
        fprintf(stderr, "Could not allocate selector\n");
 
6963
        exit(1);
 
6964
    }
 
6965
 
 
6966
    sel_set_fd_handlers(ui_sel, 0, NULL, user_input_ready, NULL, NULL, NULL);
 
6967
    sel_set_fd_read_handler(ui_sel, 0, SEL_FD_HANDLER_ENABLED);
 
6968
 
 
6969
    ipmi_init(&ipmi_ui_cb_handlers);
 
6970
 
 
6971
    /* This is a dummy allocation just to make sure that the malloc
 
6972
       debugger is working. */
 
6973
    ipmi_mem_alloc(10);
 
6974
 
 
6975
    sensor_states = ipmi_mem_alloc(ipmi_states_size());
 
6976
    if (!sensor_states) {
 
6977
        fprintf(stderr, "Could not allocate sensor states\n");
 
6978
        exit(1);
 
6979
    }
 
6980
 
 
6981
    sensor_event_states = ipmi_mem_alloc(ipmi_event_state_size());
 
6982
    if (!sensor_event_states) {
 
6983
        fprintf(stderr, "Could not allocate sensor event states\n");
 
6984
        exit(1);
 
6985
    }
 
6986
 
 
6987
    sensor_thresholds = ipmi_mem_alloc(ipmi_thresholds_size());
 
6988
    if (!sensor_thresholds) {
 
6989
        fprintf(stderr, "Could not allocate sensor thresholds\n");
 
6990
        exit(1);
 
6991
    }
 
6992
 
 
6993
    rv = init_commands();
 
6994
    if (rv) {
 
6995
        fprintf(stderr, "Could not initialize commands\n");
 
6996
        exit(1);
 
6997
    }
 
6998
 
 
6999
    rv = init_keypad();
 
7000
    if (rv) {
 
7001
        fprintf(stderr, "Could not initialize keymap\n");
 
7002
        exit(1);
 
7003
    }
 
7004
 
 
7005
    if (full_screen) {
 
7006
        rv = init_win();
 
7007
        if (rv) {
 
7008
            fprintf(stderr, "Could not initialize curses\n");
 
7009
            exit(1);
 
7010
        }
 
7011
    } else {
 
7012
        struct termios new_termios;
 
7013
 
 
7014
        tcgetattr(0, &old_termios);
 
7015
        new_termios = old_termios;
 
7016
        new_termios.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
 
7017
                                 |INLCR|IGNCR|ICRNL|IXON);
 
7018
        new_termios.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
 
7019
        tcsetattr(0, TCSADRAIN, &new_termios);
 
7020
        old_flags = fcntl(0, F_GETFL) & O_ACCMODE;
 
7021
//      fcntl(0, F_SETFL, old_flags | O_NONBLOCK);
 
7022
    }
 
7023
 
 
7024
    help_cmd(NULL, NULL, NULL);
 
7025
 
 
7026
    ui_log("Starting setup, wait until complete before entering commands.\n");
 
7027
 
 
7028
    {
 
7029
        struct timeval now;
 
7030
        rv = sel_alloc_timer(ui_sel, redisplay_timeout, NULL,
 
7031
                             &redisplay_timer);
 
7032
        if (rv)
 
7033
            leave_err(rv, "sel_alloc_timer");
 
7034
        gettimeofday(&now, NULL);
 
7035
        now.tv_sec += 1;
 
7036
        rv = sel_start_timer(redisplay_timer, &now);
 
7037
        if (rv)
 
7038
            leave_err(rv, "Unable to restart redisplay timer");
 
7039
    }
 
7040
 
 
7041
    *selector = ui_sel;
 
7042
 
 
7043
    return 0;
 
7044
}
 
7045
 
 
7046
void
 
7047
ipmi_ui_shutdown(void)
 
7048
{
 
7049
    ipmi_mem_free(sensor_states);
 
7050
    sensor_states = NULL;
 
7051
    ipmi_mem_free(sensor_event_states);
 
7052
    sensor_event_states = NULL;
 
7053
    ipmi_mem_free(sensor_thresholds);
 
7054
    sensor_thresholds = NULL;
 
7055
    leave(0, "");
 
7056
}