1 /*****************************************************************************\
2  *  $Id: ipmi-sdr-defs.h,v 1.13 2010-02-08 22:09:40 chu11 Exp $
3  *****************************************************************************
4  *  Copyright (C) 2007-2015 Lawrence Livermore National Security, LLC.
5  *  Copyright (C) 2006-2007 The Regents of the University of California.
6  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
7  *  Written by Albert Chu <chu11@llnl.gov>
8  *  UCRL-CODE-222073
9  *
10  *  This file is part of Ipmimonitoring, an IPMI sensor monitoring
11  *  library.  For details, see http://www.llnl.gov/linux/.
12  *
13  *  Ipmimonitoring is free software; you can redistribute it and/or modify
14  *  it under the terms of the GNU General Public License as published by the
15  *  Free Software Foundation; either version 3 of the License, or (at your
16  *  option) any later version.
17  *
18  *  Ipmimonitoring is distributed in the hope that it will be useful, but
19  *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21  *  for more details.
22  *
23  *  You should have received a copy of the GNU General Public License along
24  *  with Ipmimonitoring.  If not, see <http://www.gnu.org/licenses/>.
25 \*****************************************************************************/
26 
27 #ifndef IPMI_SDR_DEFS_H
28 #define IPMI_SDR_DEFS_H
29 
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif /* HAVE_CONFIG_H */
33 
34 #include <stdint.h>
35 #include <sys/types.h>          /* off_t */
36 #include <sys/param.h>
37 #if HAVE_UNISTD_H
38 #include <unistd.h>             /* off_t */
39 #endif /* HAVE_UNISTD_H */
40 
41 #include "freeipmi/sdr/ipmi-sdr.h"
42 
43 #include "list.h"
44 
45 #ifndef MAXPATHLEN
46 #define MAXPATHLEN 4096
47 #endif /* MAXPATHLEN */
48 
49 #define IPMI_SDR_CTX_MAGIC        0xABCD9876
50 
51 #define IPMI_SDR_OPERATION_UNINITIALIZED  0
52 #define IPMI_SDR_OPERATION_CREATE_CACHE   1
53 #define IPMI_SDR_OPERATION_READ_CACHE     2
54 #define IPMI_SDR_OPERATION_DELETE_CACHE   3
55 
56 /* Why use indexes instead of fiid templates?  B/c that's how it was
57  * written before libipmimonitoring's libipmisdrcache was written before
58  * it was included in freeipmi.
59  */
60 #define IPMI_SDR_RECORD_HEADER_LENGTH               5
61 #define IPMI_SDR_RECORD_LENGTH_INDEX                4
62 #define IPMI_SDR_RECORD_ID_INDEX_LS                 0
63 #define IPMI_SDR_RECORD_ID_INDEX_MS                 1
64 #define IPMI_SDR_RECORD_TYPE_INDEX                  3
65 #define IPMI_SDR_RECORD_SENSOR_OWNER_ID_INDEX       5
66 #define IPMI_SDR_RECORD_SENSOR_NUMBER_INDEX         7
67 #define IPMI_SDR_RECORD_COMPACT_SHARE_COUNT         23
68 #define IPMI_SDR_RECORD_COMPACT_SHARE_COUNT_BITMASK 0x0F
69 #define IPMI_SDR_RECORD_COMPACT_SHARE_COUNT_SHIFT   0
70 #define IPMI_SDR_RECORD_EVENT_SHARE_COUNT           12
71 #define IPMI_SDR_RECORD_EVENT_SHARE_COUNT_BITMASK   0x0F
72 #define IPMI_SDR_RECORD_EVENT_SHARE_COUNT_SHIFT     0
73 
74 #if 0
75 /* Original - sdr cache version 1.0 - keep for documentation history */
76 #define IPMI_SDR_CACHE_FILE_MAGIC_0 0xEF
77 #define IPMI_SDR_CACHE_FILE_MAGIC_1 0xE7
78 #define IPMI_SDR_CACHE_FILE_MAGIC_2 0x35
79 #define IPMI_SDR_CACHE_FILE_MAGIC_3 0x7C
80 #endif
81 
82 #define IPMI_SDR_CACHE_FILE_MAGIC_0 0x72
83 #define IPMI_SDR_CACHE_FILE_MAGIC_1 0x8C
84 #define IPMI_SDR_CACHE_FILE_MAGIC_2 0x9D
85 #define IPMI_SDR_CACHE_FILE_MAGIC_3 0x1F
86 
87 /* Cache Version 0.1 format
88  *
89  * magic bytes (4 bytes)
90  * version bytes (4)
91  * sdr version (1)
92  * record count (2)
93  * most recent addition timestamp (4)
94  * most recent erase timestamp (4)
95  * records (variable)
96  */
97 #define IPMI_SDR_CACHE_FILE_VERSION_1_0 0x00
98 #define IPMI_SDR_CACHE_FILE_VERSION_1_1 0x00
99 #define IPMI_SDR_CACHE_FILE_VERSION_1_2 0x00
100 #define IPMI_SDR_CACHE_FILE_VERSION_1_3 0x01
101 
102 /* Cache Version 1.2 format
103  *
104  * magic bytes (4 bytes)
105  * version bytes (4)
106  * sdr version (1)
107  * record count (2)
108  * most recent addition timestamp (4)
109  * most recent erase timestamp (4)
110  * header checksum (1) [all bytes above]
111  * records (variable)
112  * total bytes of file (4)
113  * trailer checksum (1) [records + total bytes of file]
114  */
115 
116 #define IPMI_SDR_CACHE_FILE_VERSION_1_2_0 0x00
117 #define IPMI_SDR_CACHE_FILE_VERSION_1_2_1 0x01
118 #define IPMI_SDR_CACHE_FILE_VERSION_1_2_2 0x00
119 #define IPMI_SDR_CACHE_FILE_VERSION_1_2_3 0x02
120 
121 #define IPMI_MAX_ENTITY_IDS          256
122 #define IPMI_MAX_ENTITY_ID_INSTANCES 256
123 
124 struct ipmi_sdr_offset {
125   off_t offset;
126   int offset_dumped;
127 };
128 
129 struct ipmi_sdr_entity_count {
130   uint8_t entity_instances[IPMI_MAX_ENTITY_ID_INSTANCES];
131   unsigned int entity_instances_count;
132 };
133 
134 struct ipmi_sdr_ctx {
135   uint32_t magic;
136   int errnum;
137   unsigned int operation;
138   unsigned int flags;
139   char *debug_prefix;
140 
141   uint8_t sdr_version;
142   uint16_t record_count;
143   uint32_t most_recent_addition_timestamp;
144   uint32_t most_recent_erase_timestamp;
145 
146   /* Cache Reading Vars */
147   int fd;
148   off_t file_size;
149   off_t records_start_offset;
150   off_t records_end_offset;
151   uint8_t *sdr_cache;
152   struct ipmi_sdr_offset current_offset;
153   int callback_lock;
154 
155   /* for saving/reset */
156   List saved_offsets;
157 
158   /* Stats */
159   int stats_compiled;
160   struct ipmi_sdr_entity_count entity_counts[IPMI_MAX_ENTITY_IDS];
161 };
162 
163 #endif /* IPMI_SDR_DEFS_H */
164