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

« back to all changes in this revision

Viewing changes to lib/strings.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
 * strings.c
 
3
 *
 
4
 * MontaVista IPMI code for converting values to strings.
 
5
 *
 
6
 * Author: MontaVista Software, Inc.
 
7
 *         Corey Minyard <minyard@mvista.com>
 
8
 *         source@mvista.com
 
9
 *
 
10
 * Copyright 2002,2003 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 <stdlib.h>
 
35
#include <stdio.h>
 
36
#include <OpenIPMI/ipmi_bits.h>
 
37
#include <OpenIPMI/ipmi_msgbits.h>
 
38
#include <OpenIPMI/ipmi_auth.h>
 
39
#include <OpenIPMI/ipmiif.h>
 
40
#include <OpenIPMI/ipmi_err.h>
 
41
#include <string.h>
 
42
#include <OpenIPMI/internal/ipmi_malloc.h>
 
43
 
 
44
const char *
 
45
ipmi_update_e_string(enum ipmi_update_e val)
 
46
{
 
47
    switch (val) {
 
48
    case IPMI_ADDED: return "added";
 
49
    case IPMI_DELETED: return "deleted";
 
50
    case IPMI_CHANGED: return "changed";
 
51
    default: return "invalid";
 
52
    }
 
53
}
 
54
 
 
55
static char *hysteresis_support_types[] =
 
56
{
 
57
    "none",
 
58
    "readable",
 
59
    "settable",
 
60
    "fixed",
 
61
};
 
62
#define NUM_HYSTERESIS_SUPPORT_TYPES (sizeof(hysteresis_support_types)/sizeof(char *))
 
63
const char *
 
64
ipmi_get_hysteresis_support_string(unsigned int val)
 
65
{
 
66
    if (val >= NUM_HYSTERESIS_SUPPORT_TYPES)
 
67
        return "invalid";
 
68
    return hysteresis_support_types[val];
 
69
}
 
70
 
 
71
static char *threshold_access_support_types[] =
 
72
{
 
73
    "none",
 
74
    "readable",
 
75
    "settable",
 
76
    "fixed",
 
77
};
 
78
#define NUM_THRESHOLD_ACCESS_SUPPORT_TYPES (sizeof(threshold_access_support_types)/sizeof(char *))
 
79
const char *
 
80
ipmi_get_threshold_access_support_string(unsigned int val)
 
81
{
 
82
    if (val >= NUM_THRESHOLD_ACCESS_SUPPORT_TYPES)
 
83
        return "invalid";
 
84
    return threshold_access_support_types[val];
 
85
}
 
86
 
 
87
static char *event_support_types[] =
 
88
{
 
89
    "per_state",
 
90
    "entire_sensor",
 
91
    "global_disable",
 
92
    "none",
 
93
};
 
94
#define NUM_EVENT_SUPPORT_TYPES (sizeof(event_support_types)/sizeof(char *))
 
95
const char *
 
96
ipmi_get_event_support_string(unsigned int val)
 
97
{
 
98
    if (val >= NUM_EVENT_SUPPORT_TYPES)
 
99
        return "invalid";
 
100
    return event_support_types[val];
 
101
}
 
102
 
 
103
static char *sensor_types[] =
 
104
{
 
105
    "unspecified",
 
106
    "temperature",
 
107
    "voltage",
 
108
    "current",
 
109
    "fan",
 
110
    "physical_security",
 
111
    "platform_security",
 
112
    "processor",
 
113
    "power_supply",
 
114
    "power_unit",
 
115
    "cooling_device",
 
116
    "other_units_based_sensor",
 
117
    "memory",
 
118
    "drive_slot",
 
119
    "power_memory_resize",
 
120
    "system_firmware_progress",
 
121
    "event_logging_disabled",
 
122
    "watchdog_1",
 
123
    "system_event",
 
124
    "critical_interrupt",
 
125
    "button",
 
126
    "module_board",
 
127
    "microcontroller_coprocessor",
 
128
    "add_in_card",
 
129
    "chassis",
 
130
    "chip_set",
 
131
    "other_fru",
 
132
    "cable_interconnect",
 
133
    "terminator",
 
134
    "system_boot_initiated",
 
135
    "boot_error",
 
136
    "os_boot",
 
137
    "os_critical_stop",
 
138
    "slot_connector",
 
139
    "system_acpi_power_state",
 
140
    "watchdog_2",
 
141
    "platform_alert",
 
142
    "entity_presense",
 
143
    "monitor_asic_ic",
 
144
    "lan",
 
145
    "management_subsystem_health",
 
146
    "battery",
 
147
};
 
148
#define NUM_SENSOR_TYPES (sizeof(sensor_types)/sizeof(char *))
 
149
const char *
 
150
ipmi_get_sensor_type_string(unsigned int val)
 
151
{
 
152
    if (val >= NUM_SENSOR_TYPES)
 
153
        return "invalid";
 
154
    return sensor_types[val];
 
155
}
 
156
 
 
157
static char *event_reading_types[] =
 
158
{
 
159
    "unspecified",
 
160
    "threshold",
 
161
    "discrete_usage",
 
162
    "discrete_state",
 
163
    "discrete_predictive_failure",
 
164
    "discrete_limit_exceeded",
 
165
    "discrete_performance_met",
 
166
    "discrete_severity",
 
167
    "discrete_device_presense",
 
168
    "discrete_device_enable",
 
169
    "discrete_availability",
 
170
    "discrete_redundancy",
 
171
    "discrete_acpi_power",
 
172
};
 
173
#define NUM_EVENT_READING_TYPES (sizeof(event_reading_types)/sizeof(char *))
 
174
const char *
 
175
ipmi_get_event_reading_type_string(unsigned int val)
 
176
{
 
177
    if (val == IPMI_EVENT_READING_TYPE_SENSOR_SPECIFIC)
 
178
        return "sensor specific";
 
179
 
 
180
    if (val >= NUM_EVENT_READING_TYPES)
 
181
        return "invalid";
 
182
    return event_reading_types[val];
 
183
}
 
184
 
 
185
static char *sensor_directions[] =
 
186
{
 
187
    "unspecified",
 
188
    "input",
 
189
    "output",
 
190
};
 
191
#define NUM_SENSOR_DIRECTIONS (sizeof(sensor_directions)/sizeof(char *))
 
192
const char *
 
193
ipmi_get_sensor_direction_string(unsigned int val)
 
194
{
 
195
    if (val >= NUM_SENSOR_DIRECTIONS)
 
196
        return "invalid";
 
197
    return sensor_directions[val];
 
198
}
 
199
 
 
200
static char *rate_unit_types[] =
 
201
{
 
202
    "",
 
203
    "/us",
 
204
    "/ms",
 
205
    "/sec",
 
206
    "/min",
 
207
    "/hour",
 
208
    "/day",
 
209
};
 
210
#define NUM_RATE_UNIT_TYPES (sizeof(rate_unit_types)/sizeof(char *))
 
211
const char *
 
212
ipmi_get_rate_unit_string(unsigned int val)
 
213
{
 
214
    if (val >= NUM_RATE_UNIT_TYPES)
 
215
        return "invalid";
 
216
    return rate_unit_types[val];
 
217
}
 
218
 
 
219
static char *unit_types[] =
 
220
{
 
221
    "unspecified",
 
222
    "C",
 
223
    "F",
 
224
    "K",
 
225
    "volts",
 
226
    "amps",
 
227
    "watts",
 
228
    "joules",
 
229
    "coulombs",
 
230
    "VA",
 
231
    "nits",
 
232
    "lumens",
 
233
    "lux",
 
234
    "candela",
 
235
    "kpa",
 
236
    "PSI",
 
237
    "newtons",
 
238
    "CFM",
 
239
    "RPM",
 
240
    "HZ",
 
241
    "useconds",
 
242
    "mseconds",
 
243
    "seconds",
 
244
    "minute",
 
245
    "hour",
 
246
    "day",
 
247
    "week",
 
248
    "mil",
 
249
    "inches",
 
250
    "feet",
 
251
    "cubic inchs",
 
252
    "cubic feet",
 
253
    "millimeters",
 
254
    "centimeters",
 
255
    "meters",
 
256
    "cubic centimeters"
 
257
    "cubic meters",
 
258
    "liters",
 
259
    "fluid ounces",
 
260
    "radians",
 
261
    "seradians",
 
262
    "revolutions",
 
263
    "cycles",
 
264
    "gravities",
 
265
    "ounces",
 
266
    "pounds",
 
267
    "foot pounds",
 
268
    "ounce inches",
 
269
    "gauss",
 
270
    "gilberts",
 
271
    "henries",
 
272
    "mhenries",
 
273
    "farads",
 
274
    "ufarads",
 
275
    "ohms",
 
276
    "siemens",
 
277
    "moles",
 
278
    "becquerels",
 
279
    "PPM",
 
280
    "unspecified",
 
281
    "decibels",
 
282
    "DbA",
 
283
    "DbC",
 
284
    "grays",
 
285
    "sieverts",
 
286
    "color temp deg K",
 
287
    "bits",
 
288
    "kbits",
 
289
    "mbits",
 
290
    "gbits",
 
291
    "bytes",
 
292
    "kbytes",
 
293
    "mbytes",
 
294
    "gbytes",
 
295
    "words",
 
296
    "dwords",
 
297
    "qwords",
 
298
    "lines",
 
299
    "hits",
 
300
    "misses",
 
301
    "retries",
 
302
    "resets",
 
303
    "overruns",
 
304
    "underruns",
 
305
    "collisions",
 
306
    "packets",
 
307
    "messages",
 
308
    "characters",
 
309
    "errors",
 
310
    "correctable_errors",
 
311
    "uncorrectable_errors",
 
312
    "fatal errors",
 
313
    "grams",
 
314
};
 
315
#define NUM_UNIT_TYPES (sizeof(unit_types)/sizeof(char *))
 
316
const char *
 
317
ipmi_get_unit_type_string(unsigned int val)
 
318
{
 
319
    if (val >= NUM_UNIT_TYPES)
 
320
        return "invalid";
 
321
    return unit_types[val];
 
322
}
 
323
 
 
324
static char *threshold_types[] =
 
325
{
 
326
    "lower non-critical",
 
327
    "lower critical",
 
328
    "lower non-recoverable",
 
329
    "upper non-critical",
 
330
    "upper critical",
 
331
    "upper non-recoverable"
 
332
};
 
333
#define NUM_THRESHOLD_TYPES (sizeof(threshold_types)/sizeof(char *))
 
334
const char *
 
335
ipmi_get_threshold_string(enum ipmi_thresh_e val)
 
336
{
 
337
    if (val > NUM_THRESHOLD_TYPES)
 
338
        return "invalid";
 
339
    return threshold_types[val];
 
340
}
 
341
 
 
342
static char *value_dir_types[] =
 
343
{
 
344
    "going-low",
 
345
    "going-high"
 
346
};
 
347
#define NUM_VALUE_DIR_TYPES (sizeof(value_dir_types)/sizeof(char *))
 
348
const char *
 
349
ipmi_get_value_dir_string(enum ipmi_event_value_dir_e val)
 
350
{
 
351
    if (val > NUM_VALUE_DIR_TYPES)
 
352
        return "invalid";
 
353
    return value_dir_types[val];
 
354
}
 
355
 
 
356
static char *event_dir_types[] =
 
357
{
 
358
    "assertion",
 
359
    "deassertion"
 
360
};
 
361
#define NUM_EVENT_DIR_TYPES (sizeof(event_dir_types)/sizeof(char *))
 
362
const char *
 
363
ipmi_get_event_dir_string(enum ipmi_event_dir_e val)
 
364
{
 
365
    if (val > NUM_EVENT_DIR_TYPES)
 
366
        return "invalid";
 
367
    return event_dir_types[val];
 
368
}
 
369
 
 
370
static char *entity_id_types[] =
 
371
{
 
372
    "unspecified",                                      /* 0 */
 
373
    "other",
 
374
    "unkown",
 
375
    "processor",
 
376
    "disk",
 
377
    "peripheral",
 
378
    "system_management_module",
 
379
    "system_board",
 
380
    "memory_module",
 
381
    "processor_module",
 
382
    "power_supply",                                     /* 10 */
 
383
    "add_in_card",
 
384
    "front_panel_board",
 
385
    "back_panel_board",
 
386
    "power_system_board",
 
387
    "drive_backplane",
 
388
    "system_internal_expansion_board",
 
389
    "other_system_board",
 
390
    "processor_board",
 
391
    "power_unit",
 
392
    "power_module",                                     /* 20 */
 
393
    "power_management_board",
 
394
    "chassis_back_panel_board",
 
395
    "system_chassis",
 
396
    "sub_chassis",
 
397
    "other_chassis_board",
 
398
    "disk_drive_bay",
 
399
    "peripheral_bay",
 
400
    "device_bay",
 
401
    "fan_cooling",
 
402
    "cooling_unit",                                     /* 30 */
 
403
    "cable_interconnect",
 
404
    "memory_device",
 
405
    "system_management_software",
 
406
    "bios",
 
407
    "operating_system",
 
408
    "system_bus",
 
409
    "group",
 
410
    "remote_mgmt_comm_device",
 
411
    "external_environment",
 
412
    "battery",                                          /* 40 */
 
413
    "processing blade",
 
414
    "connectivity switch",
 
415
    "processor/memory module",
 
416
    "I/O module",
 
417
    "processor I/O module",
 
418
    "management controller firmware",
 
419
    "ipmi channel",
 
420
    "pci bus",
 
421
    "pci express bus",
 
422
    "scsi bus",                                         /* 50 */
 
423
    "sata/sas bus",
 
424
    "processor front side bus",
 
425
};
 
426
#define NUM_ENTITY_ID_TYPES (sizeof(entity_id_types)/sizeof(char *))
 
427
const char *
 
428
ipmi_get_entity_id_string(unsigned int val)
 
429
{
 
430
    if (val >= NUM_ENTITY_ID_TYPES)
 
431
        return "invalid";
 
432
    return entity_id_types[val];
 
433
}
 
434
 
 
435
static char *event_reading_states[256][16] =
 
436
{
 
437
    { },
 
438
    { "lower non-critical - going low",
 
439
      "lower non-critical - going high",
 
440
      "lower critical - going low",
 
441
      "lower critical - going high",
 
442
      "lower non-recoverable - going low",
 
443
      "lower non-recoverable - going high",
 
444
      "upper non-critical - going low",
 
445
      "upper non-critical - going high",
 
446
      "upper critical - going low",
 
447
      "upper critical - going high",
 
448
      "upper non-recoverable - going low",
 
449
      "upper non-recoverable - going high", },
 
450
    { "transition to idle", "transition to active", "transition to busy" },
 
451
    { "state deasserted", "state asserted" },
 
452
    { "predictive failure deasserted", "predictive failure asserted" },
 
453
    { "limit not exceeded", "limit exceeded" },
 
454
    { "performance met", "performance lags" },
 
455
    { "transition to ok",
 
456
      "transition to non-cricital from ok",
 
457
      "transition to critical from ok",
 
458
      "transition to non-recoverable from less severe",
 
459
      "transition to non-critical from more severe",
 
460
      "transition to critical from non-recoverable",
 
461
      "transition to non-recoverable",
 
462
      "monitor",
 
463
      "informational", },
 
464
    { "device removed/absent", "device inserted/present" },
 
465
    { "device disabled", "device enabled" },
 
466
    { "transition to ",
 
467
      "transition to in test",
 
468
      "transition to power off",
 
469
      "transition to on line",
 
470
      "transition to off line",
 
471
      "transition to off duty",
 
472
      "transition to degraded",
 
473
      "transition to power save",
 
474
      "install error" },
 
475
    { "fully redundant",
 
476
      "redundancy lost",
 
477
      "redundancy degraded",
 
478
      "non-redundant: sufficient resources from redundant",
 
479
      "non-redundant: sufficient resources from insufficient resources",
 
480
      "non-redundant: insufficient resources",
 
481
      "redundancy degraded from fully redundant",
 
482
      "redundancy degraded from non-redundant" },
 
483
    { "D0 power state",
 
484
      "D1 power state",
 
485
      "D2 power state",
 
486
      "D3 power state" }
 
487
};
 
488
 
 
489
static char *sensor_states[256][16] =
 
490
{
 
491
    {}, /* 0x00 */
 
492
    {}, /* 0x01 */
 
493
    {}, /* 0x02 */
 
494
    {}, /* 0x03 */
 
495
    {}, /* 0x04 */
 
496
    { /* 0x05 */
 
497
        "general chassis intrusion",
 
498
        "drive bay intrusion",
 
499
        "I/O card area intrusion",
 
500
        "processor area intrusion",
 
501
        "LAN leash lost",
 
502
        "unauthorized doc/undock",
 
503
        "fan area intrusion"
 
504
    },
 
505
    { /* 0x06 */
 
506
        "secure mode",
 
507
        "pre-boot password violation - user password",
 
508
        "pre-boot password violation - setup password",
 
509
        "pre-boot password violation - network boot password",
 
510
        "other pre-boot password violation",
 
511
        "out-of-band access password violation",
 
512
    },
 
513
    { /* 0x07 */
 
514
        "IERR",
 
515
        "Termal Trip",
 
516
        "FRB1/BIST failure",
 
517
        "FRB2/Hand in POST failure",
 
518
        "FRB3/Processor startup/initialization failure",
 
519
        "configuration error",
 
520
        "SM BIOS 'uncorrectable CPU-complex error'",
 
521
        "processor presence detected",
 
522
        "processor disabled",
 
523
        "terminator presence detected"
 
524
    },
 
525
    { /* 0x08 */
 
526
        "presence detected",
 
527
        "power supply failure detected",
 
528
        "predictive failure",
 
529
        "power supply AC lost",
 
530
        "AC lost or out-of-range",
 
531
        "AC out of range, but present"
 
532
    },
 
533
    { /* 0x09 */
 
534
        "power off/power down",
 
535
        "power cycle",
 
536
        "240VA power down",
 
537
        "interlock power down",
 
538
        "AC lost",
 
539
        "soft power control failure",
 
540
        "power unit falure detected",
 
541
        "predictive failure",
 
542
    },
 
543
    {}, /* 0x0a */
 
544
    {}, /* 0x0b */
 
545
    { /* 0x0c */
 
546
        "correctable ECC",
 
547
        "uncorrectable ECC",
 
548
        "parity",
 
549
        "memory scrub failed (stuck bit)",
 
550
        "memory device disabled",
 
551
        "correctable ECC log limit reached",
 
552
        "presence detected",
 
553
        "configuration error",
 
554
        "spare",
 
555
        "memory automatically throttled",
 
556
    },
 
557
    { /* 0x0d */
 
558
        "drive presence",
 
559
        "drive fault",
 
560
        "predictive failure",
 
561
        "hot spare",
 
562
        "consistancy/parity check in progress",
 
563
        "in critical array",
 
564
        "in failed array",
 
565
        "rebuild/remap in progress",
 
566
        "rebuild/remap aborted",
 
567
    },
 
568
    {}, /* 0x0e */
 
569
    { /* 0x0f */
 
570
        "system firmware error",
 
571
        "system firmware hang",
 
572
        "system firmware progress"
 
573
    },
 
574
    { /* 0x10 */
 
575
        "correctable memory error logging disabled",
 
576
        "event type logging siabled",
 
577
        "log area reset/cleared",
 
578
        "all event logging disabled",
 
579
    },
 
580
    { /* 0x11 */
 
581
        "BIOS watchdog reset",
 
582
        "OS watchdog reset",
 
583
        "os watchdog shutdown",
 
584
        "os watchdog power down",
 
585
        "os watchdog power cycle",
 
586
        "os watchdog NMI/diag interrupt",
 
587
        "os watchdog expired",
 
588
        "os watchdog pretimout interrupt",
 
589
    },
 
590
    { /* 0x12 */
 
591
        "system reconfigured",
 
592
        "OEM system boot event",
 
593
        "undetermined system hardware failure",
 
594
        "entry added to auxiliary log",
 
595
        "PEF action",
 
596
    },
 
597
    { /* 0x13 */
 
598
        "front panel NMI/diag interrupt",
 
599
        "bus timeout",
 
600
        "I/O channel check NMI",
 
601
        "software NMI",
 
602
        "PCI PERR",
 
603
        "PCI SERR",
 
604
        "EISA fail safe timeout",
 
605
        "bus correctable error",
 
606
        "bus uncorrectable error",
 
607
        "fatal NMI"
 
608
    },
 
609
    { /* 0x14 */
 
610
        "power button pressed",
 
611
        "sleep button pressed",
 
612
        "reset button pressed"
 
613
    },
 
614
    {}, /* 0x15 */
 
615
    {}, /* 0x16 */
 
616
    {}, /* 0x17 */
 
617
    {}, /* 0x18 */
 
618
    {}, /* 0x19 */
 
619
    {}, /* 0x1a */
 
620
    { /* 0x1b */
 
621
        "cable/interconnect is connected",
 
622
        "configuration error",
 
623
    },
 
624
    {}, /* 0x1c */
 
625
    { /* 0x1d */
 
626
        "initiated by power up",
 
627
        "initiated by hard reset",
 
628
        "initiated by warm reset",
 
629
        "user requested PXE boot",
 
630
        "automatic boot to diagnostic"
 
631
    },
 
632
    { /* 0x1e */
 
633
        "no bootable media",
 
634
        "non-bootable diskette left in drive",
 
635
        "PXE server not found",
 
636
        "invalid boot sector",
 
637
        "timeout waiting for user selection of boot source"
 
638
    },
 
639
    { /* 0x1f */
 
640
        "A: boot completed",
 
641
        "C: boot completed",
 
642
        "PXE boot completed",
 
643
        "diagnostic boot completed",
 
644
        "CD-ROM boot completed",
 
645
        "ROM boot completed",
 
646
        "boot completed"
 
647
    },
 
648
    { /* 0x20 */
 
649
        "stop during OS load/initialization",
 
650
        "run time stop"
 
651
    },
 
652
    { /* 0x21 */
 
653
        "fault status asserted",
 
654
        "identify status asserted",
 
655
        "slot/connector device installed/attached",
 
656
        "slot/connector ready for device installation",
 
657
        "slot/connector ready for device removal",
 
658
        "slot power is off",
 
659
        "slot/connector device removal request",
 
660
        "interlock asserted",
 
661
        "slot is disabled"
 
662
    },
 
663
    { /* 0x22 */
 
664
        "S0/G0 working",
 
665
        "S1 'Sleeping with system H/W & processor context maintained'",
 
666
        "S2 'sleeping, processor context lost'",
 
667
        "S3 'sleeping, processor & h/w context lost, memory retained'",
 
668
        "S4 'non-volatile sleep/suspend to disk'",
 
669
        "S5/G2 soft-off",
 
670
        "S4/S5 soft-off"
 
671
        "G3 mechanical off",
 
672
        "sleeping in an S1, S2, or S3 state",
 
673
        "G1 sleeping",
 
674
        "S5 entered by override",
 
675
        "legacy on state",
 
676
        "legacy off state",
 
677
        NULL,
 
678
        "unknown"
 
679
    },
 
680
    { /* 0x23 */
 
681
        "timer expired",
 
682
        "hard reset",
 
683
        "power down",
 
684
        "power cycle",
 
685
        NULL,
 
686
        NULL,
 
687
        NULL,
 
688
        NULL,
 
689
        "timer interrupt"
 
690
    },
 
691
    { /* 0x24 */
 
692
        "platform generated page",
 
693
        "platform generated LAN alert",
 
694
        "platform event trap generated",
 
695
        "platform generated SNMP trap"
 
696
    },
 
697
    { /* 0x25 */
 
698
        "entity present",
 
699
        "entity absent",
 
700
        "entity disabled"
 
701
    },
 
702
    {}, /* 0x26 */
 
703
    { /* 0x27 */
 
704
        "LAN heartbeat lost",
 
705
        "LAN heartbeat"
 
706
    },
 
707
    { /* 0x28 */
 
708
        "sensor access degraded or unavailable",
 
709
        "controller access degraded or unavailable",
 
710
        "management controller off-line",
 
711
        "management controller unavailable",
 
712
    },
 
713
    { /* 0x29 */
 
714
        "battery low",
 
715
        "battery failed",
 
716
        "battery presence detected"
 
717
    },
 
718
};
 
719
 
 
720
const char *
 
721
ipmi_get_reading_name(unsigned int event_reading_type,
 
722
                      unsigned int sensor_type,
 
723
                      unsigned int val)
 
724
{
 
725
    char *rv;
 
726
    if (event_reading_type == IPMI_EVENT_READING_TYPE_SENSOR_SPECIFIC) {
 
727
        if ((sensor_type > 255) || (val > 15))
 
728
            return "invalid";
 
729
        rv = sensor_states[sensor_type][val];
 
730
    } else {
 
731
        if ((event_reading_type > 255) || (val > 15))
 
732
            return "invalid";
 
733
        rv = event_reading_states[event_reading_type][val];
 
734
    }
 
735
    if (rv == NULL)
 
736
        return "unknown";
 
737
    return rv;
 
738
}
 
739
 
 
740
static char *control_types[] =
 
741
{
 
742
    "unspecified",
 
743
    "light",
 
744
    "relay",
 
745
    "display",
 
746
    "alarm",
 
747
    "reset",
 
748
    "power",
 
749
    "fan speed",
 
750
    "identifier",
 
751
    "one-shot reset",
 
752
    "output",
 
753
    "one-shot output",
 
754
};
 
755
#define NUM_CONTROL_TYPES (sizeof(control_types)/sizeof(char *))
 
756
const char *
 
757
ipmi_get_control_type_string(unsigned int val)
 
758
{
 
759
    if (val >= NUM_CONTROL_TYPES)
 
760
        return "invalid";
 
761
    return control_types[val];
 
762
}
 
763
 
 
764
static char *colors[] =
 
765
{
 
766
    "black",
 
767
    "white",
 
768
    "red",
 
769
    "green",
 
770
    "blue",
 
771
    "yellow",
 
772
    "orange",
 
773
};
 
774
#define NUM_COLORS (sizeof(colors)/sizeof(char *))
 
775
const char *
 
776
ipmi_get_color_string(unsigned int val)
 
777
{
 
778
    if (val >= NUM_COLORS)
 
779
        return "invalid";
 
780
    return colors[val];
 
781
}
 
782
 
 
783
static char *ipmi_netfns[] =
 
784
{
 
785
    "chassis(c):%02x",          // +0 : 0x00
 
786
    "chassis(r):%02x",          // +1 : 0x01
 
787
    "bridge(c):%02x",           // +2 : 0x02
 
788
    "bridge(r):%02x",           // +3 : 0x03
 
789
    "s/e(c):%02x",              // +4 : 0x04
 
790
    "s/e(r):%02x",              // +5 : 0x05
 
791
    "app(c):%02x",              // +6 : 0x06
 
792
    "app(r):%02x",              // +7 : 0x07
 
793
    "firmware(c):%02x",         // +8 : 0x08
 
794
    "firmware(r):%02x",         // +9 : 0x09
 
795
    "storage(c):%02x",          // +10: 0x0a
 
796
    "storage(r):%02x",          // +11: 0x0b
 
797
    "transport(c):%02x",        // +12: 0x0c
 
798
    "transport(r):%02x",        // +13: 0x0d
 
799
    "reserved(c):%02x",         // +14: 0x0e..0x2b reserved
 
800
    "reserved(r):%02x",         // +15: 0x2b
 
801
    "grpext(c):%02x",           // +16: 0x2c
 
802
    "grpext(r):%02x",           // +17: 0x2d
 
803
    "oem/grp(c):%02x",          // +18: 0x2e
 
804
    "oem/grp(r):%02x",          // +19: 0x2f
 
805
    "ctlrspec(c):%02x",         // +20: 0x30..3f Controller specific
 
806
    "ctlrspec(r):%02x",         // +21: 0x3f
 
807
};
 
808
/*
 
809
 * Convert a NetFN code into a string
 
810
 */
 
811
char *
 
812
ipmi_get_netfn_string(unsigned int netfn,
 
813
                      char         *buffer,
 
814
                      unsigned int buf_len)
 
815
{
 
816
    char *netfn_fs;
 
817
 
 
818
    netfn &= 0x3f;
 
819
 
 
820
    if ( netfn > 0x2f )
 
821
        netfn_fs = ipmi_netfns[(netfn & 0x01) + 20];
 
822
    else if ( netfn > 0x2d )
 
823
        netfn_fs = ipmi_netfns[(netfn & 0x01) + 18];
 
824
    else if ( netfn > 0x2b )
 
825
        netfn_fs = ipmi_netfns[(netfn & 0x01) + 16];
 
826
    else if ( netfn > 0x0d )
 
827
        netfn_fs = ipmi_netfns[(netfn & 0x01) + 14];
 
828
    else
 
829
        netfn_fs = ipmi_netfns[netfn];
 
830
 
 
831
    snprintf(buffer, buf_len, netfn_fs, netfn);
 
832
 
 
833
    return buffer;
 
834
}
 
835
 
 
836
static char * ipmi_app_cmds[] =
 
837
{
 
838
    "reserved:%02x",            // +0 : 0x00
 
839
    "GetDevId:%02x",            // +1 : 0x01
 
840
    "ColdReset:%02x",           // +2 : 0x02
 
841
    "WarmReset:%02x",           // +3 : 0x03
 
842
    "GetSelfTest:%02x",         // +4 : 0x04
 
843
    "ManuTestOn:%02x",          // +5 : 0x05
 
844
    "SetACPIpwr:%02x",          // +6 : 0x06
 
845
    "GetACPIpwr:%02x",          // +7 : 0x07
 
846
    "GetDevGUID:%02x",          // +8 : 0x08 (0x09..0x21 unassigned)
 
847
    "ResetWdog:%02x",           // +9 : 0x22
 
848
    "unassigned:%02x",          // +10: 0x23 unassigned
 
849
    "SetWdog:%02x",             // +11: 0x24
 
850
    "GetWdog:%02x",             // +12: 0x25 (0x26..0x2d unassigned)
 
851
    "SetBMCgblEna:%02x",        // +13: 0x2e
 
852
    "GetBMCgblEna:%02x",        // +14: 0x2f
 
853
    "ClrMsgFlags:%02x",         // +15: 0x30
 
854
    "GetMsgFlags:%02x",         // +16: 0x31
 
855
    "EnaMsgChRcv:%02x",         // +17: 0x32
 
856
    "GetMsg:%02x",              // +18: 0x33
 
857
    "SndMsg:%02x",              // +19: 0x34
 
858
    "ReadEvntMsg:%02x",         // +20: 0x35
 
859
    "GetBTifCap:%02x",          // +21: 0x36
 
860
    "GetSysGUID:%02x",          // +22: 0x37
 
861
    "GetChAuthCap:%02x",        // +23: 0x38
 
862
    "GetSessChlng:%02x",        // +24: 0x39
 
863
    "ActiSess:%02x",            // +25: 0x3a
 
864
    "SetSessPrivlvl:%02x",      // +26: 0x3b
 
865
    "CloseSess:%02x",           // +27: 0x3c
 
866
    "GetSessInfo:%02x",         // +28: 0x3d
 
867
    "unassigned:%02x",          // +29: 0x3e unassigned
 
868
    "GetAuthCode:%02x",         // +30: 0x3f
 
869
    "SetChAccess:%02x",         // +31: 0x40
 
870
    "GetChAccess:%02x",         // +32: 0x41
 
871
    "GetChInfoCmd:%02x",        // +33: 0x42
 
872
    "SetUsrAccCmd:%02x",        // +34: 0x43
 
873
    "GetUsrAccCmd:%02x",        // +35: 0x44
 
874
    "SetUsrName:%02x",          // +36: 0x45
 
875
    "GetUsrName:%02x",          // +37: 0x46
 
876
    "SetUsrPasswd:%02x",        // +38: 0x47
 
877
    "ActPayload:%02x",          // +39: 0x48
 
878
    "DeactPayload:%02x",        // +40: 0x49
 
879
    "GetPayloadActStat:%02x",   // +41: 0x4a
 
880
    "GetPayloadInstInfo:%02x",  // +42: 0x4b
 
881
    "SetUserPayloadAcc:%02x",   // +43: 0x4c
 
882
    "GetUserPayloadAcc:%02x",   // +44: 0x4d
 
883
    "GetChanPayloadSup:%02x",   // +45: 0x4e
 
884
    "GetChanPayloadVer:%02x",   // +46: 0x4f
 
885
    "GetChanOEMPayloadInf:%02x",// +47: 0x50
 
886
    "unassigned:%02x",          // +48: 0x51 unassigned
 
887
    "MstrWrRd:%02x",            // +49: 0x52
 
888
    "unassigned:%02x",          // +50: 0x53 unassigned
 
889
    "GetChanCipherSuites:%02x", // +51: 0x54
 
890
    "SuspResPayloadEnc:%02x",   // +52: 0x55
 
891
    "SetChanSecKey:%02x",       // +53: 0x56
 
892
    "GetSysIntfCap:%02x",       // +54: 0x57
 
893
};
 
894
 
 
895
static char * ipmi_chassis_cmds[] =
 
896
{
 
897
    "GetChassisCap:%02x",       // +0 : 0x00
 
898
    "GetChassisSts:%02x",       // +1 : 0x01
 
899
    "ChassisCtrl:%02x",         // +2 : 0x02
 
900
    "ChassisReset:%02x",        // +3 : 0x03
 
901
    "ChassisIdent:%02x",        // +4 : 0x04
 
902
    "SetChassisCap:%02x",       // +5 : 0x05
 
903
    "SetPwrRestPol:%02x",       // +6 : 0x06
 
904
    "GetSysRstCause:%02x",      // +7 : 0x07
 
905
    "SetSysBootOp:%02x",        // +8 : 0x08
 
906
    "GetSysBootOp:%02x",        // +9 : 0x09
 
907
    "unassigned:%02x",          // +10: 0x0a..0x0e unassigned
 
908
    "GetPOHcounter:%02x",       // +11: 0x0f
 
909
};
 
910
 
 
911
static char * ipmi_se_cmds[] =
 
912
{
 
913
    "SetEvntRcvr:%02x",         // +0 : 0x00
 
914
    "GetEvntRcvr:%02x",         // +1 : 0x01
 
915
    "EventMsg:%02x",            // +2 : 0x02 (0x03..0x0f unassigned)
 
916
    "GetPEFcap:%02x",           // +3 : 0x10
 
917
    "ArmPEFtimer:%02x",         // +4 : 0x11
 
918
    "SetPEFconfig:%02x",        // +5 : 0x12
 
919
    "GetPEFconfig:%02x",        // +6 : 0x13
 
920
    "SetLastEvId:%02x",         // +7 : 0x14
 
921
    "GetLastEvId:%02x",         // +8 : 0x15
 
922
    "AlertImmed:%02x",          // +9 : 0x16
 
923
    "PETackn:%02x",             // +10: 0x17 (0x18..0x1f unassigned)
 
924
    "GetDevSDRinfo:%02x",       // +11: 0x20
 
925
    "GetDevSDR:%02x",           // +12: 0x21
 
926
    "ReservSDRreposit:%02x",    // +13: 0x22
 
927
    "GetSensReadFact:%02x",     // +14: 0x23
 
928
    "SetSensHyst:%02x",         // +15: 0x24
 
929
    "GetSensHyst:%02x",         // +16: 0x25
 
930
    "SetSensThresh:%02x",       // +17: 0x26
 
931
    "GetSensThresh:%02x",       // +18: 0x27
 
932
    "SetSensEvEna:%02x",        // +29: 0x28
 
933
    "GetSensEvEna:%02x",        // +20: 0x29
 
934
    "RearmSensEv:%02x",         // +21: 0x2a
 
935
    "GetSensEvStat:%02x",       // +22: 0x2b
 
936
    "unassigned:%02x",          // +23: 0x2c unassigned
 
937
    "GetSensReading:%02x",      // +24: 0x2d
 
938
    "SetSensType:%02x",         // +25: 0x2e
 
939
    "GetSensType:%02x",         // +26: 0x2f
 
940
};
 
941
 
 
942
static char * ipmi_storage_cmds[] =
 
943
{
 
944
    "unassigned:%02x",          // +0 : 0x00..0x0f unassigned
 
945
    "GetFRUinvInfo:%02x",       // +1 : 0x10
 
946
    "ReadFRUdata:%02x",         // +2 : 0x11
 
947
    "WriteFRUdata:%02x",        // +3 : 0x12 (0x13..0x1f unassigned)
 
948
    "GetSDRrepInfo:%02x",       // +4 : 0x20
 
949
    "GetSDRrepAlloc:%02x",      // +5 : 0x21
 
950
    "ResrvSDRrepo:%02x",        // +6 : 0x22
 
951
    "GetSDR:%02x",              // +7 : 0x23
 
952
    "AddSDR:%02x",              // +8 : 0x24
 
953
    "PartialAddSDR:%02x",       // +9 : 0x25
 
954
    "DeleteSDR:%02x",           // +10: 0x26
 
955
    "ClrSDRrepo:%02x",          // +11: 0x27
 
956
    "GetSDRrepTime:%02x",       // +12: 0x28
 
957
    "SetSDRrepTime:%02x",       // +13: 0x29
 
958
    "EntrSDRrepUpd:%02x",       // +14: 0x2a
 
959
    "ExitSDRrepUpd:%02x",       // +15: 0x2b
 
960
    "RunInitAgent:%02x",        // +16: 0x2c (0x2d..0x3f unassigned)
 
961
    "GetSELinfo:%02x",          // +17: 0x40
 
962
    "GetSELallocInfo:%02x",     // +18: 0x41
 
963
    "ReservSEL:%02x",           // +19: 0x42
 
964
    "GetSELentry:%02x",         // +20: 0x43
 
965
    "AddSELentry:%02x",         // +21: 0x44
 
966
    "PartAddSELentry:%02x",     // +22: 0x45
 
967
    "DeleteSELent:%02x",        // +23: 0x46
 
968
    "ClrSEL:%02x",              // +24: 0x47
 
969
    "GetSELtime:%02x",          // +25: 0x48
 
970
    "SetSELtime:%02x",          // +26: 0x49 (0x4a..0x59 unassigned)
 
971
    "GetAuxLogSts:%02x",        // +27: 0x5a
 
972
    "SetAuxLogSts:%02x",        // +28: 0x5b
 
973
};
 
974
 
 
975
static char * ipmi_transport_cmds[] =
 
976
{
 
977
    "unassigned:%02x",          // +0 : 0x00 unassigned
 
978
    "SetLANconfParm:%02x",      // +1 : 0x01
 
979
    "GetLANconfParm:%02x",      // +2 : 0x02
 
980
    "SuspBMCarps:%02x",         // +3 : 0x03
 
981
    "GetIPstats:%02x",          // +4 : 0x04 (0x05..0x0f unassigned)
 
982
    "SetSerialConf:%02x",       // +5 : 0x10
 
983
    "GetSerialConf:%02x",       // +6 : 0x11
 
984
    "SetSerialMux:%02x",        // +7 : 0x12
 
985
    "GetTAPrespCodes:%02x",     // +8 : 0x13
 
986
    "SetPPPproxyTx:%02x",       // +9 : 0x14
 
987
    "GetPPPproxyTx:%02x",       // +10: 0x15
 
988
    "SendPPPproxyPkt:%02x",     // +11: 0x16
 
989
    "GetPPPproxyRxData:%02x",   // +12: 0x17
 
990
    "SerialConnAct:%02x",       // +13: 0x18
 
991
    "Callback:%02x",            // +14: 0x19
 
992
    "SetUsrCallOpts:%02x",      // +15: 0x1a
 
993
    "GetUsrCallOpts:%02x",      // +16: 0x1b
 
994
    "unassigned:%02x",          // +17: 0x1c
 
995
    "unassigned:%02x",          // +18: 0x1d
 
996
    "unassigned:%02x",          // +19: 0x1e
 
997
    "unassigned:%02x",          // +20: 0x1f
 
998
    "SOLActivating:%02x",       // +21: 0x20
 
999
    "SetSOLConfParm:%02x",      // +22: 0x21
 
1000
    "GetSOLConfParm:%02x",      // +23: 0x22
 
1001
};
 
1002
 
 
1003
static char * ipmi_bridge_cmds[] =
 
1004
{
 
1005
    "GetBridgeState:%02x",      // +0 : 0x00
 
1006
    "SetBridgeState:%02x",      // +1 : 0x01
 
1007
    "GetICMBaddr:%02x",         // +2 : 0x02
 
1008
    "SetICMBaddr:%02x",         // +3 : 0x03
 
1009
    "SetBridgeProxyAddr:%02x",  // +4 : 0x04
 
1010
    "GetBridgeStats:%02x",      // +5 : 0x05
 
1011
    "GetICMBcaps:%02x",         // +6 : 0x06
 
1012
    "unassigned:%02x",          // +7 : 0x07 unassigned
 
1013
    "ClrBridgeStats:%02x",      // +8 : 0x08
 
1014
    "GetBridgeProxyAddr:%02x",  // +9 : 0x09
 
1015
    "GetICMBConnInfo:%02x",     // +10: 0x0a
 
1016
    "GetICMBConnId:%02x",       // +11: 0x0b
 
1017
    "SendICMBConnId:%02x",      // +12: 0x0c (0x0d..0x0f unassigned)
 
1018
    "Prep4Disc:%02x",           // +13: 0x10
 
1019
    "GetAddresses:%02x",        // +14: 0x11
 
1020
    "SetDiscovered:%02x",       // +15: 0x12
 
1021
    "GetChassDevId:%02x",       // +16: 0x13
 
1022
    "SetChassDevId:%02x",       // +17: 0x14 (0x15..0x1f unassigned)
 
1023
    "BridgeRequest:%02x",       // +18: 0x20
 
1024
    "BridgeMessage:%02x",       // +19: 0x21 (0x22..0x2f unassigned)
 
1025
    "GetEventCnt:%02x",         // +20: 0x30
 
1026
    "SetEventDest:%02x",        // +21: 0x31
 
1027
    "SetEventRecpState:%02x",   // +22: 0x32
 
1028
    "SndICMBevMsg:%02x",        // +23: 0x33
 
1029
    "GetEventDest:%02x",        // +24: 0x34
 
1030
    "GetEventRecpState:%02x",   // +25: 0x35 (0x36..0xbf unassigned)
 
1031
    "OEMcommands:%02x",         // +26: 0xc0..0xfe
 
1032
    "ErrorReport:%02x",         // +27: 0xff
 
1033
};
 
1034
 
 
1035
/*
 
1036
 * Convert a NetFN/Command code into a string
 
1037
 */
 
1038
char *
 
1039
ipmi_get_command_string(unsigned int netfn,
 
1040
                        unsigned int cmd,
 
1041
                        char         *buffer,
 
1042
                        unsigned int buf_len)
 
1043
{
 
1044
    char **netfn_table;
 
1045
    char *cmd_fs = NULL;
 
1046
 
 
1047
    netfn &= 0x3f;
 
1048
 
 
1049
    if ( netfn <= 0x0d ) {
 
1050
        switch ( netfn ) {
 
1051
            case IPMI_CHASSIS_NETFN:
 
1052
            case IPMI_CHASSIS_NETFN | 1:
 
1053
            {
 
1054
                netfn_table=ipmi_chassis_cmds;
 
1055
                if ( cmd < 0x0b )
 
1056
                    cmd_fs = netfn_table[cmd];
 
1057
                else if ( cmd == 0x0f )
 
1058
                    cmd_fs = netfn_table[11];
 
1059
                break;
 
1060
            }
 
1061
            case IPMI_BRIDGE_NETFN:
 
1062
            case IPMI_BRIDGE_NETFN | 1:
 
1063
            {
 
1064
                netfn_table=ipmi_bridge_cmds;
 
1065
                if ( cmd < 0x0d )
 
1066
                    cmd_fs = netfn_table[cmd];
 
1067
                else if ( (cmd > 0x0f) && (cmd < 0x15) )
 
1068
                    cmd_fs = netfn_table[cmd - 0x10 + 13];
 
1069
                else if ( (cmd > 0x1f) && (cmd < 0x22) )
 
1070
                    cmd_fs = netfn_table[cmd - 0x20 + 18];
 
1071
                else if ( (cmd > 0x2f) && (cmd < 0x36) )
 
1072
                    cmd_fs = netfn_table[cmd - 0x30 + 20];
 
1073
                else if ( (cmd > 0xbf) && (cmd < 0xff) )
 
1074
                    cmd_fs = netfn_table[26];
 
1075
                break;
 
1076
            }
 
1077
            case IPMI_SENSOR_EVENT_NETFN:
 
1078
            case IPMI_SENSOR_EVENT_NETFN | 1:
 
1079
            {
 
1080
                netfn_table=ipmi_se_cmds;
 
1081
                if ( cmd < 0x03 )
 
1082
                    cmd_fs = netfn_table[cmd];
 
1083
                else if ( (cmd > 0x0f) && (cmd < 0x18) )
 
1084
                    cmd_fs = netfn_table[cmd - 0x10 + 3];
 
1085
                else if ( (cmd > 0x1f) && (cmd < 0x30) )
 
1086
                    cmd_fs = netfn_table[cmd - 0x20 + 11];
 
1087
                break;
 
1088
            }
 
1089
            case IPMI_APP_NETFN:
 
1090
            case IPMI_APP_NETFN | 1:
 
1091
            {
 
1092
                netfn_table=ipmi_app_cmds;
 
1093
                if ( cmd < 0x09 )
 
1094
                    cmd_fs = netfn_table[cmd];
 
1095
                else if ( (cmd > 0x21) && (cmd < 0x26) )
 
1096
                    cmd_fs = netfn_table[cmd - 0x22 + 9];
 
1097
                else if ( (cmd > 0x2d) && (cmd < 0x58) )
 
1098
                    cmd_fs = netfn_table[cmd - 0x2e + 13];
 
1099
                break;
 
1100
            }
 
1101
            case IPMI_FIRMWARE_NETFN:
 
1102
            case IPMI_FIRMWARE_NETFN | 1:
 
1103
            {
 
1104
                cmd_fs="unknown:%02x";
 
1105
                break;
 
1106
            }
 
1107
            case IPMI_STORAGE_NETFN:
 
1108
            case IPMI_STORAGE_NETFN | 1:
 
1109
            {
 
1110
                netfn_table=ipmi_storage_cmds;
 
1111
                if ( cmd < 0x10 )
 
1112
                    cmd_fs = netfn_table[0];
 
1113
                else if ( (cmd > 0x0f) && (cmd < 0x13) )
 
1114
                    cmd_fs = netfn_table[cmd - 0x10 + 1];
 
1115
                else if ( (cmd > 0x1f) && (cmd < 0x2d) )
 
1116
                    cmd_fs = netfn_table[cmd - 0x20 + 4];
 
1117
                else if ( (cmd > 0x3f) && (cmd < 0x4a) )
 
1118
                    cmd_fs = netfn_table[cmd - 0x40 + 17];
 
1119
                else if ( (cmd > 0x59) && (cmd < 0x5c) )
 
1120
                    cmd_fs = netfn_table[cmd - 0x5a + 27];
 
1121
                break;
 
1122
            }
 
1123
            case IPMI_TRANSPORT_NETFN:
 
1124
            case IPMI_TRANSPORT_NETFN | 1:
 
1125
            {
 
1126
                netfn_table=ipmi_transport_cmds;
 
1127
                if ( cmd < 0x05 )
 
1128
                    cmd_fs = netfn_table[cmd];
 
1129
                else if ( (cmd > 0x0f) && (cmd < 0x23) )
 
1130
                    cmd_fs = netfn_table[cmd - 0x10 + 5];
 
1131
                break;
 
1132
            }
 
1133
        }
 
1134
    }
 
1135
 
 
1136
    if (!cmd_fs)
 
1137
        cmd_fs = "unknown:%02x";
 
1138
 
 
1139
    snprintf(buffer, buf_len, cmd_fs, cmd);
 
1140
 
 
1141
    return buffer;
 
1142
}
 
1143
 
 
1144
static char *ipmi_ccodes[] =
 
1145
{
 
1146
    "Normal:%02x",      // +0 : 0x00 (0x01..0xbf undefined)
 
1147
    "NodeBusy:%02x",    // +1 : 0xc0
 
1148
    "InvCmd:%02x",      // +2 : 0xc1
 
1149
    "InvCmd4LUN:%02x",  // +3 : 0xc2
 
1150
    "Timeout:%02x",     // +4 : 0xc3
 
1151
    "OutOfSpace:%02x",  // +5 : 0xc4
 
1152
    "ResvCancInv:%02x", // +6 : 0xc5
 
1153
    "DataTrunc:%02x",   // +7 : 0xc6
 
1154
    "DataLenInv:%02x",  // +8 : 0xc7
 
1155
    "DataLenOvr:%02x",  // +9 : 0xc8
 
1156
    "PrmRangeErr:%02x", // +10: 0xc9
 
1157
    "InsuffData:%02x",  // +11: 0xca
 
1158
    "ObjNotPres:%02x",  // +12: 0xcb
 
1159
    "InvDataFld:%02x",  // +13: 0xcc
 
1160
    "IllCmd4Obj:%02x",  // +14: 0xcd
 
1161
    "NoResponse:%02x",  // +15: 0xce
 
1162
    "DupReq:%02x",      // +16: 0xcf
 
1163
    "SDRrepoBusy:%02x", // +17: 0xd0
 
1164
    "FirmwareUpd:%02x", // +18: 0xd1
 
1165
    "BMCiniting:%02x",  // +19: 0xd2
 
1166
    "DestUnavail:%02x", // +20: 0xd3
 
1167
    "PrivError:%02x",   // +21: 0xd4
 
1168
    "InvalState:%02x",  // +22: 0xd5 (0xd6..0xfe undefined)
 
1169
    "Unspecified:%02x", // +23: 0xff
 
1170
};
 
1171
/*
 
1172
 * Convert a Completion Code into a string
 
1173
 */
 
1174
char *
 
1175
ipmi_get_cc_string(unsigned int cc,
 
1176
                   char         *buffer,
 
1177
                   unsigned int buf_len)
 
1178
{
 
1179
    char *cc_fs;
 
1180
 
 
1181
    if ( cc == 0x00 )
 
1182
        cc_fs = ipmi_ccodes[0];
 
1183
    else if ( (cc > 0xbf) && (cc < 0xd6) )
 
1184
        cc_fs = ipmi_ccodes[cc - 0xc0 + 1];
 
1185
    else if ( cc == 0xff )
 
1186
        cc_fs = ipmi_ccodes[23];
 
1187
    else
 
1188
        cc_fs = "Unknown:%02x";
 
1189
 
 
1190
    snprintf(buffer, buf_len, cc_fs, cc);
 
1191
 
 
1192
    return buffer;
 
1193
}
 
1194
 
 
1195
 
 
1196
static const char *sol_error_codes[] =
 
1197
{
 
1198
        "SoLCharTransUnavail",
 
1199
        "SoLDeactivated",
 
1200
        "SoLNotAvailable",
 
1201
        "SoLDisconnected",
 
1202
        "SoLUnconfirmOp",
 
1203
        "SoLFlushed",
 
1204
        "SoLUnknown"
 
1205
};
 
1206
 
 
1207
static const char *rmcpp_error_codes[] =
 
1208
{
 
1209
        "InsufResourForSess",
 
1210
        "InvalSessID",
 
1211
        "InvalPayloadType",
 
1212
        "InvalAuthAlg",
 
1213
        "InvalIntegAlg",
 
1214
        "NoMatchAuthPayld",
 
1215
        "NoMatchIntegPayld",
 
1216
        "InactSessID",
 
1217
        "InvalidRole",
 
1218
        "UnauthRoleOrPriv",
 
1219
        "InsufResourForRole",
 
1220
        "InvalNameLength",
 
1221
        "UnauthName",
 
1222
        "UnauthGUID",
 
1223
        "InvalIntegChkVal",
 
1224
        "InvalConfidAlg",
 
1225
        "NoCipherSuiteMatch",
 
1226
        "IllegalParam",
 
1227
        "RMCPPUnknown"
 
1228
};
 
1229
 
 
1230
char *
 
1231
ipmi_get_error_string(unsigned int err,
 
1232
                        char *buffer,
 
1233
                        unsigned int buf_len)
 
1234
{
 
1235
        char *temp_buffer;
 
1236
        char *err_type;
 
1237
 
 
1238
        if (err == 0)
 
1239
        {
 
1240
                strncpy(buffer, "Success (No error)", buf_len);
 
1241
                return buffer;
 
1242
        }
 
1243
 
 
1244
        temp_buffer = ipmi_mem_alloc(buf_len);
 
1245
        if (!temp_buffer)
 
1246
                temp_buffer = buffer;
 
1247
 
 
1248
        if (IPMI_IS_OS_ERR(err))
 
1249
        {
 
1250
                strncpy(temp_buffer, strerror(IPMI_GET_OS_ERR(err)), buf_len);
 
1251
                err_type = "OS";
 
1252
        } else if (IPMI_IS_IPMI_ERR(err))
 
1253
        {
 
1254
                ipmi_get_cc_string(IPMI_GET_IPMI_ERR(err), temp_buffer, buf_len);
 
1255
                err_type = "IPMI";
 
1256
        } else if (IPMI_IS_RMCPP_ERR(err))
 
1257
        {
 
1258
                int rmcpp_err = IPMI_GET_RMCPP_ERR(err);
 
1259
                if ((rmcpp_err <= 0) && (rmcpp_err > 0x12))
 
1260
                        rmcpp_err = 0x13;
 
1261
                snprintf(temp_buffer, buf_len, "%s (0x%02x)", rmcpp_error_codes[rmcpp_err - 1], IPMI_GET_RMCPP_ERR(err));
 
1262
                err_type = "RMCP+";
 
1263
        } else if (IPMI_IS_SOL_ERR(err))
 
1264
        {
 
1265
                int sol_err = IPMI_GET_SOL_ERR(err);
 
1266
                if ((sol_err < 1) || (sol_err > 7))
 
1267
                        sol_err = 7;
 
1268
                snprintf(temp_buffer, buf_len, sol_error_codes[sol_err - 1]);
 
1269
                err_type = "SoL";
 
1270
        }
 
1271
        else
 
1272
        {
 
1273
                strncpy(temp_buffer, "Unknown", buf_len);
 
1274
                err_type = "Unknown";
 
1275
        }
 
1276
 
 
1277
        if (temp_buffer != buffer)
 
1278
        {
 
1279
                snprintf(buffer, buf_len, "%s: %s", err_type, temp_buffer);
 
1280
                ipmi_mem_free(temp_buffer);
 
1281
        }
 
1282
 
 
1283
        return buffer;
 
1284
}
 
1285
 
 
1286
/* Get a string name fo the hot swap state. */
 
1287
const char *
 
1288
ipmi_hot_swap_state_name(enum ipmi_hot_swap_states state)
 
1289
{
 
1290
    switch (state) {
 
1291
    case IPMI_HOT_SWAP_NOT_PRESENT: return "not_present";
 
1292
    case IPMI_HOT_SWAP_INACTIVE: return "inactive";
 
1293
    case IPMI_HOT_SWAP_ACTIVATION_REQUESTED: return "activation_requested";
 
1294
    case IPMI_HOT_SWAP_ACTIVATION_IN_PROGRESS: return "activation_in_progress";
 
1295
    case IPMI_HOT_SWAP_ACTIVE: return "active";
 
1296
    case IPMI_HOT_SWAP_DEACTIVATION_REQUESTED: return "deactivation_requested";
 
1297
    case IPMI_HOT_SWAP_DEACTIVATION_IN_PROGRESS: return "deactivation_in_progress";
 
1298
    case IPMI_HOT_SWAP_OUT_OF_CON: return "out_of_con";
 
1299
    default: return "invalid_state";
 
1300
    }
 
1301
}
 
1302
 
 
1303
static char *domain_types[] =
 
1304
{
 
1305
    "unknown",
 
1306
    "MXP",
 
1307
    "ATCA",
 
1308
};
 
1309
#define NUM_DOMAIN_TYPES (sizeof(domain_types)/sizeof(char *))
 
1310
 
 
1311
const char *
 
1312
ipmi_domain_get_type_string(enum ipmi_domain_type dtype)
 
1313
{
 
1314
    if ((dtype < 0) || (dtype >= NUM_DOMAIN_TYPES))
 
1315
        return "invalid";
 
1316
    return domain_types[dtype];
 
1317
}
 
1318
 
 
1319
const char *
 
1320
ipmi_authtype_string(int authtype)
 
1321
{
 
1322
    switch(authtype) {
 
1323
    case IPMI_AUTHTYPE_DEFAULT:
 
1324
        return "default";
 
1325
    case IPMI_AUTHTYPE_NONE:
 
1326
        return "none";
 
1327
    case IPMI_AUTHTYPE_MD2:
 
1328
        return "md2";
 
1329
    case IPMI_AUTHTYPE_MD5:
 
1330
        return "md5";
 
1331
    case IPMI_AUTHTYPE_STRAIGHT:
 
1332
        return "straight";
 
1333
    case IPMI_AUTHTYPE_OEM:
 
1334
        return "oem";
 
1335
    case IPMI_AUTHTYPE_RMCP_PLUS:
 
1336
        return "rmcp+";
 
1337
    default:
 
1338
        return "invalid";
 
1339
    }
 
1340
}
 
1341
 
 
1342
const char *
 
1343
ipmi_privilege_string(int privilege)
 
1344
{
 
1345
    switch(privilege) {
 
1346
    case IPMI_PRIVILEGE_CALLBACK:
 
1347
        return "callback";
 
1348
    case IPMI_PRIVILEGE_USER:
 
1349
        return "user";
 
1350
    case IPMI_PRIVILEGE_OPERATOR:
 
1351
        return "operator";
 
1352
    case IPMI_PRIVILEGE_ADMIN:
 
1353
        return "admin";
 
1354
    case IPMI_PRIVILEGE_OEM:
 
1355
        return "oem";
 
1356
    default:
 
1357
        return "invalid";
 
1358
    }
 
1359
}