forked from maoali/freeipmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipmi_monitoring_sel.c
969 lines (856 loc) · 35.1 KB
/
ipmi_monitoring_sel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
/*****************************************************************************\
* $Id: ipmi_monitoring_sel.c,v 1.2 2010-07-22 21:49:00 chu11 Exp $
*****************************************************************************
* Copyright (C) 2007-2015 Lawrence Livermore National Security, LLC.
* Copyright (C) 2006-2007 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Albert Chu <[email protected]>
* UCRL-CODE-222073
*
* This file is part of Ipmimonitoring, an IPMI sensor monitoring
* library. For details, see http://www.llnl.gov/linux/.
*
* Ipmimonitoring is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* Ipmimonitoring is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with Ipmimonitoring. If not, see <http://www.gnu.org/licenses/>.
\*****************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <stdlib.h>
#if STDC_HEADERS
#include <string.h>
#endif /* STDC_HEADERS */
#include <assert.h>
#include <errno.h>
#include <freeipmi/freeipmi.h>
#include "ipmi_monitoring.h"
#include "ipmi_monitoring_offsets.h"
#include "ipmi_monitoring_debug.h"
#include "ipmi_monitoring_defs.h"
#include "ipmi_monitoring_ipmi_communication.h"
#include "ipmi_monitoring_parse_common.h"
#include "ipmi_monitoring_sensor_reading.h"
#include "freeipmi-portability.h"
#define IPMI_MONITORING_SEL_EVENT_OFFSET_STRING_MAX 1024
struct sel_parse_data
{
ipmi_monitoring_ctx_t c;
unsigned int sel_flags;
unsigned int *sensor_types;
unsigned int sensor_types_len;
unsigned int date_begin;
unsigned int date_end;
};
static void
_sel_cleanup (ipmi_monitoring_ctx_t c)
{
assert (c);
assert (c->magic == IPMI_MONITORING_MAGIC);
ipmi_sel_ctx_destroy (c->sel_parse_ctx);
c->sel_parse_ctx = NULL;
}
int
ipmi_monitoring_sel_init (ipmi_monitoring_ctx_t c)
{
assert (c);
assert (c->magic == IPMI_MONITORING_MAGIC);
assert (c->ipmi_ctx);
assert (c->sdr_ctx);
assert (!c->sel_parse_ctx);
if (!(c->sel_parse_ctx = ipmi_sel_ctx_create (c->ipmi_ctx, c->sdr_ctx)))
{
IPMI_MONITORING_DEBUG (("ipmi_sel_ctx_create: %s", strerror (errno)));
c->errnum = IPMI_MONITORING_ERR_OUT_OF_MEMORY;
goto cleanup;
}
return (0);
cleanup:
_sel_cleanup (c);
return (-1);
}
int
ipmi_monitoring_sel_cleanup (ipmi_monitoring_ctx_t c)
{
assert (c);
assert (c->magic == IPMI_MONITORING_MAGIC);
_sel_cleanup (c);
return (0);
}
static int
_get_event_offset_type (ipmi_monitoring_ctx_t c,
uint8_t event_type_code,
uint8_t sdr_sensor_type)
{
int event_offset_type;
assert (c);
assert (c->magic == IPMI_MONITORING_MAGIC);
assert (c->sel_records);
if (event_type_code == IPMI_EVENT_READING_TYPE_CODE_THRESHOLD)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_THRESHOLD;
else if (event_type_code == IPMI_EVENT_READING_TYPE_CODE_TRANSITION_STATE)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_TRANSITION_STATE;
else if (event_type_code == IPMI_EVENT_READING_TYPE_CODE_STATE)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_STATE;
else if (event_type_code == IPMI_EVENT_READING_TYPE_CODE_PREDICTIVE_FAILURE)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_PREDICTIVE_FAILURE;
else if (event_type_code == IPMI_EVENT_READING_TYPE_CODE_LIMIT)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_LIMIT;
else if (event_type_code == IPMI_EVENT_READING_TYPE_CODE_PERFORMANCE)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_PERFORMANCE;
else if (event_type_code == IPMI_EVENT_READING_TYPE_CODE_TRANSITION_SEVERITY)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_TRANSITION_SEVERITY;
else if (event_type_code == IPMI_EVENT_READING_TYPE_CODE_DEVICE_PRESENT)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_DEVICE_PRESENT;
else if (event_type_code == IPMI_EVENT_READING_TYPE_CODE_DEVICE_ENABLED)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_DEVICE_ENABLED;
else if (event_type_code == IPMI_EVENT_READING_TYPE_CODE_TRANSITION_AVAILABILITY)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_TRANSITION_AVAILABILITY;
else if (event_type_code == IPMI_EVENT_READING_TYPE_CODE_REDUNDANCY)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_REDUNDANCY;
else if (event_type_code == IPMI_EVENT_READING_TYPE_CODE_ACPI_POWER_STATE)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_ACPI_POWER_STATE;
else if (event_type_code == IPMI_EVENT_READING_TYPE_CODE_SENSOR_SPECIFIC)
{
if (sdr_sensor_type == IPMI_SENSOR_TYPE_PHYSICAL_SECURITY)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_PHYSICAL_SECURITY;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_PLATFORM_SECURITY_VIOLATION_ATTEMPT)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_PLATFORM_SECURITY_VIOLATION_ATTEMPT;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_PROCESSOR)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_PROCESSOR;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_POWER_SUPPLY)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_POWER_SUPPLY;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_POWER_UNIT)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_POWER_UNIT;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_COOLING_DEVICE)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_COOLING_DEVICE;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_OTHER_UNITS_BASED_SENSOR)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_OTHER_UNITS_BASED_SENSOR;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_MEMORY)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_MEMORY;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_DRIVE_SLOT)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_DRIVE_SLOT;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_POST_MEMORY_RESIZE)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_POST_MEMORY_RESIZE;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_SYSTEM_FIRMWARE_PROGRESS)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_SYSTEM_FIRMWARE_PROGRESS;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_EVENT_LOGGING_DISABLED)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_EVENT_LOGGING_DISABLED;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_WATCHDOG1)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_WATCHDOG1;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_SYSTEM_EVENT)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_SYSTEM_EVENT;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_CRITICAL_INTERRUPT)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_CRITICAL_INTERRUPT;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_BUTTON_SWITCH)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_BUTTON_SWITCH;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_MODULE_BOARD)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_MODULE_BOARD;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_MICROCONTROLLER_COPROCESSOR)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_MICROCONTROLLER_COPROCESSOR;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_ADD_IN_CARD)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_ADD_IN_CARD;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_CHASSIS)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_CHASSIS;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_CHIP_SET)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_CHIP_SET;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_OTHER_FRU)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_OTHER_FRU;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_CABLE_INTERCONNECT)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_CABLE_INTERCONNECT;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_TERMINATOR)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_TERMINATOR;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_SYSTEM_BOOT_INITIATED)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_SYSTEM_BOOT_INITIATED;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_BOOT_ERROR)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_BOOT_ERROR;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_OS_BOOT)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_OS_BOOT;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_OS_CRITICAL_STOP)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_OS_CRITICAL_STOP;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_SLOT_CONNECTOR)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_SLOT_CONNECTOR;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_SYSTEM_ACPI_POWER_STATE)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_SYSTEM_ACPI_POWER_STATE;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_WATCHDOG2)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_WATCHDOG2;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_PLATFORM_ALERT)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_PLATFORM_ALERT;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_ENTITY_PRESENCE)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_ENTITY_PRESENCE;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_MONITOR_ASIC_IC)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_MONITOR_ASIC_IC;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_LAN)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_LAN;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_MANAGEMENT_SUBSYSTEM_HEALTH)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_MANAGEMENT_SUBSYSTEM_HEALTH;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_BATTERY)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_BATTERY;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_SESSION_AUDIT)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_SESSION_AUDIT;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_VERSION_CHANGE)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_VERSION_CHANGE;
else if (sdr_sensor_type == IPMI_SENSOR_TYPE_FRU_STATE)
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_FRU_STATE;
/* To avoid gcc warnings, subtract -1 in comparison */
else if (sdr_sensor_type >= IPMI_SENSOR_TYPE_OEM_MIN
&& (sdr_sensor_type - 1) <= (IPMI_SENSOR_TYPE_OEM_MAX - 1))
{
IPMI_MONITORING_DEBUG (("sensor_type '0x%X' event offset is OEM", sdr_sensor_type));
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_OEM;
}
else
{
IPMI_MONITORING_DEBUG (("sensor_type '0x%X' event offset not supported", sdr_sensor_type));
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_UNKNOWN;
}
}
else if (event_type_code >= IPMI_EVENT_READING_TYPE_CODE_OEM_MIN
&& event_type_code <= IPMI_EVENT_READING_TYPE_CODE_OEM_MAX)
{
IPMI_MONITORING_DEBUG (("event_type_code '0x%X' event offset is OEM",
event_type_code));
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_OEM;
}
else
{
IPMI_MONITORING_DEBUG (("event_type_code '0x%X' event offset not supported",
event_type_code));
event_offset_type = IPMI_MONITORING_EVENT_OFFSET_TYPE_UNKNOWN;
}
return (event_offset_type);
}
static void
_sel_parse_ctx_error_convert (ipmi_monitoring_ctx_t c)
{
int errnum;
assert (c);
assert (c->magic == IPMI_MONITORING_MAGIC);
assert (c->ipmi_ctx);
assert (c->sel_parse_ctx);
errnum = ipmi_sel_ctx_errnum (c->sel_parse_ctx);
/* if callback error - assume we set as needed */
if (errnum != IPMI_SEL_ERR_CALLBACK_ERROR)
{
if (errnum == IPMI_SEL_ERR_IPMI_ERROR)
c->errnum = IPMI_MONITORING_ERR_IPMI_ERROR;
else if (errnum == IPMI_SEL_ERR_OUT_OF_MEMORY)
c->errnum = IPMI_MONITORING_ERR_OUT_OF_MEMORY;
else if (errnum == IPMI_SEL_ERR_SYSTEM_ERROR)
c->errnum = IPMI_MONITORING_ERR_SYSTEM_ERROR;
else
c->errnum = IPMI_MONITORING_ERR_INTERNAL_ERROR;
}
}
static int
_ipmi_monitoring_sel_parse_system_event_record (ipmi_monitoring_ctx_t c,
struct ipmi_monitoring_sel_record *s,
unsigned int sel_flags)
{
uint32_t timestamp;
uint8_t sel_sensor_type;
uint8_t sensor_number;
uint8_t event_direction;
uint8_t event_offset;
uint8_t event_type_code;
uint8_t event_data1;
uint8_t event_data2;
uint8_t event_data3;
char event_offset_string[IPMI_MONITORING_SEL_EVENT_OFFSET_STRING_MAX + 1];
int sensor_type;
unsigned int sel_string_flags;
int ret;
assert (c);
assert (c->magic == IPMI_MONITORING_MAGIC);
assert (s);
if (ipmi_sel_parse_read_timestamp (c->sel_parse_ctx,
NULL,
0,
×tamp) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_timestamp: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
s->timestamp = timestamp;
if (ipmi_sel_parse_read_sensor_type (c->sel_parse_ctx,
NULL,
0,
&sel_sensor_type) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_sensor_type: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
if ((sensor_type = ipmi_monitoring_get_sensor_type (c, sel_sensor_type)) < 0)
return (-1);
s->sensor_type = sensor_type;
if (ipmi_sel_parse_read_sensor_number (c->sel_parse_ctx,
NULL,
0,
&sensor_number) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_sensor_number: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
s->sensor_number = sensor_number;
if (ipmi_sel_parse_read_event_direction (c->sel_parse_ctx,
NULL,
0,
&event_direction) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_event_direction: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
if (event_direction == IPMI_SEL_RECORD_ASSERTION_EVENT)
s->event_direction = IPMI_MONITORING_SEL_EVENT_DIRECTION_ASSERTION;
else
s->event_direction = IPMI_MONITORING_SEL_EVENT_DIRECTION_DEASSERTION;
if (ipmi_sel_parse_read_event_data1_offset_from_event_reading_type_code (c->sel_parse_ctx,
NULL,
0,
&event_offset) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_event_data1_offset_from_event_reading_type_code: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
s->event_offset = event_offset;
if (ipmi_sel_parse_read_event_type_code (c->sel_parse_ctx,
NULL,
0,
&event_type_code) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_event_type_code: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
s->event_type_code = event_type_code;
if ((s->event_offset_type = _get_event_offset_type (c,
event_type_code,
sel_sensor_type)) < 0)
return (-1);
if (ipmi_sel_parse_read_event_data1 (c->sel_parse_ctx,
NULL,
0,
&event_data1) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_event_data1: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
s->event_data1 = event_data1;
if (ipmi_sel_parse_read_event_data2 (c->sel_parse_ctx,
NULL,
0,
&event_data2) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_event_data2: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
s->event_data2 = event_data2;
if (ipmi_sel_parse_read_event_data3 (c->sel_parse_ctx,
NULL,
0,
&event_data3) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_event_data3: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
s->event_data3 = event_data3;
sel_string_flags = IPMI_SEL_STRING_FLAGS_IGNORE_UNAVAILABLE_FIELD | IPMI_SEL_STRING_FLAGS_OUTPUT_NOT_AVAILABLE;
if (sel_flags & IPMI_MONITORING_SEL_FLAGS_ENTITY_SENSOR_NAMES)
sel_string_flags |= IPMI_SEL_STRING_FLAGS_ENTITY_SENSOR_NAMES;
if (ipmi_sel_parse_read_record_string (c->sel_parse_ctx,
"%s",
NULL,
0,
s->sensor_name,
IPMI_MONITORING_MAX_SENSOR_NAME_LENGTH,
sel_string_flags) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_record_string: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
memset (event_offset_string, '\0', IPMI_MONITORING_SEL_EVENT_OFFSET_STRING_MAX + 1);
sel_string_flags = IPMI_SEL_STRING_FLAGS_IGNORE_UNAVAILABLE_FIELD | IPMI_SEL_STRING_FLAGS_OUTPUT_NOT_AVAILABLE;
if ((ret = ipmi_sel_parse_read_record_string (c->sel_parse_ctx,
"%e",
NULL,
0,
event_offset_string,
IPMI_MONITORING_SEL_EVENT_OFFSET_STRING_MAX,
sel_string_flags)) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_record_string: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
if (ret)
{
if (!(s->event_offset_string = strdup (event_offset_string)))
{
IPMI_MONITORING_DEBUG (("strdup: %s", strerror (errno)));
c->errnum = IPMI_MONITORING_ERR_OUT_OF_MEMORY;
return (-1);
}
}
else
{
/* return empty string */
if (!(s->event_offset_string = strdup ("")))
{
IPMI_MONITORING_DEBUG (("strdup: %s", strerror (errno)));
c->errnum = IPMI_MONITORING_ERR_OUT_OF_MEMORY;
return (-1);
}
}
return (0);
}
static int
_ipmi_monitoring_sel_parse_timestamped_oem_record (ipmi_monitoring_ctx_t c,
struct ipmi_monitoring_sel_record *s)
{
uint32_t timestamp;
uint32_t manufacturer_id;
int ret;
assert (c);
assert (c->magic == IPMI_MONITORING_MAGIC);
assert (s);
if (ipmi_sel_parse_read_timestamp (c->sel_parse_ctx,
NULL,
0,
×tamp) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_timestamp: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
s->timestamp = timestamp;
if (ipmi_sel_parse_read_manufacturer_id (c->sel_parse_ctx,
NULL,
0,
&manufacturer_id) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_manufacturer_id: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
s->manufacturer_id = manufacturer_id;
if ((ret = ipmi_sel_parse_read_oem (c->sel_parse_ctx,
NULL,
0,
s->oem_data,
IPMI_MONITORING_OEM_DATA_MAX)) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_oem: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
s->oem_data_len = ret;
return (0);
}
static int
_ipmi_monitoring_sel_parse_non_timestamped_oem_record (ipmi_monitoring_ctx_t c,
struct ipmi_monitoring_sel_record *s)
{
int ret;
assert (c);
assert (c->magic == IPMI_MONITORING_MAGIC);
assert (s);
if ((ret = ipmi_sel_parse_read_oem (c->sel_parse_ctx,
NULL,
0,
s->oem_data,
IPMI_MONITORING_OEM_DATA_MAX)) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_oem: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
return (-1);
}
s->oem_data_len = ret;
return (0);
}
static int
_store_sel_record (ipmi_monitoring_ctx_t c, unsigned int sel_flags)
{
struct ipmi_monitoring_sel_record *s = NULL;
uint8_t sel_record[IPMI_SEL_RECORD_MAX_RECORD_LENGTH];
int sel_record_len;
uint16_t record_id;
uint8_t record_type;
int record_type_class;
unsigned int sel_state;
assert (c);
assert (c->magic == IPMI_MONITORING_MAGIC);
assert (c->sel_records);
if (!(s = (struct ipmi_monitoring_sel_record *)malloc (sizeof (struct ipmi_monitoring_sel_record))))
{
IPMI_MONITORING_DEBUG (("malloc: %s", strerror (errno)));
c->errnum = IPMI_MONITORING_ERR_OUT_OF_MEMORY;
goto cleanup;
}
memset (s, '\0', sizeof (struct ipmi_monitoring_sel_record));
if ((sel_record_len = ipmi_sel_parse_read_record (c->sel_parse_ctx,
sel_record,
IPMI_SEL_RECORD_MAX_RECORD_LENGTH)) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_record: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
goto cleanup;
}
if (ipmi_sel_parse_read_record_id (c->sel_parse_ctx,
NULL,
0,
&record_id) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_record_id: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
goto cleanup;
}
if (ipmi_sel_parse_read_record_type (c->sel_parse_ctx,
NULL,
0,
&record_type) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_record_id: %s",
ipmi_sel_ctx_errnum (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
goto cleanup;
}
/* IPMI Workaround
*
* HP DL 380 G5
*
* Motherboard is reporting SEL Records of record type 0x00, which
* is not a valid record type.
*/
if (sel_flags & IPMI_MONITORING_SEL_FLAGS_ASSUME_SYSTEM_EVENT_RECORD
&& !IPMI_SEL_RECORD_TYPE_VALID (record_type))
record_type = IPMI_SEL_RECORD_TYPE_SYSTEM_EVENT_RECORD;
s->record_id = record_id;
s->record_type = record_type;
if (ipmi_interpret_sel (c->interpret_ctx,
sel_record,
sel_record_len,
&sel_state) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_interpret_sel: %s",
ipmi_interpret_ctx_errormsg (c->interpret_ctx)));
c->errnum = IPMI_MONITORING_ERR_INTERNAL_ERROR;
goto cleanup;
}
if (sel_state == IPMI_INTERPRET_STATE_NOMINAL)
s->sel_state = IPMI_MONITORING_STATE_NOMINAL;
else if (sel_state == IPMI_INTERPRET_STATE_WARNING)
s->sel_state = IPMI_MONITORING_STATE_WARNING;
else if (sel_state == IPMI_INTERPRET_STATE_CRITICAL)
s->sel_state = IPMI_MONITORING_STATE_CRITICAL;
else if (sel_state == IPMI_INTERPRET_STATE_UNKNOWN)
s->sel_state = IPMI_MONITORING_STATE_UNKNOWN;
record_type_class = ipmi_sel_record_type_class (record_type);
if (record_type_class == IPMI_SEL_RECORD_TYPE_CLASS_SYSTEM_EVENT_RECORD)
{
s->record_type_class = IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_SYSTEM_EVENT_RECORD;
if (_ipmi_monitoring_sel_parse_system_event_record (c, s, sel_flags) < 0)
goto cleanup;
}
else if (record_type_class == IPMI_SEL_RECORD_TYPE_CLASS_TIMESTAMPED_OEM_RECORD)
{
s->record_type_class = IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_TIMESTAMPED_OEM_RECORD;
if (_ipmi_monitoring_sel_parse_timestamped_oem_record (c, s) < 0)
goto cleanup;
}
else if (record_type_class == IPMI_SEL_RECORD_TYPE_CLASS_NON_TIMESTAMPED_OEM_RECORD)
{
s->record_type_class = IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_NON_TIMESTAMPED_OEM_RECORD;
if (_ipmi_monitoring_sel_parse_non_timestamped_oem_record (c, s) < 0)
goto cleanup;
}
else
s->record_type_class = IPMI_MONITORING_SEL_RECORD_TYPE_CLASS_UNKNOWN;
/* achu: should come before list_append to avoid having a freed entry on the list */
if (c->callback)
{
c->callback_sel_record = s;
if ((*c->callback)(c, c->callback_data) < 0)
{
IPMI_MONITORING_DEBUG (("callback error"));
c->errnum = IPMI_MONITORING_ERR_CALLBACK_ERROR;
goto cleanup;
}
}
if (!list_append (c->sel_records, s))
{
IPMI_MONITORING_DEBUG (("list_append: %s", strerror (errno)));
c->errnum = IPMI_MONITORING_ERR_INTERNAL_ERROR;
goto cleanup;
}
return (0);
cleanup:
if (s)
{
free (s->event_offset_string);
free (s);
}
return (-1);
}
static int
_ipmi_monitoring_sel_parse_record_id (ipmi_sel_ctx_t ctx, void *callback_data)
{
struct sel_parse_data *spd;
assert (ctx);
assert (callback_data);
spd = (struct sel_parse_data *)callback_data;
/* all SEL records get stored */
if (_store_sel_record (spd->c, spd->sel_flags) < 0)
return (-1);
return (0);
}
static int
_ipmi_monitoring_sel_parse_sensor_types (ipmi_sel_ctx_t ctx, void *callback_data)
{
struct sel_parse_data *spd;
uint8_t record_type;
int record_type_class;
assert (ctx);
assert (callback_data);
spd = (struct sel_parse_data *)callback_data;
if (ipmi_sel_parse_read_record_type (spd->c->sel_parse_ctx,
NULL,
0,
&record_type) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_record_id: %s",
ipmi_sel_ctx_errnum (spd->c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (spd->c);
return (-1);
}
/* IPMI Workaround
*
* HP DL 380 G5
*
* Motherboard is reporting SEL Records of record type 0x00, which
* is not a valid record type.
*/
if (spd->sel_flags & IPMI_MONITORING_SEL_FLAGS_ASSUME_SYSTEM_EVENT_RECORD
&& !IPMI_SEL_RECORD_TYPE_VALID (record_type))
record_type = IPMI_SEL_RECORD_TYPE_SYSTEM_EVENT_RECORD;
record_type_class = ipmi_sel_record_type_class (record_type);
if (record_type_class == IPMI_SEL_RECORD_TYPE_CLASS_SYSTEM_EVENT_RECORD)
{
uint8_t sel_sensor_type;
unsigned int i;
int sensor_type;
int found = 0;
if (ipmi_sel_parse_read_sensor_type (spd->c->sel_parse_ctx,
NULL,
0,
&sel_sensor_type) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_sensor_type: %s",
ipmi_sel_ctx_errnum (spd->c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (spd->c);
return (-1);
}
if ((sensor_type = ipmi_monitoring_get_sensor_type (spd->c, sel_sensor_type)) < 0)
return (-1);
for (i = 0; i < spd->sensor_types_len; i++)
{
if (spd->sensor_types[i] == sensor_type)
{
found++;
break;
}
}
if (found)
{
if (_store_sel_record (spd->c, spd->sel_flags) < 0)
return (-1);
}
}
return (0);
}
static int
_ipmi_monitoring_sel_parse_date_range (ipmi_sel_ctx_t ctx, void *callback_data)
{
struct sel_parse_data *spd;
uint8_t record_type;
int record_type_class;
assert (ctx);
assert (callback_data);
spd = (struct sel_parse_data *)callback_data;
if (ipmi_sel_parse_read_record_type (spd->c->sel_parse_ctx,
NULL,
0,
&record_type) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_record_id: %s",
ipmi_sel_ctx_errnum (spd->c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (spd->c);
return (-1);
}
/* IPMI Workaround
*
* HP DL 380 G5
*
* Motherboard is reporting SEL Records of record type 0x00, which
* is not a valid record type.
*/
if (spd->sel_flags & IPMI_MONITORING_SEL_FLAGS_ASSUME_SYSTEM_EVENT_RECORD
&& !IPMI_SEL_RECORD_TYPE_VALID (record_type))
record_type = IPMI_SEL_RECORD_TYPE_SYSTEM_EVENT_RECORD;
record_type_class = ipmi_sel_record_type_class (record_type);
if (record_type_class == IPMI_SEL_RECORD_TYPE_CLASS_SYSTEM_EVENT_RECORD
|| record_type_class == IPMI_SEL_RECORD_TYPE_CLASS_TIMESTAMPED_OEM_RECORD)
{
uint32_t timestamp;
if (ipmi_sel_parse_read_timestamp (spd->c->sel_parse_ctx,
NULL,
0,
×tamp) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse_read_timestamp: %s",
ipmi_sel_ctx_errnum (spd->c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (spd->c);
return (-1);
}
if (timestamp >= spd->date_begin
&& timestamp <= spd->date_end)
{
if (_store_sel_record (spd->c, spd->sel_flags) < 0)
return (-1);
}
}
return (0);
}
int
ipmi_monitoring_get_sel (ipmi_monitoring_ctx_t c,
unsigned int sel_flags,
unsigned int *record_ids,
unsigned int record_ids_len,
unsigned int *sensor_types,
unsigned int sensor_types_len,
unsigned int *date_begin,
unsigned int *date_end)
{
struct sel_parse_data spd;
uint16_t *record_ids_tmp = NULL;
unsigned int i;
int rv = -1;
assert (c);
assert (c->magic == IPMI_MONITORING_MAGIC);
assert (c->ipmi_ctx);
assert (c->sel_parse_ctx);
assert (c->sel_records);
spd.c = c;
spd.sel_flags = sel_flags;
if (record_ids
&& record_ids_len)
{
/* ipmi_sel_parse takes uint16_t */
if (!((record_ids_tmp = malloc (sizeof (uint16_t) * record_ids_len))))
{
IPMI_MONITORING_DEBUG (("malloc: %s", strerror (errno)));
c->errnum = IPMI_MONITORING_ERR_OUT_OF_MEMORY;
goto cleanup;
}
for (i = 0; i < record_ids_len; i++)
record_ids_tmp[i] = record_ids[i];
if (ipmi_sel_parse_record_ids (c->sel_parse_ctx,
record_ids_tmp,
record_ids_len,
_ipmi_monitoring_sel_parse_record_id,
&spd) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse: %s",
ipmi_sel_ctx_errormsg (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
goto cleanup;
}
}
else if (sensor_types
&& sensor_types_len)
{
spd.sensor_types = sensor_types;
spd.sensor_types_len = sensor_types_len;
if (ipmi_sel_parse (c->sel_parse_ctx,
IPMI_SEL_RECORD_ID_FIRST,
IPMI_SEL_RECORD_ID_LAST,
_ipmi_monitoring_sel_parse_sensor_types,
&spd) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse: %s",
ipmi_sel_ctx_errormsg (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
goto cleanup;
}
}
else if (date_begin
&& date_end)
{
spd.date_begin = (*date_begin);
spd.date_end = (*date_end);
if (ipmi_sel_parse (c->sel_parse_ctx,
IPMI_SEL_RECORD_ID_FIRST,
IPMI_SEL_RECORD_ID_LAST,
_ipmi_monitoring_sel_parse_date_range,
&spd) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse: %s",
ipmi_sel_ctx_errormsg (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
goto cleanup;
}
}
else
{
if (ipmi_sel_parse (c->sel_parse_ctx,
IPMI_SEL_RECORD_ID_FIRST,
IPMI_SEL_RECORD_ID_LAST,
_ipmi_monitoring_sel_parse_record_id,
&spd) < 0)
{
IPMI_MONITORING_DEBUG (("ipmi_sel_parse: %s",
ipmi_sel_ctx_errormsg (c->sel_parse_ctx)));
_sel_parse_ctx_error_convert (c);
goto cleanup;
}
}
rv = 0;
cleanup:
free (record_ids_tmp);
return (rv);
}