Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

TokenImpl.h

Go to the documentation of this file.
00001 // vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:
00002 /*
00003  * Copyright (C) 2005 Dell Inc.
00004  *  by Michael Brown <Michael_E_Brown@dell.com>
00005  * Licensed under the Open Software License version 2.1
00006  *
00007  * Alternatively, you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published
00009  * by the Free Software Foundation; either version 2 of the License,
00010  * or (at your option) any later version.
00011 
00012  * This program is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00015  * See the GNU General Public License for more details.
00016  */
00017 
00018 #ifndef TOKENIMPL_H
00019 #define TOKENIMPL_H
00020 
00021 // compat header should always be first header
00022 #include "smbios/compat.h"
00023 
00024 #include <vector>
00025 
00026 // types.h should be first user-defined header.
00027 #include "smbios/types.h"
00028 
00029 // Include I*.h headers first
00030 #include "smbios/IToken.h"
00031 #include "smbios/ICmosRW.h"
00032 #include "smbios/ISmbios.h"
00033 #include "smbios/IObserver.h"
00034 #include "ExceptionImpl.h"
00035 
00036 #include "TokenLowLevel.h"
00037 
00038 
00039 namespace smbios
00040 {
00041     DEFINE_EXCEPTION_EX( InvalidTokenTableModeImpl, smbios, InvalidTokenTableMode );
00042     DEFINE_EXCEPTION_EX( InvalidAccessModeImpl, smbios, InvalidAccessMode );
00043     DEFINE_EXCEPTION_EX( DerefNullPointerImpl, smbios, DerefNullPointer );
00044     DEFINE_EXCEPTION_EX( ParameterErrorImpl, smbios, ParameterError );
00045     DEFINE_EXCEPTION_EX( InvalidChecksumImpl, smbios, InvalidChecksum );
00046     DEFINE_EXCEPTION_EX( NeedAuthenticationImpl, smbios, NeedAuthentication );
00047 
00048     // forward declarations
00049     class CmosTokenD4;
00050     class TokenTableIterator;
00051     class TokenTableConstIterator;
00052     class CmosRWChecksumObserver;
00053 
00054     class TokenTable: public ITokenTable
00055     {
00056     public:
00057         TokenTable( const smbios::ISmbiosTable & );
00058         virtual ~TokenTable();
00059 
00060         // ITERATORS
00061         virtual iterator begin ();
00062         virtual const_iterator begin () const;
00063 
00064         virtual iterator end ();
00065         virtual const_iterator end () const;
00066 
00067         virtual iterator operator[]( const int );
00068         virtual const_iterator operator[]( const int ) const;
00069 
00070         virtual iterator operator[]( const std::string & );
00071         virtual const_iterator operator[]( const std::string & ) const;
00072 
00073         virtual std::ostream & streamify( std::ostream & cout ) const;
00074 
00075         friend class TokenTableIteratorBase;
00076 
00077     protected:
00078         void addD4Structures(const smbios::ISmbiosTable & table);
00079         void addD5Structures(const smbios::ISmbiosTable & table);
00080         void addD6Structures(const smbios::ISmbiosTable & table);
00081         void addDAStructures(const smbios::ISmbiosTable & table);
00082         void getD4TokensFromStruct(const smbios::ISmbiosTable::const_iterator &item, const u8 *ptr, size_t size);
00083         void getDATokensFromStruct(const smbios::ISmbiosTable::const_iterator &item, const u8 *ptr, size_t size);
00084         void addChecksumObserverForD4Struct(const smbios::ISmbiosTable::const_iterator &item, const u8 *ptr, size_t size);
00085 
00086 
00087         std::vector< IToken *> tokenList;
00088         std::vector< CmosRWChecksumObserver > checksumList;
00089 
00090     private:
00091         // No-arg constructor not legal for this class for outside parties
00092         TokenTable();
00093 
00094     };
00095 
00096     class CmosTokenD4 : public IToken, public ICmosToken
00097     {
00098     public:
00099         CmosTokenD4( const smbios::ISmbiosItem &item, const indexed_io_token *token );
00100         virtual ~CmosTokenD4() throw();
00101 
00102         u32 getType() const;
00103 
00104         virtual bool isActive() const;
00105         virtual void activate() const;
00106         virtual bool isString() const;
00107         virtual bool isBool() const;
00108         virtual unsigned int getStringLength() const;
00109         virtual const std::string getString( u8 *byteArray = 0, unsigned int size = 0 ) const;
00110         virtual void setString( const u8 *byteArray, size_t size ) const;
00111 
00112         virtual const ISmbiosItem &getItemRef() const;
00113         virtual void getCMOSDetails( u16 *indexPort, u16 *dataPort, u8 *location ) const;
00114 
00115         virtual std::string getTokenClass() const;
00116 
00117         virtual std::ostream & streamify( std::ostream & cout ) const;
00118 
00119     protected:
00120         CmosTokenD4();
00121         CmosTokenD4(const CmosTokenD4 &);
00122         void operator = (const CmosTokenD4 &);
00123 
00124     private:
00125         std::auto_ptr<const smbios::ISmbiosItem> item;
00126         indexed_io_access_structure structure;
00127         indexed_io_token token;
00128         cmos::ICmosRW  *cmos;  // NEVER DELETE THIS!
00129         //lifetime is managed by the cmosrw factory
00130     };
00131 
00132     class CmosTokenD5 : public IToken, public ICmosToken, public IProtectedToken
00133     {
00134     public:
00135         CmosTokenD5( const smbios::ISmbiosItem &item, std::vector< CmosRWChecksumObserver > &initChecksumList);
00136         virtual ~CmosTokenD5() throw();
00137 
00138         u32 getType() const;
00139 
00140         virtual bool isActive() const;
00141         virtual void activate() const;
00142         virtual bool isString() const;
00143         virtual bool isBool() const;
00144         virtual unsigned int getStringLength() const;
00145         virtual const std::string getString( u8 *byteArray = 0, unsigned int size = 0 ) const;
00146         virtual void setString( const u8 *byteArray, size_t size ) const;
00147 
00148         virtual const ISmbiosItem &getItemRef() const;
00149         virtual void getCMOSDetails( u16 *indexPort, u16 *dataPort, u8 *location ) const;
00150         virtual bool tryPassword(std::string pw) const;
00151         virtual std::string getTokenClass() const;
00152         virtual u32 getValueFormat() const;
00153 
00154         virtual std::ostream & streamify( std::ostream & cout ) const;
00155 
00156     protected:
00157         CmosTokenD5();
00158         CmosTokenD5(const CmosTokenD5 &);
00159         void operator = (const CmosTokenD5 &);
00160 
00161         virtual void addChecksumObserver() const;
00162 
00163         dell_protected_value_1_structure structure;
00164         std::auto_ptr<const smbios::ISmbiosItem> item;
00165         cmos::ICmosRW  *cmos;  // NEVER DELETE THIS!
00166         //lifetime is managed by the cmosrw factory
00167         std::string validationKey;
00168         std::vector< CmosRWChecksumObserver > &checksumList;
00169     };
00170 
00171     class CmosTokenD6 : public CmosTokenD5
00172     {
00173     public:
00174         CmosTokenD6( const smbios::ISmbiosItem &item, std::vector< CmosRWChecksumObserver > &initChecksumList);
00175         virtual std::string getTokenClass() const;
00176 
00177     protected:
00178         CmosTokenD6();
00179         CmosTokenD6(const CmosTokenD6 &);
00180         void operator = (const CmosTokenD6 &);
00181 
00182         virtual void addChecksumObserver() const;
00183 
00184     private:
00185         dell_protected_value_2_structure structure;
00186     };
00187 
00188     class SmiTokenDA : public IToken, public ISmiToken, public IProtectedToken
00189     {
00190     public:
00191         SmiTokenDA( const smbios::ISmbiosItem &item, const calling_interface_token *token );
00192         virtual ~SmiTokenDA() throw();
00193 
00194         u32 getType() const;
00195 
00196         virtual bool isActive() const;
00197         virtual void activate() const;
00198         virtual bool isString() const;
00199         virtual bool isBool() const;
00200         virtual unsigned int getStringLength() const;
00201         virtual const std::string getString( u8 *byteArray = 0, unsigned int size = 0 ) const;
00202         virtual void setString( const u8 *byteArray, size_t size ) const;
00203         virtual const ISmbiosItem &getItemRef() const;
00204         virtual std::string getTokenClass() const;
00205         virtual u32 getValueFormat() const;
00206         virtual bool tryPassword(std::string pw) const;
00207         virtual std::ostream & streamify( std::ostream & cout ) const;
00208         virtual void getSmiDetails(  u16 *cmdIOAddress, u8 *cmdIOCode, u8 *location ) const;
00209 
00210     protected:
00211         SmiTokenDA();
00212         SmiTokenDA(const SmiTokenDA &);
00213         void operator = (const SmiTokenDA &);
00214 
00215     private:
00216         std::auto_ptr<const smbios::ISmbiosItem> item;
00217         calling_interface_structure structure;
00218         calling_interface_token token;
00219         mutable std::string password;
00220     };
00221 
00222     // fixes up checksums on a cmos object
00223     // when the cmos object is written to
00224     class CmosRWChecksumObserver : public observer::IObserver
00225     {
00226     public:
00227         CmosRWChecksumObserver( std::string description, cmos::ICmosRW *cmos, int checkType, u32 indexPort, u32 dataPort, u32 start, u32 end, u32 checksumLocation  );
00228         CmosRWChecksumObserver( const CmosRWChecksumObserver &source );
00229         // called when the observed cmos changes
00230         // doUpdate should be bool*.  not very safe, but hey, this is C.
00231         virtual void update( const observer::IObservable *whatChanged, void *doUpdate );
00232         virtual ~CmosRWChecksumObserver();
00233     private:
00234         std::string description;
00235         cmos::ICmosRW *cmos;
00236         int checkType;
00237         u32 indexPort;
00238         u32 dataPort;
00239         u32 start;
00240         u32 end;
00241         u32 checksumLocation;
00242     };
00243 
00244     enum
00245     {
00246         CHECK_TYPE_WORD_CHECKSUM   = 0x00, //simple running sum in word
00247         CHECK_TYPE_BYTE_CHECKSUM   = 0x01, //simple running sum in byte
00248         CHECK_TYPE_WORD_CRC        = 0x02, // crc
00249         CHECK_TYPE_WORD_CHECKSUM_N = 0x03, //simple runnign sum in word, then (~result + 1)
00250     };
00251 
00252 
00253 
00254 }
00255 
00256 #endif  /* TOKEN_H */

Generated on Wed Apr 11 16:25:10 2007 for SMBIOS Library by doxygen 1.3.5