00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "smbios/compat.h"
00021
00022 #include <iostream>
00023 #include <iomanip>
00024
00025 #include "RbuImpl.h"
00026
00027
00028 #include "smbios/message.h"
00029
00030 using namespace std;
00031
00032 namespace rbu
00033 {
00034
00035 static u16 extractSystemId(u16 val)
00036 {
00037 return (val & 0xFF) | ((val & 0xF800) >> 3);
00038 }
00039
00040 static struct rbu_hdr_file_header getHdr(string fileName)
00041 {
00042 struct rbu_hdr_file_header hdr;
00043 memset(&hdr, 0, sizeof(hdr));
00044
00045 FILE *hdr_fh = fopen(fileName.c_str(), "rb");
00046 if(!hdr_fh)
00047 throw exception();
00048
00049 fread(&hdr, 1, sizeof(hdr), hdr_fh);
00050 fclose(hdr_fh);
00051
00052 return hdr;
00053 }
00054
00055 bool checkSystemId(string fileName, u16 sysId )
00056 {
00057 struct rbu_hdr_file_header hdr = getHdr(fileName);
00058 for (int i=0; i<hdr.numSystems; i++)
00059 if( extractSystemId(hdr.systemIdList[i]) == sysId )
00060 return true;
00061
00062 return false;
00063 }
00064
00065 std::string getHdrBiosVer(std::string fileName)
00066 {
00067 struct rbu_hdr_file_header hdr = getHdr(fileName);
00068 return hdr.biosVersion;
00069 }
00070
00071
00072 void dumpHdrInfo(string fileName)
00073 {
00074 cout << "file: " << fileName << endl;
00075
00076 struct rbu_hdr_file_header hdr = getHdr(fileName);
00077
00078 cout << "HeaderId: "
00079 << hdr.headerId[0]
00080 << hdr.headerId[1]
00081 << hdr.headerId[2]
00082 << hdr.headerId[3] << endl;
00083
00084 cout << "Header Length: " << static_cast<int>(hdr.headerLength) << endl;
00085 cout << "Header Major Ver: " << static_cast<int>(hdr.headerMajorVer) << endl;
00086 cout << "Header Minor Ver: " << static_cast<int>(hdr.headerMinorVer) << endl;
00087 cout << "Num Systems: " << static_cast<int>(hdr.numSystems) << endl;
00088
00089 cout << "Version: " << hdr.biosVersion << endl;
00090
00091 char quickCheck[41] = {0};
00092 strncpy(quickCheck, hdr.quickCheck, 40);
00093 cout << "Quick Check: " << quickCheck << endl;
00094
00095 cout << "System ID List:" << hex;
00096 for (int i=0; i<hdr.numSystems; i++)
00097 cout << " 0x" << setfill ('0') << setw (4) << static_cast<int>(extractSystemId(hdr.systemIdList[i]));
00098 cout << endl;
00099 }
00100 }
00101