~ubuntu-branches/ubuntu/karmic/libsmbios/karmic

« back to all changes in this revision

Viewing changes to libraries/common/TokenImpl.h

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Tallon
  • Date: 2007-04-22 13:04:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070422130455-t40zo63zf23cip6t
Tags: 0.13.6-1
* New upstream version
  - Adds complete support for EFI (i.e. intel-based Macs)

* Fixed FTBFS with gcc4.3 (missing includes) (Closes: #418621)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:
 
2
/*
 
3
 * Copyright (C) 2005 Dell Inc.
 
4
 *  by Michael Brown <Michael_E_Brown@dell.com>
 
5
 * Licensed under the Open Software License version 2.1
 
6
 *
 
7
 * Alternatively, you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published
 
9
 * by the Free Software Foundation; either version 2 of the License,
 
10
 * or (at your option) any later version.
 
11
 
 
12
 * This program is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
15
 * See the GNU General Public License for more details.
 
16
 */
 
17
 
 
18
#ifndef TOKENIMPL_H
 
19
#define TOKENIMPL_H
 
20
 
 
21
// compat header should always be first header
 
22
#include "smbios/compat.h"
 
23
 
 
24
#include <vector>
 
25
 
 
26
// types.h should be first user-defined header.
 
27
#include "smbios/types.h"
 
28
 
 
29
// Include I*.h headers first
 
30
#include "smbios/IToken.h"
 
31
#include "smbios/ICmosRW.h"
 
32
#include "smbios/ISmbios.h"
 
33
#include "smbios/IObserver.h"
 
34
#include "ExceptionImpl.h"
 
35
 
 
36
#include "TokenLowLevel.h"
 
37
 
 
38
 
 
39
namespace smbios
 
40
{
 
41
    DEFINE_EXCEPTION_EX( InvalidTokenTableModeImpl, smbios, InvalidTokenTableMode );
 
42
    DEFINE_EXCEPTION_EX( InvalidAccessModeImpl, smbios, InvalidAccessMode );
 
43
    DEFINE_EXCEPTION_EX( DerefNullPointerImpl, smbios, DerefNullPointer );
 
44
    DEFINE_EXCEPTION_EX( ParameterErrorImpl, smbios, ParameterError );
 
45
    DEFINE_EXCEPTION_EX( InvalidChecksumImpl, smbios, InvalidChecksum );
 
46
    DEFINE_EXCEPTION_EX( NeedAuthenticationImpl, smbios, NeedAuthentication );
 
47
 
 
48
    // forward declarations
 
49
    class CmosTokenD4;
 
50
    class TokenTableIterator;
 
51
    class TokenTableConstIterator;
 
52
    class CmosRWChecksumObserver;
 
53
 
 
54
    class TokenTable: public ITokenTable
 
55
    {
 
56
    public:
 
57
        TokenTable( const smbios::ISmbiosTable & );
 
58
        virtual ~TokenTable();
 
59
 
 
60
        // ITERATORS
 
61
        virtual iterator begin ();
 
62
        virtual const_iterator begin () const;
 
63
 
 
64
        virtual iterator end ();
 
65
        virtual const_iterator end () const;
 
66
 
 
67
        virtual iterator operator[]( const int );
 
68
        virtual const_iterator operator[]( const int ) const;
 
69
 
 
70
        virtual iterator operator[]( const std::string & );
 
71
        virtual const_iterator operator[]( const std::string & ) const;
 
72
 
 
73
        virtual std::ostream & streamify( std::ostream & cout ) const;
 
74
 
 
75
        friend class TokenTableIteratorBase;
 
76
 
 
77
    protected:
 
78
        void addD4Structures(const smbios::ISmbiosTable & table);
 
79
        void addD5Structures(const smbios::ISmbiosTable & table);
 
80
        void addD6Structures(const smbios::ISmbiosTable & table);
 
81
        void addDAStructures(const smbios::ISmbiosTable & table);
 
82
        void getD4TokensFromStruct(const smbios::ISmbiosTable::const_iterator &item, const u8 *ptr, size_t size);
 
83
        void getDATokensFromStruct(const smbios::ISmbiosTable::const_iterator &item, const u8 *ptr, size_t size);
 
84
        void addChecksumObserverForD4Struct(const smbios::ISmbiosTable::const_iterator &item, const u8 *ptr, size_t size);
 
85
 
 
86
 
 
87
        std::vector< IToken *> tokenList;
 
88
        std::vector< CmosRWChecksumObserver > checksumList;
 
89
 
 
90
    private:
 
91
        // No-arg constructor not legal for this class for outside parties
 
92
        TokenTable();
 
93
 
 
94
    };
 
95
 
 
96
    class CmosTokenD4 : public IToken, public ICmosToken
 
97
    {
 
98
    public:
 
99
        CmosTokenD4( const smbios::ISmbiosItem &item, const indexed_io_token *token );
 
100
        virtual ~CmosTokenD4() throw();
 
101
 
 
102
        u32 getType() const;
 
103
 
 
104
        virtual bool isActive() const;
 
105
        virtual void activate() const;
 
106
        virtual bool isString() const;
 
107
        virtual bool isBool() const;
 
108
        virtual unsigned int getStringLength() const;
 
109
        virtual const std::string getString( u8 *byteArray = 0, unsigned int size = 0 ) const;
 
110
        virtual void setString( const u8 *byteArray, size_t size ) const;
 
111
 
 
112
        virtual const ISmbiosItem &getItemRef() const;
 
113
        virtual void getCMOSDetails( u16 *indexPort, u16 *dataPort, u8 *location ) const;
 
114
 
 
115
        virtual std::string getTokenClass() const;
 
116
 
 
117
        virtual std::ostream & streamify( std::ostream & cout ) const;
 
118
 
 
119
    protected:
 
120
        CmosTokenD4();
 
121
        CmosTokenD4(const CmosTokenD4 &);
 
122
        void operator = (const CmosTokenD4 &);
 
123
 
 
124
    private:
 
125
        std::auto_ptr<const smbios::ISmbiosItem> item;
 
126
        indexed_io_access_structure structure;
 
127
        indexed_io_token token;
 
128
        cmos::ICmosRW  *cmos;  // NEVER DELETE THIS!
 
129
        //lifetime is managed by the cmosrw factory
 
130
    };
 
131
 
 
132
    class CmosTokenD5 : public IToken, public ICmosToken, public IProtectedToken
 
133
    {
 
134
    public:
 
135
        CmosTokenD5( const smbios::ISmbiosItem &item, std::vector< CmosRWChecksumObserver > &initChecksumList);
 
136
        virtual ~CmosTokenD5() throw();
 
137
 
 
138
        u32 getType() const;
 
139
 
 
140
        virtual bool isActive() const;
 
141
        virtual void activate() const;
 
142
        virtual bool isString() const;
 
143
        virtual bool isBool() const;
 
144
        virtual unsigned int getStringLength() const;
 
145
        virtual const std::string getString( u8 *byteArray = 0, unsigned int size = 0 ) const;
 
146
        virtual void setString( const u8 *byteArray, size_t size ) const;
 
147
 
 
148
        virtual const ISmbiosItem &getItemRef() const;
 
149
        virtual void getCMOSDetails( u16 *indexPort, u16 *dataPort, u8 *location ) const;
 
150
        virtual bool tryPassword(std::string pw) const;
 
151
        virtual std::string getTokenClass() const;
 
152
        virtual u32 getValueFormat() const;
 
153
 
 
154
        virtual std::ostream & streamify( std::ostream & cout ) const;
 
155
 
 
156
    protected:
 
157
        CmosTokenD5();
 
158
        CmosTokenD5(const CmosTokenD5 &);
 
159
        void operator = (const CmosTokenD5 &);
 
160
 
 
161
        virtual void addChecksumObserver() const;
 
162
 
 
163
        dell_protected_value_1_structure structure;
 
164
        std::auto_ptr<const smbios::ISmbiosItem> item;
 
165
        cmos::ICmosRW  *cmos;  // NEVER DELETE THIS!
 
166
        //lifetime is managed by the cmosrw factory
 
167
        std::string validationKey;
 
168
        std::vector< CmosRWChecksumObserver > &checksumList;
 
169
    };
 
170
 
 
171
    class CmosTokenD6 : public CmosTokenD5
 
172
    {
 
173
    public:
 
174
        CmosTokenD6( const smbios::ISmbiosItem &item, std::vector< CmosRWChecksumObserver > &initChecksumList);
 
175
        virtual std::string getTokenClass() const;
 
176
 
 
177
    protected:
 
178
        CmosTokenD6();
 
179
        CmosTokenD6(const CmosTokenD6 &);
 
180
        void operator = (const CmosTokenD6 &);
 
181
 
 
182
        virtual void addChecksumObserver() const;
 
183
 
 
184
    private:
 
185
        dell_protected_value_2_structure structure;
 
186
    };
 
187
 
 
188
    class SmiTokenDA : public IToken, public ISmiToken, public IProtectedToken
 
189
    {
 
190
    public:
 
191
        SmiTokenDA( const smbios::ISmbiosItem &item, const calling_interface_token *token );
 
192
        virtual ~SmiTokenDA() throw();
 
193
 
 
194
        u32 getType() const;
 
195
 
 
196
        virtual bool isActive() const;
 
197
        virtual void activate() const;
 
198
        virtual bool isString() const;
 
199
        virtual bool isBool() const;
 
200
        virtual unsigned int getStringLength() const;
 
201
        virtual const std::string getString( u8 *byteArray = 0, unsigned int size = 0 ) const;
 
202
        virtual void setString( const u8 *byteArray, size_t size ) const;
 
203
        virtual const ISmbiosItem &getItemRef() const;
 
204
        virtual std::string getTokenClass() const;
 
205
        virtual u32 getValueFormat() const;
 
206
        virtual bool tryPassword(std::string pw) const;
 
207
        virtual std::ostream & streamify( std::ostream & cout ) const;
 
208
        virtual void getSmiDetails(  u16 *cmdIOAddress, u8 *cmdIOCode, u8 *location ) const;
 
209
 
 
210
    protected:
 
211
        SmiTokenDA();
 
212
        SmiTokenDA(const SmiTokenDA &);
 
213
        void operator = (const SmiTokenDA &);
 
214
 
 
215
    private:
 
216
        std::auto_ptr<const smbios::ISmbiosItem> item;
 
217
        calling_interface_structure structure;
 
218
        calling_interface_token token;
 
219
        mutable std::string password;
 
220
    };
 
221
 
 
222
    // fixes up checksums on a cmos object
 
223
    // when the cmos object is written to
 
224
    class CmosRWChecksumObserver : public observer::IObserver
 
225
    {
 
226
    public:
 
227
        CmosRWChecksumObserver( std::string description, cmos::ICmosRW *cmos, int checkType, u32 indexPort, u32 dataPort, u32 start, u32 end, u32 checksumLocation  );
 
228
        CmosRWChecksumObserver( const CmosRWChecksumObserver &source );
 
229
        // called when the observed cmos changes
 
230
        // doUpdate should be bool*.  not very safe, but hey, this is C.
 
231
        virtual void update( const observer::IObservable *whatChanged, void *doUpdate );
 
232
        virtual ~CmosRWChecksumObserver();
 
233
    private:
 
234
        std::string description;
 
235
        cmos::ICmosRW *cmos;
 
236
        int checkType;
 
237
        u32 indexPort;
 
238
        u32 dataPort;
 
239
        u32 start;
 
240
        u32 end;
 
241
        u32 checksumLocation;
 
242
    };
 
243
 
 
244
    enum
 
245
    {
 
246
        CHECK_TYPE_WORD_CHECKSUM   = 0x00, //simple running sum in word
 
247
        CHECK_TYPE_BYTE_CHECKSUM   = 0x01, //simple running sum in byte
 
248
        CHECK_TYPE_WORD_CRC        = 0x02, // crc
 
249
        CHECK_TYPE_WORD_CHECKSUM_N = 0x03, //simple runnign sum in word, then (~result + 1)
 
250
    };
 
251
 
 
252
 
 
253
 
 
254
}
 
255
 
 
256
#endif  /* TOKEN_H */