RbuHdr.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  * vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0:
00003  *
00004  * Copyright (C) 2005 Dell Inc.
00005  *  by Michael Brown <Michael_E_Brown@dell.com>
00006  * Licensed under the Open Software License version 2.1
00007  *
00008  * Alternatively, you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published
00010  * by the Free Software Foundation; either version 2 of the License,
00011  * or (at your option) any later version.
00012  
00013  * This program is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  */
00018 
00019 // compat header should always be first header if including system headers
00020 #include "smbios/compat.h"
00021 
00022 #include <iostream>
00023 #include <iomanip>
00024 
00025 #include "RbuImpl.h"
00026 
00027 // always include last if included.
00028 #include "smbios/message.h"  // not needed outside of this lib. (mainly for gettext i18n)
00029 
00030 using namespace std;
00031 
00032 namespace rbu
00033 {
00034     // bits 8:10 are hw rev id, extract them and paste the rest together
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 

Generated on Tue Jul 11 20:46:46 2006 for SMBIOS Library by  doxygen 1.4.7