File: ipmi_event.cpp

package info (click to toggle)
openhpi 2.14.1-1.2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 20,380 kB
  • sloc: ansic: 187,087; cpp: 32,188; sh: 10,415; makefile: 4,467; perl: 1,529
file content (163 lines) | stat: -rw-r--r-- 4,058 bytes parent folder | download | duplicates (8)
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
/*
 * ipmi_event.c
 *
 * Copyright (c) 2003 by FORCE Computers
 * Copyright (c) 2007 by ESO Technologies.
 *
 * Note that this file is based on parts of OpenIPMI
 * written by Corey Minyard <minyard@mvista.com>
 * of MontaVista Software. Corey's code was helpful
 * and many thanks go to him. He gave the permission
 * to use this code in OpenHPI under BSD license.
 *
 * This program 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.  This
 * file and program are licensed under a BSD style license.  See
 * the Copying file included with the OpenHPI distribution for
 * full licensing terms.
 *
 * Authors:
 *     Thomas Kanngieser <thomas.kanngieser@fci.com>
 *     Pierre Sangouard  <psangouard@eso-tech.com>
 */

#include <string.h>

#include "ipmi_event.h"
#include "ipmi_utils.h"
#include "ipmi_log.h"
#include "ipmi_sensor.h"
#include "ipmi_mc.h"


static const char *thres_map[] =
{
  "LowerNonCritical",
  "LowerCritical",
  "LowerNonRecoverable",
  "UpperNonCritical",
  "UpperCritical",
  "UpperNonRecoverable"
};

static int thres_map_num = sizeof( thres_map ) / sizeof( char * );


const char *
IpmiThresToString( tIpmiThresh val )
{
  if ( val >= thres_map_num )
       return "invalid";

  return thres_map[val];
}


void 
IpmiThresholdMaskToString( unsigned int mask, char *str )
{
  *str = 0;

  for( int i = 0; i < 6; i++ )
       if ( mask & ( 1 << i ) )
          {
            if ( *str )
                 strcat( str, " | " );

            strcat( str, thres_map[i] );
          }
}


cIpmiEvent::cIpmiEvent()
  : m_mc( 0 ), m_record_id( 0 ), m_type( 0 )
{
  memset( m_data, 0, dIpmiMaxSelData );
}


int
cIpmiEvent::Cmp( const cIpmiEvent &event2 ) const
{
  //  if ( event1->mc != event2->mc )
  //       return 1;

  if ( m_record_id > event2.m_record_id )
       return 1;

  if ( m_record_id < event2.m_record_id )
       return -1;

  if ( m_type > event2.m_type )
	return 1;

  if ( m_type < event2.m_type )
       return -1;

  return memcmp( m_data, event2.m_data, 13 );
}


void
cIpmiEvent::Dump( cIpmiLog &dump, const char *name ) const
{
  dump.Begin( "Event", name );
  dump.Entry( "RecordId" ) << m_record_id << ";\n";

  char str[80];

  if ( m_type == 0x02 )
       strcpy( str, "SystemEvent" );
  else
       snprintf( str, sizeof(str), "0x%02x", m_type );

  dump.Entry( "RecordType" ) << str << ";\n";

  unsigned int t = IpmiGetUint32( m_data );
  dump.Hex( true );
  dump.Entry( "Timestamp" ) << t << ";\n";
  dump.Hex( false );

  dump.Entry( "SlaveAddr" ) << m_data[4] << ";\n";
  dump.Entry( "Channel" ) << (m_data[5] >> 4) << ";\n";
  dump.Entry( "Lun" ) << (m_data[5] & 3 ) << ";\n";
  dump.Entry( "Revision" ) << (unsigned int)m_data[6] << ";\n";

  tIpmiSensorType sensor_type = (tIpmiSensorType)m_data[7];

  if ( !strcmp( IpmiSensorTypeToString( sensor_type ), "Invalid" ) )
       snprintf( str, sizeof(str), "0x%02x", sensor_type );
  else
       snprintf( str, sizeof(str), "%s", IpmiSensorTypeToString( sensor_type ) );

  dump.Entry( "SensorType" ) << str << ";\n";

  snprintf( str, sizeof(str), "0x%02x", m_data[8] );
  dump.Entry( "SensorNum" ) << str << ";\n";

  dump.Entry( "EventDirection" ) << ((m_data[9] & 0x80) ?
				     "Deassertion" 
				     : "Assertion" )
				 << ";\n";

  tIpmiEventReadingType reading_type = (tIpmiEventReadingType)(m_data[9] & 0x7f);

  if ( !strcmp( IpmiEventReadingTypeToString( reading_type ), "Invalid" ) )
       snprintf( str, sizeof(str), "0x%02x", reading_type );
  else
       snprintf( str, sizeof(str), "%s", IpmiEventReadingTypeToString( reading_type ) );

  dump.Entry( "EventReadingType" ) << str << ";\n";

  snprintf( str, sizeof(str), "0x%02x", m_data[10] );
  dump.Entry( "EventData1" ) << str << ";\n";

  snprintf( str, sizeof(str), "0x%02x", m_data[11] );
  dump.Entry( "EventData2" ) << str << ";\n";

  snprintf( str, sizeof(str), "0x%02x", m_data[12] );
  dump.Entry( "EventData3" ) << str << ";\n";

  dump.End();
}