20 #define LIBSMBIOS_SOURCE
38 u32 indexPort,
u32 dataPort );
41 u32 indexPort,
u32 dataPort,
bool complement );
44 u32 indexPort,
u32 dataPort );
48 CmosRWChecksumObserver::CmosRWChecksumObserver(
51 int initCheckType,
u32 initIndexPort,
u32 initDataPort,
52 u32 initStart,
u32 initEnd,
u32 initChecksumLocation )
55 description(initDesc),
57 checkType(initCheckType),
58 indexPort(initIndexPort),
59 dataPort(initDataPort),
62 checksumLocation(initChecksumLocation)
73 description(source.description),
75 checkType(source.checkType),
76 indexPort(source.indexPort),
77 dataPort(source.dataPort),
80 checksumLocation(source.checksumLocation)
103 u8 len =
sizeof(wordRetval);
104 chksum =
reinterpret_cast<const u8 *
>(&wordRetval);
110 ost <<
_(
"Checksum check for CMOS value does not match.") << endl;
111 InvalidChecksumImpl invalidChecksum;
121 ost <<
_(
"SMBIOS-specified checksum type is Byte Checksum. Type %(byte_chksum_type)i") << endl;
123 wordRetval =
byteChecksum(cmos, start, end, indexPort, dataPort);
127 ost <<
_(
"SMBIOS-specified checksum type is Word Checksum. Type %(word_chksum_type)i") << endl;
128 wordRetval =
wordChecksum(cmos, start, end, indexPort, dataPort,
false);
131 ost <<
_(
"SMBIOS-specified checksum type is One's Complement Word Checksum. Type %(word_chksum_n_type)i") << endl;
132 wordRetval =
wordChecksum(cmos, start, end, indexPort, dataPort,
true);
135 ost <<
_(
"SMBIOS-specified checksum type is Word CRC. Type %(word_crc_type)i") << endl;
136 wordRetval =
wordCrc(cmos, start, end, indexPort, dataPort);
139 ostringstream chkost;
141 chkost <<
_(
"Unknown checksum type encountered: ");
150 if( !doUpdate || *static_cast<bool*>(doUpdate) )
153 u32 actualChksum = 0;
154 u32 calculatedChksum = 0;
155 for(
int i=0; i<len; ++i )
158 actualChksum = (actualChksum << 8) | byte;
159 calculatedChksum = calculatedChksum | (chksum[i] << (8*i));
161 if( actualChksum != calculatedChksum )
165 for(
int i=0; i<len; ++i )
176 u32 actualChksum = 0;
177 u32 calculatedChksum = 0;
178 for(
int i=0; i<len; ++i )
181 actualChksum = (actualChksum << 8) | byte;
182 calculatedChksum = calculatedChksum | (chksum[i] << (8*i));
184 if( actualChksum != calculatedChksum )
186 ost <<
_(
"Checking alternate checksum algorithm results.") << endl
187 <<
_(
"Calculated (Type %(word_chksum_type)i) word checksum is: %(calc_word)i") << endl
188 <<
_(
"Calculated (Type %(byte_chksum_type)i) byte checksum is: %(calc_byte)i") << endl
189 <<
_(
"Calculated (Type %(word_crc_type)i) word crc is: %(calc_crc)i") << endl
190 <<
_(
"Calculated (Type %(word_chksum_n_type)i) 1's complement word checksum is: %(calc_word_n)i") << endl
191 <<
_(
"Actual data value is: %(actual)i") << endl
192 <<
_(
"Calculated data value is: %(calc)i") << endl
193 <<
_(
"Start: %(start)i") << endl
194 <<
_(
"End: %(end)i") << endl
195 <<
_(
"Checksum Loc: %(checksumLocation)i") << endl
196 <<
_(
"Index Port: %(index)i") << endl
197 <<
_(
"Data Port: %(data)i") << endl;
203 invalidChecksum.setParameter(
"calc_byte",
byteChecksum(cmos, start, end, indexPort, dataPort));
204 invalidChecksum.setParameter(
"calc_word",
wordChecksum(cmos, start, end, indexPort, dataPort,
false));
205 invalidChecksum.setParameter(
"calc_word_n",
wordChecksum(cmos, start, end, indexPort, dataPort,
true));
206 invalidChecksum.setParameter(
"calc_crc",
wordCrc(cmos, start, end, indexPort, dataPort));
207 invalidChecksum.setParameter(
"actual", actualChksum);
208 invalidChecksum.setParameter(
"calc", calculatedChksum);
209 invalidChecksum.setParameter(
"start", start);
210 invalidChecksum.setParameter(
"end", end);
212 invalidChecksum.setParameter(
"index", indexPort);
213 invalidChecksum.setParameter(
"data", dataPort);
215 invalidChecksum.setMessageString( ost.str() );
216 throw invalidChecksum;
228 u32 indexPort,
u32 dataPort )
230 u8 running_checksum=0;
232 for(
u32 i = start; i <= end; i++)
235 running_checksum = running_checksum + cmos->
readByte( indexPort, dataPort, i );
238 return static_cast<u8>(running_checksum);
244 u32 indexPort,
u32 dataPort,
bool complement )
246 u16 running_checksum=0;
248 for(
u32 i = start; i <= end; i++)
251 running_checksum = running_checksum + cmos->
readByte( indexPort, dataPort, i );
255 running_checksum = (~running_checksum) + 1;
256 return running_checksum;
262 u32 indexPort,
u32 dataPort )
266 for(
u32 i = start; i <= end; i++)
268 running_crc ^= cmos->
readByte( indexPort, dataPort, i );
270 for(
int j=0; j<7; j++ )
272 u16 temp = running_crc & 0x0001;
276 running_crc |= 0x8000;
277 running_crc ^= 0xA001;