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

Smi.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 #define LIBSMBIOS_SOURCE
00021 #include "smbios/compat.h"
00022 
00023 //#include <iostream>
00024 #include <string.h>
00025 
00026 #include "SmiImpl.h"
00027 #include "smbios/ISmbios.h"
00028 #include "smbios/IToken.h"
00029 #include "TokenLowLevel.h"
00030 
00031 using namespace std;
00032 
00033 #if defined(DEBUG_SMI)
00034 #   define DCOUT(line) do { cout << line; } while(0)
00035 #   define DCERR(line) do { cerr << line; } while(0)
00036 #else
00037 #   define DCOUT(line) do {} while(0)
00038 #   define DCERR(line) do {} while(0)
00039 #endif
00040 
00041 /* work around broken VC6 compiler */
00042 #define SIZEOF_KERNELBUF  (sizeof(kernel_buf) - sizeof(kernel_buf.command_buffer_start))
00043 
00044 namespace smi
00045 {
00046 
00047 
00048     //
00049     // ISmi functions
00050     //
00051     IDellCallingInterfaceSmi::IDellCallingInterfaceSmi()
00052     {}
00053 
00054     IDellCallingInterfaceSmi::~IDellCallingInterfaceSmi()
00055     {}
00056 
00057     DellCallingInterfaceSmiImpl::DellCallingInterfaceSmiImpl(SmiStrategy *initStrategy, u16 address, u8 code )
00058             :  buffer(0), bufferSize(0), smiStrategy(initStrategy)
00059     {
00060         // this is the only place where we use 'real' sizeof(kernel_buf), 
00061         // everywhere else should use SIZEOF_KERNELBUF
00062         memset( &kernel_buf, 0, sizeof(kernel_buf) );
00063 
00064         memset( &smi_buf, 0, sizeof(smi_buf) );
00065         memset( &argIsAddress, 0, sizeof(argIsAddress) );
00066         memset( &argAddressOffset, 0, sizeof(argAddressOffset) );
00067 
00068         kernel_buf.magic = KERNEL_SMI_MAGIC_NUMBER;
00069         kernel_buf.ebx = 0;
00070         kernel_buf.ecx   = DELL_CALLINTF_SMI_MAGIC_NUMBER;
00071         kernel_buf.command_address = address;
00072         kernel_buf.command_code = code;
00073 
00074         /* default to "not handled" */
00075         smi_buf.cbRES1 = -3;
00076     }
00077 
00078     DellCallingInterfaceSmiImpl::~DellCallingInterfaceSmiImpl()
00079     {
00080         if(buffer)
00081         {
00082             delete [] buffer;
00083             buffer = 0;
00084             bufferSize = 0;
00085         }
00086     }
00087 
00088     const u8 *DellCallingInterfaceSmiImpl::getBufferPtr()
00089     {
00090         return buffer;
00091     }
00092 
00093     void DellCallingInterfaceSmiImpl::setBufferSize(size_t newSize)
00094     {
00095         if ( bufferSize != newSize )
00096         {
00097             delete [] buffer;
00098             buffer = new u8[newSize];
00099             memset(buffer, 0, newSize);
00100 
00101             bufferSize=newSize;
00102         }
00103     }
00104 
00105     void DellCallingInterfaceSmiImpl::setBufferContents(const u8 *src, size_t size)
00106     {
00107         if(!bufferSize)
00108             throw SmiExceptionImpl("Output buffer not large enough.");
00109 
00110         memcpy(buffer, src, bufferSize<size?bufferSize:size);
00111     }
00112 
00113     void DellCallingInterfaceSmiImpl::execute()
00114     {
00115         smiStrategy->lock() ;
00116         smiStrategy->setSize( SIZEOF_KERNELBUF + sizeof(smi_buf) + bufferSize );
00117 
00118         size_t baseAddr = smiStrategy->getPhysicalBufferBaseAddress();
00119         for( int i=0; i<4; i++)
00120             if( argIsAddress[i] )
00121                 smi_buf.inputArgs[i] = static_cast<u32>(baseAddr + SIZEOF_KERNELBUF + sizeof(smi_buf) + argAddressOffset[i]);
00122 
00123         smiStrategy->addInputBuffer(reinterpret_cast<u8 *>(&kernel_buf), SIZEOF_KERNELBUF);
00124         smiStrategy->addInputBuffer(reinterpret_cast<u8 *>(&smi_buf), sizeof(smi_buf));
00125         if(buffer)
00126             smiStrategy->addInputBuffer(buffer, bufferSize);
00127 
00128         smiStrategy->execute();
00129 
00130         smiStrategy->getResultBuffer(reinterpret_cast<u8 *>(&kernel_buf), SIZEOF_KERNELBUF);
00131         smiStrategy->getResultBuffer(reinterpret_cast<u8 *>(&smi_buf), sizeof(smi_buf));
00132         if(buffer)
00133             smiStrategy->getResultBuffer(reinterpret_cast<u8 *>(buffer), bufferSize);
00134 
00135         smiStrategy->finish();
00136 
00137         if( -6 == smi_buf.cbRES1 )
00138             throw SmiExceptionImpl("Output buffer not large enough.");
00139 
00140         if( -5 == smi_buf.cbRES1 )
00141             throw SmiExceptionImpl("Output buffer format error.");
00142 
00143         if( -3 == smi_buf.cbRES1 )
00144             throw UnhandledSmiImpl("Unhandled SMI call.");
00145 
00146         if( -2 == smi_buf.cbRES1 )
00147             throw UnsupportedSmiImpl("Unsupported SMI call.");
00148 
00149         if( -1 == smi_buf.cbRES1 )
00150             throw SmiExecutedWithErrorImpl("BIOS returned error for SMI call.");
00151     }
00152 
00153     void DellCallingInterfaceSmiImpl::setArgAsPhysicalAddress( u8 argNumber, u32 bufferOffset )
00154     {
00155         if( argNumber >= 4 )
00156             throw ParameterErrorImpl("Internal programming error. Argument must be in range 0..3");
00157 
00158         argIsAddress[argNumber] = true;
00159         argAddressOffset[argNumber] = bufferOffset;
00160     }
00161 
00162 
00163     void DellCallingInterfaceSmiImpl::setClass( u16 newClass )
00164     {
00165         smi_buf.smiClass = newClass;
00166     }
00167 
00168     void DellCallingInterfaceSmiImpl::setSelect( u16 newSelect )
00169     {
00170         smi_buf.smiSelect = newSelect;
00171     }
00172 
00173     void DellCallingInterfaceSmiImpl::setArg( u8 argNumber, u32 argValue )
00174     {
00175         if( argNumber >= 4 )
00176             throw ParameterErrorImpl("Internal programming error. Argument must be in range 0..3");
00177 
00178         smi_buf.inputArgs[ argNumber ] = argValue;
00179     }
00180 
00181     u32 DellCallingInterfaceSmiImpl::getRes( u8 resNumber ) const
00182     {
00183         if( resNumber >= 4 )
00184             throw ParameterErrorImpl("Internal programming error. Result request must be in range 0..3");
00185 
00186         return smi_buf.outputRes[resNumber];
00187     }
00188 
00189 
00190     /**************************************************************************
00191             HELPER FUNCTIONS  (Non-member functions)
00192      *************************************************************************/
00193 
00194     std::auto_ptr<smi::IDellCallingInterfaceSmi> setupCallingInterfaceSmi(u16 smiClass, u16 select, const u32 args[4])
00195     {
00196         const smbios::ISmbiosTable *table = 0;
00197         table = smbios::SmbiosFactory::getFactory()->getSingleton();
00198 
00199         std::auto_ptr<smi::IDellCallingInterfaceSmi> smi = smi::SmiFactory::getFactory()->makeNew(smi::SmiFactory::DELL_CALLING_INTERFACE_SMI);
00200 
00201         smi->setClass( smiClass );
00202         smi->setSelect( select );
00203         smi->setArg(0, args[0]);
00204         smi->setArg(1, args[1]);
00205         smi->setArg(2, args[2]);
00206         smi->setArg(3, args[3]);
00207 
00208         return smi;
00209     }
00210 
00211     void doSimpleCallingInterfaceSmi(u16 smiClass, u16 select, const u32 args[4], u32 res[4])
00212     {
00213 
00214         std::auto_ptr<smi::IDellCallingInterfaceSmi> smi(
00215             setupCallingInterfaceSmi(smiClass, select, args));
00216 
00217         smi->execute();
00218 
00219         res[0] = smi->getRes(0);
00220         res[1] = smi->getRes(1);
00221         res[2] = smi->getRes(2);
00222         res[3] = smi->getRes(3);
00223     }
00224 
00225     /*
00226        An application that will attempt to set information via any Security-Key-protected Calling Interface function must first acquire a proper Security Key.  It does this by performing the following steps:
00227 
00228        1.Check to see if an Administrator Password is set (Class 10, Selector 0 or 3). If yes, go to 2; otherwise, go to 3.
00229 
00230        2.Verify the Administrator Password (Class 10 Selector 1 or 4). If the password is verified (cbRES1 == 0), read the Security Key from cbRES2, and use it on subsequent set functions where it is required. If the password does not verify (cbRES1 == -1), repeat step 2 until it does verify; otherwise, subsequent set functions protected by the Administrator Password will be rejected by the BIOS if it supports the Security Key feature.
00231 
00232        3.Check to see if a User Password is set (Class 9, Selector 0 or 3). If yes, go to 4; otherwise, no Security Key will be needed to change data through the Calling Interface, and the caller can use any value at all for the Security Key when using any Security-Key-protected Calling Interface function.
00233 
00234        4.Verify the User Password (Class 9 Selector 1 or 4). If the password is verified (cbRES1 == 0), read the Security Key from cbRES2, and use it on subsequent set functions where it is required. If the password does not verify (cbRES1 == -1), repeat step 4 until it does verify; otherwise, subsequent set functions protected by the User Password will be rejected by the BIOS if it supports the Security Key feature.
00235 
00236        */
00237     static bool getPasswordPropertiesII(u16 which, u8 &maxLen, u8 &minLen, u8 &props)
00238     {
00239         if( which != 9 && which != 10 )
00240             throw ParameterErrorImpl("Internal programming error. Argument must be either 9 or 10.");
00241 
00242         bool hasPw = false;
00243 
00244         u32 args[4] = {0,}, res[4] = {0,};
00245 
00246         // select 3 == get properties
00247         doSimpleCallingInterfaceSmi(which, 3, args, res);
00248 
00249         // byte 1 of res[1] shows password status. 0==password installed
00250         if( res[1] & 0xFF )
00251             goto out;
00252 
00253         DCERR( "getPasswordPropertiesII()" << hex << endl ); 
00254         DCERR( "res[0]: " << res[0] << endl);
00255         DCERR( "res[1]: " << res[1] << endl);
00256         DCERR( "res[2]: " << res[2] << endl);
00257         DCERR( "res[3]: " << res[3] << endl);
00258 
00259         hasPw = true;
00260         maxLen = static_cast<u8>((res[1] & 0x0000FF00) >> 8);
00261         minLen = static_cast<u8>((res[1] & 0x00FF0000) >> 16);
00262         props  = static_cast<u8>((res[1] & 0xFF000000) >> 24);
00263 
00264 out:
00265         return hasPw;
00266     }
00267 
00268     static u32 getAuthenticationKeyII(const string &password)
00269     {
00270         u32 authKey = 0;
00271 
00272         DCERR( "getAuthenticationKeyII()" << endl );
00273 
00274         u16 toCheck[2] = { class_admin_password, class_user_password };
00275         DCERR( "  trying auth keys" << endl);
00276 
00277         // try admin password first, then user password
00278         for( int i=0; i<2; i++ )
00279         {
00280             DCERR( "  trying class code: " << toCheck[i] << endl);
00281 
00282             u8 maxLen=0, minLen=0, props=0;
00283             // try next password type if no password set
00284             try
00285             {
00286                 if( ! getPasswordPropertiesII(toCheck[i], maxLen, minLen, props) )
00287                     continue;
00288             }
00289             catch( const exception & )
00290             {
00291                 // usually get here for unsupported SMI exception.
00292                 // in which case, it makes no sense to continue 
00293                 //DCERR( "  Caught something." << e.what() << endl);
00294                 continue;
00295             }
00296 
00297             DCERR("has a password." << hex << endl);
00298             DCERR( "  max len: " << (int)maxLen << endl);
00299             DCERR( "  min len: " << (int)minLen << endl);
00300             DCERR( "  props  : " << hex << props << endl);
00301 
00302             u32 args[4] = {0,};
00303             // select 4 == verify password
00304             std::auto_ptr<smi::IDellCallingInterfaceSmi> smi(setupCallingInterfaceSmi(toCheck[i], 4, args));
00305             smi->setBufferContents(reinterpret_cast<const u8*>(password.c_str()), strnlen(password.c_str(), maxLen));
00306             smi->setArgAsPhysicalAddress( 0, 0 );
00307             smi->execute();
00308 
00309             DCERR("after verify:"<< endl);
00310             DCERR("res[0]: " << smi->getRes(0) << endl; );
00311             DCERR("res[1]: " << smi->getRes(1) << endl; );
00312             DCERR("res[2]: " << smi->getRes(2) << endl; );
00313             DCERR("res[3]: " << smi->getRes(3) << endl; );
00314 
00315             if(! smi->getRes(0))
00316                 authKey = smi->getRes(1);
00317             else
00318                 throw PasswordVerificationFailedImpl("BIOS setup password enabled, but given password does not match.");
00319 
00320             // if this password is installed, no sense in checking the other, as it will not work.
00321             // highest priority password always takes precedence
00322             break;
00323         }
00324 
00325         return authKey;
00326     }
00327 
00328     u32 getAuthenticationKey(const string &password)
00329     {
00330         u32 authKey = 0;
00331 
00332         DCERR("getAuthenticationKey(" << password << ")" << endl);
00333 
00334         // try admin password first, then user password
00335         u16 toCheck[2] = { class_admin_password, class_user_password };
00336         DCERR("  trying auth keys" << endl);
00337 
00338         for( int i=0; i<2; i++ )
00339         {
00340             DCERR("    trying class code: " << toCheck[i] << endl);
00341             try
00342             {
00343                 u32 args[4] = {0,}, res[4] = {0,};
00344                 doSimpleCallingInterfaceSmi(toCheck[i], 0, args, res);
00345 
00346                 // no password of this type installed if res[0] == 0
00347                 if( res[0] != 0 )
00348                     continue;
00349             }
00350             catch(const SmiException &)
00351             {
00352                 // We should only get here under the following circumstances:
00353                 // - unsupported SMI call
00354                 // - unhandled SMI call
00355                 // - could not talk to dcdbas driver
00356                 continue;
00357             }
00358 
00359             // If we get here, that means a password of type toCheck[i]
00360             // is installed.
00361             //
00362             DCERR("      password installed" << endl);
00363 
00364             u32 args[4] = {0}, res[4] = {0,};
00365             strncpy(reinterpret_cast<char *>(args), password.c_str(), 2 * sizeof(u32));
00366 
00367             DCERR("    args are  : 0x" << args[0] << " 0x" << args[1] << " 0x" << args[2] << " 0x" << args[3] << endl);
00368 
00369             // if SMI above succeeded, this should too, no exception handling
00370             doSimpleCallingInterfaceSmi(toCheck[i], 1, args, res);
00371 
00372             DCERR("    res was  : 0x" << res[0] << " 0x" << res[1] << " 0x" << res[2] << " 0x" << res[3] << endl);
00373             if( res[0] == 0 )
00374                 authKey = res[1];
00375             else
00376                 throw PasswordVerificationFailedImpl("BIOS setup password enabled, but given password does not match.");
00377 
00378             // if this password is installed, no sense in checking the other, as it will not work.
00379             // highest priority password always takes precedence
00380             break;
00381         }
00382 
00383         // if this didn't work, try other method.
00384         if( ! authKey )
00385             authKey = getAuthenticationKeyII( password );
00386 
00387         return authKey;
00388     }
00389 
00390     password_format_enum getPasswordFormat()
00391     {
00392         password_format_enum format = PW_FORMAT_UNKNOWN;
00393 
00394         try
00395         {
00396             u32 args[4] = {0,}, res[4] = {0,};
00397             doSimpleCallingInterfaceSmi(class_admin_password, 0, args, res);
00398             format = PW_FORMAT_SCAN_CODE;
00399             goto out;
00400         }
00401         catch(const exception &)
00402         { }
00403 
00404         try
00405         {
00406             u32 args[4] = {0,}, res[4] = {0,};
00407             doSimpleCallingInterfaceSmi(class_user_password, 0, args, res);
00408             format = PW_FORMAT_SCAN_CODE;
00409             goto out;
00410         }
00411         catch(const exception &)
00412         { }
00413 
00414         try
00415         {
00416             u8 maxLen=0, minLen=0, props=0;
00417             getPasswordPropertiesII(class_admin_password, maxLen, minLen, props);
00418             format = PW_FORMAT_SCAN_CODE;
00419             if (props & 0x01)
00420                 format = PW_FORMAT_ASCII;
00421             goto out;
00422         }
00423         catch(const exception &)
00424         { }
00425 
00426         try
00427         {
00428             u8 maxLen=0, minLen=0, props=0;
00429             getPasswordPropertiesII(class_user_password, maxLen, minLen, props);
00430             format = PW_FORMAT_SCAN_CODE;
00431             if (props & 0x01)
00432                 format = PW_FORMAT_ASCII;
00433             goto out;
00434         }
00435         catch(const exception &)
00436         { }
00437 
00438 out:
00439         return format;
00440     }
00441 
00442     static u32 readSetting(u16 select, u32 location, u32 *minValue, u32 *maxValue)
00443     {
00444         u32 args[4] = {location, 0,}, res[4] = {0,};
00445         doSimpleCallingInterfaceSmi(0, select, args, res); // 0 == class code for setting/batter/ac/systemstatus
00446         if(minValue)
00447             *minValue = res[2];
00448         if(maxValue)
00449             *maxValue = res[3];
00450         return res[1]; // current value
00451     }
00452 
00453     u32 readNVStorage(u32 location, u32 *minValue, u32 *maxValue)
00454     {
00455         return readSetting(0, location, minValue, maxValue); // 0 = select code for nv storage
00456     }
00457 
00458     u32 readBatteryModeSetting(u32 location, u32 *minValue, u32 *maxValue)
00459     {
00460         return readSetting(1, location, minValue, maxValue); // 1 = select code for battery mode
00461     }
00462 
00463     u32 readACModeSetting(u32 location, u32 *minValue, u32 *maxValue)
00464     {
00465         return readSetting(2, location, minValue, maxValue); // 2 = select code for ac mode
00466     }
00467 
00468     u32 readSystemStatus(u32 *failingSensorHandle)
00469     {
00470         // 3 = select code for system status
00471         // 1st 0 == dummy location value
00472         // 2nd 0 == dummy max value pointer
00473         return readSetting(3, 0, failingSensorHandle, 0);
00474     }
00475 
00476 
00477     static u32 writeSetting(const std::string &password, u16 select, u32 location, u32 newValue, u32 *minValue, u32 *maxValue)
00478     {
00479         u32 args[4] = {location, newValue,}, res[4] = {0,};
00480 
00481         // go twice. Once without security key, once by trying password given.
00482         for(int i=0; i<2; i++)
00483         {
00484             try
00485             {
00486                 // 0 == class code for writing to setting/battery/ac/systemstatus
00487                 DCERR("Try #" << i << " for writeSetting()" << endl);
00488                 DCERR("    args are  : 0x" << args[0] << " 0x" << args[1] << " 0x" << args[2] << " 0x" << args[3] << endl);
00489                 doSimpleCallingInterfaceSmi(1, select, args, res);
00490                 DCERR("    res was  : 0x" << res[0] << " 0x" << res[1] << " 0x" << res[2] << " 0x" << res[3] << endl);
00491                 break;
00492             }
00493             catch(const SmiExecutedWithError &)
00494             {
00495                 // on second time through, just pass exception upwards.
00496                 if(i==1)
00497                     throw;
00498 
00499                 DCERR("Executed with error, try password..." << endl);
00500                 args[2] = getAuthenticationKey(password);
00501             }
00502         }
00503 
00504         if(minValue)
00505             *minValue = res[2];
00506         if(maxValue)
00507             *maxValue = res[3];
00508         return res[1]; // current value
00509     }
00510 
00511     u32 writeNVStorage(const std::string &password, u32 location, u32 value, u32 *minValue, u32 *maxValue)
00512     {
00513         return writeSetting(password, 0, location, value, minValue, maxValue);
00514     }
00515 
00516     u32 writeBatteryModeSetting(const std::string &password, u32 location, u32 value, u32 *minValue, u32 *maxValue)
00517     {
00518         return writeSetting(password, 1, location, value, minValue, maxValue);
00519     }
00520 
00521     u32 writeACModeSetting(const std::string &password, u32 location, u32 value, u32 *minValue, u32 *maxValue)
00522     {
00523         return writeSetting(password, 2, location, value, minValue, maxValue);
00524     }
00525 
00526     void getDisplayType(u32 &type, u32 &resolution, u32 &memSizeX256kb)
00527     {
00528         u32 args[4] = {0,}, res[4] = {0,};
00529         doSimpleCallingInterfaceSmi(4, 0, args, res);
00530 
00531         type = (res[1] & 0x00FF);
00532         resolution = (res[1] & 0xFF00) >> 8;
00533         memSizeX256kb = res[2];
00534     }
00535 
00536     void getPanelResolution(u32 &horiz, u32 &vert)
00537     {
00538         u32 args[4] = {0,}, res[4] = {0,};
00539         doSimpleCallingInterfaceSmi(4, 1, args, res);
00540 
00541         horiz = (res[1] & 0x0000FFFF);
00542         vert  = (res[1] & 0xFFFF0000) >> 16;
00543     }
00544 
00545     void getActiveDisplays(u32 &bits)
00546     {
00547         u32 args[4] = {0,}, res[4] = {0,};
00548         doSimpleCallingInterfaceSmi(4, 2, args, res);
00549 
00550         bits = res[1];
00551     }
00552 
00553     void setActiveDisplays(u32 &bits)
00554     {
00555         u32 args[4] = {bits, 0,}, res[4] = {0,};
00556         doSimpleCallingInterfaceSmi(4, 3, args, res);
00557     }
00558 
00559     void getPropertyOwnershipTag(char *tagBuf, size_t size)
00560     {
00561         u32 args[4] = {0,};
00562         // class 20 == property tag
00563         std::auto_ptr<smi::IDellCallingInterfaceSmi> smi(setupCallingInterfaceSmi(20, 0, args));
00564         smi->setBufferSize(80); // 80 is max len, making sure it doesn't overflow now. :-)
00565         smi->setArgAsPhysicalAddress( 0, 0 );
00566         smi->execute();
00567         strncpy( tagBuf, reinterpret_cast<const char*>(smi->getBufferPtr()), size < 80? size:80);
00568         tagBuf[size-1] = '\0';
00569     }
00570 
00571     void setPropertyOwnershipTag(const string password, const char *newTag, size_t size)
00572     {
00573         u32 args[4] = {0,};
00574 
00575         for(int i=0; i<2; i++)
00576         {
00577             try
00578             {
00579                 // class 20 == property tag
00580                 std::auto_ptr<smi::IDellCallingInterfaceSmi> smi(setupCallingInterfaceSmi(20, 1, args));
00581                 smi->setBufferSize(120); // 80 is max len, making sure it doesn't overflow now. :-)
00582                 smi->setBufferContents(reinterpret_cast<const u8*>(newTag), strnlen(newTag, 80));
00583                 smi->setArgAsPhysicalAddress( 0, 0 );
00584                 smi->execute();
00585                 break;
00586             }
00587             catch(const SmiExecutedWithError &)
00588             {
00589                 // on second time through, just pass exception upwards.
00590                 if(i==1)
00591                     throw;
00592 
00593                 //cout << "Caught error. Might be bad password. Trying password: " << password << endl;
00594                 args[1] = getAuthenticationKey(password);
00595             }
00596         }
00597     }
00598 
00599 
00600     // token list for wireless tokens. Probably not the best place for this,
00601     // but until something better comes along...
00602     const int Bluetooth_Devices_Disable = 0x0153;  // docs appear to be wrong. They say 0x0152, but this looks backwards from reality
00603     const int Bluetooth_Devices_Enable = 0x0152;  // docs appear to be wrong. They say 0x0153, but this looks backwards from reality
00604     const int Cellular_Radio_Disable = 0x017B;
00605     const int Cellular_Radio_Enable = 0x017C;
00606     const int WiFi_Locator_Disable = 0x017D;
00607     const int WiFi_Locator_Enable = 0x017E;
00608     const int Wireless_LAN_Disable = 0x017F;
00609     const int Wireless_LAN_Enable = 0x0180;
00610     const int Wireless_Switch_Bluetooth_Control_Disable = 0x0181;
00611     const int Wireless_Switch_Bluetooth_Control_Enable = 0x0182;
00612     const int Wireless_Switch_Cellular_Control_Disable = 0x0183;
00613     const int Wireless_Switch_Cellular_Control_Enable = 0x0184;
00614     const int Wireless_Switch_Wireless_LAN_Control_Disable = 0x0185;
00615     const int Wireless_Switch_Wireless_LAN_Control_Enable = 0x0186;
00616     const int Radio_Transmission_Enable = 0x010c;
00617     const int Radio_Transmission_Disable = 0x010d;
00618     const int Wireless_Device_Disable = 0x0114;
00619     const int Wireless_Device_App_Control = 0x0115;
00620     const int Wireless_Device_App_Or_Hotkey_Control = 0x0116;
00621 
00622     // cbClass 17
00623     // cbSelect 11
00624     // WiFi Control
00625     // Entry/return values grouped by the value of cbARG1, byte0 which indicates the function to perform:
00626     // 0x1 = Set QuickSet Radio Disable Flag
00627     //  cbARG1, byte1    Radio ID value:
00628     //      0 Radio Status
00629     //      1 WLAN ID
00630     //      2 BT ID
00631     //      3 WWAN ID
00632     //  cbARG1, byte2   Flag bits:
00633     //      0 QuickSet disables radio (1)
00634     //      1-7 Reserved (0)
00635     //  cbRES1      Standard return codes (0, -1, -2)
00636     //  cbRES2      QuickSet (QS) radio disable bit map:
00637     //      0 QS disables WLAN
00638     //      1 QS disables BT
00639     //      2 QS disables WWAN
00640     //      3-31 Reserved (0)
00641     void wirelessRadioControl(bool enable, bool boot, bool runtime, int enable_token, int disable_token, int radioNum, std::string password)
00642     {
00643         if (boot)
00644             smbios::activateToken( (enable ?
00645                 enable_token :
00646                 disable_token),
00647                 password
00648                 );
00649         if (runtime)
00650         {
00651             if (enable && !smbios::isTokenActive(enable_token))
00652                 throw ConfigErrorImpl("boot time config disabled, runtime setting has no effect.");
00653 
00654             u32 disable = enable ? 0:1;
00655             u32 args[4] = {(1 | (static_cast<u32>(radioNum)<<8) | ((disable)<<16)), 0, 0, 0};
00656             u32 res[4] = {0,};
00657             doSimpleCallingInterfaceSmi(17, 11, args, res);
00658         }
00659     }
00660 
00661 
00662     static void switchControl(u32 whichConfig, u32 whichSwitch, bool enable)
00663     {
00664         std::auto_ptr<smi::IDellCallingInterfaceSmi> smi = smi::SmiFactory::getFactory()->makeNew(smi::SmiFactory::DELL_CALLING_INTERFACE_SMI);
00665         smi->setClass( 17 );  /* ? */
00666         smi->setSelect( 11 );  /* WiFi Control */
00667     
00668         // 0x2 = Wireless Switch Configuration
00669         //  cbARG1, byte1   Subcommand:
00670         //      0 Get config
00671         //      1 Set config
00672         //      2 Set WiFi locator enable/disable
00673         //  cbARG1,byte2    Switch settings (if byte 1==1):
00674         //      0 WLAN switch control (1)
00675         //      1 BT switch control (1)
00676         //      2 WWAN switch control (1)
00677         //      3-7 Reserved (0)
00678         //  cbARG1, byte2   Enable bits (if byte 1==2):
00679         //      0 Enable WiFi locator (1)
00680         //  cbRES1      Standard return codes (0, -1, -2)
00681         //  cbRES2      QuickSet radio disable bit map:
00682         //      0 WLAN controlled by switch (1)
00683         //      1 BT controlled by switch (1)
00684         //      2 WWAN controlled by switch (1)
00685         //      3-6 Reserved (0)
00686         //      7 Wireless switch config locked (1)
00687         //      8 WiFi locator enabled (1)
00688         //      9-14 Reserved (0)
00689         //      15 WiFi locator setting locked (1)
00690         //      16-31 Reserved (0)
00691         smi->setArg(smi::cbARG1, 0x2);
00692         smi->execute();
00693     
00694         u32 oldConfig = smi->getRes(smi::cbRES2);
00695         if (whichConfig == 1)
00696             oldConfig &= 0xFF;
00697         else if (whichConfig == 2)
00698             oldConfig = ((oldConfig>>8) & 0xFF);
00699     
00700         u32 newConfig = (oldConfig & ~whichSwitch) | ((enable?1:0) * whichSwitch);
00701         smi->setArg(smi::cbARG1, (0x2 | (whichConfig << 8) | (newConfig << 16)));
00702         smi->execute();
00703     }
00704     
00705     void wirelessSwitchControl(bool enable, bool boot, bool runtime, int enable_token, int disable_token, int switchNum, std::string password)
00706     {
00707         int intSwitchConfig = 0, intSwitchNum = 0;
00708         switch(switchNum)
00709         {
00710             case WLAN_SWITCH_CTL:
00711                 intSwitchConfig = 1;
00712                 intSwitchNum = 1;
00713                 break;
00714             case BLUETOOTH_SWITCH_CTL:
00715                 intSwitchConfig = 1;
00716                 intSwitchNum = 2;
00717                 break;
00718             case WWAN_SWITCH_CTL:
00719                 intSwitchConfig = 1;
00720                 intSwitchNum = 4;
00721                 break;
00722             case LOCATOR_SWITCH_CTL:
00723                 intSwitchConfig = 2;
00724                 intSwitchNum = 1;
00725                 break;
00726             default:
00727                 throw ParameterErrorImpl("Invalid switch number passed to wirelessSwitchControl()");
00728         }
00729         
00730         if (boot)
00731             smbios::activateToken( (enable ?
00732                 enable_token :
00733                 disable_token),
00734                 password
00735                 );
00736         if (runtime)
00737             switchControl(intSwitchConfig, intSwitchNum, enable);
00738     }
00739 
00740     radioStatusCode wirelessRadioStatus(radioNum which, std::ostream &cout, u32 defRes2)
00741     {
00742         radioStatusCode ret = STATUS_UNKNOWN;
00743         try
00744         {
00745             u32 args[4] = {0,}, res[4] ={0,};
00746             if (!defRes2)
00747                 smi::doSimpleCallingInterfaceSmi(17, 11, args, res);
00748             else
00749                 res[smi::cbRES2] = defRes2;
00750     
00751             int supported_bit=0, installed_bit=0, disabled_bit=0;
00752             string name;
00753             switch(which)
00754             {
00755                 case smi::WLAN_RADIO_NUM:
00756                     supported_bit = 2;
00757                     installed_bit = 8;
00758                     disabled_bit = 17;
00759                     name = "WLAN";
00760                     break;
00761                 case smi::BLUETOOTH_RADIO_NUM:
00762                     supported_bit = 3;
00763                     installed_bit = 9;
00764                     disabled_bit = 18;
00765                     name = "Bluetooth";
00766                     break;
00767                 case smi::WWAN_RADIO_NUM:
00768                     supported_bit = 4;
00769                     installed_bit = 10;
00770                     disabled_bit = 19;
00771                     name = "WWAN";
00772                     break;
00773             }
00774     
00775             cout << "Radio Status for " << name << ":" << endl;
00776             if (res[smi::cbRES2] & (1 << supported_bit))
00777             {
00778                 cout << "\t" << name << " supported" << endl;
00779                 cout << "\t" << name << " " << ((res[smi::cbRES2] & (1 << installed_bit)) ? "installed":"not installed") << endl;
00780                 cout << "\t" << name << " " << ((res[smi::cbRES2] & (1 << disabled_bit)) ? "disabled" : "enabled") << endl;
00781     
00782                 ret = STATUS_DISABLED;
00783                 if (!(res[smi::cbRES2] & (1 << installed_bit)))
00784                     ret = STATUS_NOT_PRESENT;
00785                 else if (!(res[smi::cbRES2] & (1 << disabled_bit)))
00786                     ret = STATUS_ENABLED;
00787             } else {
00788                 cout << "\t" << name << " not supported" << endl;
00789                 ret = STATUS_UNSUPPORTED;
00790         }
00791             cout << "\tStatus Code: " << ret << endl;
00792         } catch (smi::UnsupportedSmi &) {
00793             // this interface not available...
00794         }
00795         return ret;
00796     }
00797 
00798 }

Generated on Tue Feb 26 14:39:00 2008 for SMBIOS Library by  doxygen 1.3.9.1