SMBIOS Library
SmiImpl.h
Go to the documentation of this file.
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 SMIIMPL_H
19 #define SMIIMPL_H
20 
21 #include "smbios/ISmi.h"
22 #include "SmiLowLevel.h"
23 #include "ExceptionImpl.h"
24 
25 #include <cstdio>
26 
27 namespace smi
28 {
29  // define our exceptions
30  DEFINE_EXCEPTION_EX( SmiExceptionImpl, smi, SmiException);
31  DEFINE_EXCEPTION_EX( InvalidSmiModeImpl, smi, InvalidSmiMode);
32  DEFINE_EXCEPTION_EX( ParameterErrorImpl, smi, ParameterError);
33  DEFINE_EXCEPTION_EX( UnsupportedSmiImpl, smi, UnsupportedSmi);
34  DEFINE_EXCEPTION_EX( UnhandledSmiImpl, smi, UnhandledSmi);
35  DEFINE_EXCEPTION_EX( SmiExecutedWithErrorImpl, smi, SmiExecutedWithError);
36  DEFINE_EXCEPTION_EX( PasswordVerificationFailedImpl, smi, PasswordVerificationFailed);
37  DEFINE_EXCEPTION_EX( ConfigErrorImpl, smi, ConfigError);
38 
40  {
41  public:
43  {}
44  ;
45  virtual ~SmiStrategy()
46  {}
47  ;
48 
49  virtual void lock()
50  = 0;
51  virtual void setSize(int) = 0;
52  virtual size_t getPhysicalBufferBaseAddress() = 0;
53  virtual void addInputBuffer(u8 *buffer, size_t size) = 0;
54  virtual void execute() = 0;
55  virtual void getResultBuffer(u8 *buffer, size_t size) = 0;
56  virtual void finish() = 0;
57  };
58 
60  {
61  public:
62  SmiMockStrategy(std::string initFilename) : fh(fopen (initFilename.c_str (), "w+b")), filename(initFilename)
63  {}
64  ;
65  virtual ~SmiMockStrategy()
66  {
67  fclose (fh);
68  };
69 
70  virtual void lock()
71  {}
72  ;
73  virtual void setSize(int)
74  {}
75  ;
77  {
78  return 0xDEADBEEF;
79  };
80  virtual void addInputBuffer(u8 *buffer, size_t size)
81  {
82  fwrite(buffer, 1, size, fh);
83  };
84  virtual void execute()
85  {
86  fseek(fh,0,0);
87  };
88  virtual void getResultBuffer(u8 *buffer, size_t size)
89  {
90  size_t numbytes = fread(buffer,1,size,fh); // only used in unit tests, not critical
91  if (numbytes != size)
92  {
93  throw SmiExceptionImpl("Short read from file.");
94  }
95  };
96  virtual void finish()
97  {}
98  ;
99  private:
100  FILE *fh;
101  std::string filename;
102  };
103 
105  {
106  public:
107  SmiArchStrategy();
108  virtual ~SmiArchStrategy();
109 
110  virtual void lock()
111  ;
112  virtual void setSize(int);
113  virtual size_t getPhysicalBufferBaseAddress();
114  virtual void addInputBuffer(u8 *buffer, size_t size);
115  virtual void execute();
116  virtual void getResultBuffer(u8 *buffer, size_t size);
117  virtual void finish();
118 
119  private:
120  void *privateData;
121  };
122 
123 
125  {
126  public:
127  DellCallingInterfaceSmiImpl(SmiStrategy *, u16 address, u8 code );
129 
130  virtual void execute();
131  virtual void setClass( u16 newClass );
132  virtual void setSelect( u16 newSelect );
133  virtual void setArg( u8 argNumber, u32 argValue );
134  virtual u32 getRes( u8 resNumber ) const;
135  virtual void setArgAsPhysicalAddress( u8 argNumber, u32 bufferOffset );
136  virtual const u8 *getBufferPtr();
137  virtual void setBufferSize(size_t newSize);
138  virtual void setBufferContents(const u8 *, size_t size);
139 
140  protected:
142  bool argIsAddress[4];
146  size_t bufferSize;
147  std::auto_ptr<SmiStrategy> smiStrategy;
148 
149  private:
151  };
152 
153 }
154 
155 #endif /* SMIIMPL_H */