00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #define LIBSMBIOS_SOURCE
00021 #include "smbios/compat.h"
00022
00023 #include <cstring>
00024
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
00042 #define SIZEOF_KERNELBUF (sizeof(kernel_buf) - sizeof(kernel_buf.command_buffer_start))
00043
00044 namespace smi
00045 {
00046
00047
00048
00049
00050
00051 ISmi::ISmi()
00052 {}
00053
00054 ISmi::~ISmi()
00055 {}
00056
00057 IDellCallingInterfaceSmi::IDellCallingInterfaceSmi()
00058 {}
00059
00060 IDellCallingInterfaceSmi::~IDellCallingInterfaceSmi()
00061 {}
00062
00063 DellCallingInterfaceSmiImpl::DellCallingInterfaceSmiImpl(SmiStrategy *initStrategy)
00064 : ISmi(), IDellCallingInterfaceSmi(), buffer(0), bufferSize(0), smiStrategy(initStrategy)
00065 {
00066
00067
00068 memset( &kernel_buf, 0, sizeof(kernel_buf) );
00069
00070 memset( &smi_buf, 0, sizeof(smi_buf) );
00071 memset( &argIsAddress, 0, sizeof(argIsAddress) );
00072 memset( &argAddressOffset, 0, sizeof(argAddressOffset) );
00073
00074 kernel_buf.magic = KERNEL_SMI_MAGIC_NUMBER;
00075 kernel_buf.ebx = 0;
00076 kernel_buf.ecx = DELL_CALLINTF_SMI_MAGIC_NUMBER;
00077 kernel_buf.command_address = 0;
00078 kernel_buf.command_code = 0;
00079
00080
00081 smi_buf.cbRES1 = -3;
00082 }
00083
00084 DellCallingInterfaceSmiImpl::~DellCallingInterfaceSmiImpl()
00085 {
00086 if(buffer)
00087 {
00088 delete [] buffer;
00089 buffer = 0;
00090 bufferSize = 0;
00091 }
00092 }
00093
00094 void DellCallingInterfaceSmiImpl::setCommandIOMagic( u16 address, u8 code )
00095 {
00096 kernel_buf.command_address = address;
00097 kernel_buf.command_code = code;
00098 }
00099
00100 u8 *DellCallingInterfaceSmiImpl::getBufferPtr()
00101 {
00102 return buffer;
00103 }
00104
00105 void DellCallingInterfaceSmiImpl::setBufferSize(size_t newSize)
00106 {
00107 if ( bufferSize != newSize )
00108 {
00109 delete [] buffer;
00110 buffer = new u8[newSize];
00111 memset(buffer, 0, newSize);
00112
00113 bufferSize=newSize;
00114 }
00115 }
00116
00117 void DellCallingInterfaceSmiImpl::execute()
00118 {
00119 smiStrategy->lock()
00120 ;
00121 smiStrategy->setSize( SIZEOF_KERNELBUF + sizeof(smi_buf) + bufferSize );
00122
00123 size_t baseAddr = smiStrategy->getPhysicalBufferBaseAddress();
00124 for( int i=0; i<4; i++)
00125 if( argIsAddress[i] )
00126 smi_buf.inputArgs[i] = static_cast<u32>(baseAddr + SIZEOF_KERNELBUF + sizeof(smi_buf) + argAddressOffset[i]);
00127
00128 smiStrategy->addInputBuffer(reinterpret_cast<u8 *>(&kernel_buf), SIZEOF_KERNELBUF);
00129 smiStrategy->addInputBuffer(reinterpret_cast<u8 *>(&smi_buf), sizeof(smi_buf));
00130 if(buffer)
00131 smiStrategy->addInputBuffer(buffer, bufferSize);
00132
00133 smiStrategy->execute();
00134
00135 smiStrategy->getResultBuffer(reinterpret_cast<u8 *>(&kernel_buf), SIZEOF_KERNELBUF);
00136 smiStrategy->getResultBuffer(reinterpret_cast<u8 *>(&smi_buf), sizeof(smi_buf));
00137 if(buffer)
00138 smiStrategy->getResultBuffer(reinterpret_cast<u8 *>(buffer), bufferSize);
00139
00140 smiStrategy->finish();
00141
00142 if( -6 == smi_buf.cbRES1 )
00143 throw SmiExceptionImpl("Output buffer not large enough.");
00144
00145 if( -5 == smi_buf.cbRES1 )
00146 throw SmiExceptionImpl("Output buffer format error.");
00147
00148 if( -3 == smi_buf.cbRES1 )
00149 throw UnhandledSmiImpl("Unhandled SMI call.");
00150
00151 if( -2 == smi_buf.cbRES1 )
00152 throw UnsupportedSmiImpl("Unsupported SMI call.");
00153
00154 if( -1 == smi_buf.cbRES1 )
00155 throw SmiExecutedWithErrorImpl("BIOS returned error for SMI call.");
00156 }
00157
00158 void DellCallingInterfaceSmiImpl::setArgAsPhysicalAddress( u8 argNumber, u32 bufferOffset )
00159 {
00160 if( argNumber >= 4 )
00161 throw ParameterErrorImpl("Internal programming error. Argument must be in range 0..3");
00162
00163 argIsAddress[argNumber] = true;
00164 argAddressOffset[argNumber] = bufferOffset;
00165 }
00166
00167
00168 void DellCallingInterfaceSmiImpl::setClass( u16 newClass )
00169 {
00170 smi_buf.smiClass = newClass;
00171 }
00172
00173 void DellCallingInterfaceSmiImpl::setSelect( u16 newSelect )
00174 {
00175 smi_buf.smiSelect = newSelect;
00176 }
00177
00178 void DellCallingInterfaceSmiImpl::setArg( u8 argNumber, u32 argValue )
00179 {
00180 if( argNumber >= 4 )
00181 throw ParameterErrorImpl("Internal programming error. Argument must be in range 0..3");
00182
00183 smi_buf.inputArgs[ argNumber ] = argValue;
00184 }
00185
00186 u32 DellCallingInterfaceSmiImpl::getRes( u8 resNumber ) const
00187 {
00188 if( resNumber >= 4 )
00189 throw ParameterErrorImpl("Internal programming error. Result request must be in range 0..3");
00190
00191 return smi_buf.outputRes[resNumber];
00192 }
00193
00194
00195
00196
00197
00198
00199 std::auto_ptr<smi::IDellCallingInterfaceSmi> setupCallingInterfaceSmi(u16 smiClass, u16 select, const u32 args[4])
00200 {
00201 smbios::ISmbiosTable *table = 0;
00202 table = smbios::SmbiosFactory::getFactory()->getSingleton();
00203
00204 std::auto_ptr<smi::ISmi> smi = smi::SmiFactory::getFactory()->makeNew(smi::SmiFactory::DELL_CALLING_INTERFACE_SMI);
00205 smi::IDellCallingInterfaceSmi *ci = dynamic_cast<smi::IDellCallingInterfaceSmi *>(smi.get());
00206
00207 ci->setClass( smiClass );
00208 ci->setSelect( select );
00209 ci->setArg(0, args[0]);
00210 ci->setArg(1, args[1]);
00211 ci->setArg(2, args[2]);
00212 ci->setArg(3, args[3]);
00213
00214 std::auto_ptr<smi::IDellCallingInterfaceSmi> retval(
00215 dynamic_cast<smi::IDellCallingInterfaceSmi *>(smi.get())
00216 );
00217 smi.release();
00218 return retval;
00219 }
00220
00221 void doSimpleCallingInterfaceSmi(u16 smiClass, u16 select, const u32 args[4], u32 res[4])
00222 {
00223
00224 std::auto_ptr<smi::IDellCallingInterfaceSmi> smi(
00225 setupCallingInterfaceSmi(smiClass, select, args));
00226
00227 smi->execute();
00228
00229 res[0] = smi->getRes(0);
00230 res[1] = smi->getRes(1);
00231 res[2] = smi->getRes(2);
00232 res[3] = smi->getRes(3);
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 static bool getPasswordPropertiesII(u16 which, u8 &maxLen, u8 &minLen, u8 &props)
00248 {
00249 if( which != 9 && which != 10 )
00250 throw ParameterErrorImpl("Internal programming error. Argument must be either 9 or 10.");
00251
00252 bool hasPw = false;
00253
00254 u32 args[4] = {0,}, res[4] = {0,};
00255
00256
00257 doSimpleCallingInterfaceSmi(which, 3, args, res);
00258
00259
00260 if( res[1] & 0xFF )
00261 goto out;
00262
00263 DCERR( "getPasswordPropertiesII()" << hex << endl );
00264 DCERR( "res[0]: " << res[0] << endl);
00265 DCERR( "res[1]: " << res[1] << endl);
00266 DCERR( "res[2]: " << res[2] << endl);
00267 DCERR( "res[3]: " << res[3] << endl);
00268
00269 hasPw = true;
00270 maxLen = static_cast<u8>((res[1] & 0x0000FF00) >> 8);
00271 minLen = static_cast<u8>((res[1] & 0x00FF0000) >> 16);
00272 props = static_cast<u8>((res[1] & 0xFF000000) >> 24);
00273
00274 out:
00275 return hasPw;
00276 }
00277
00278 bool getPasswordStatus(u16 which)
00279 {
00280 if( which != 9 && which != 10 )
00281 throw ParameterErrorImpl("Internal programming error. Argument must be either 9 or 10.");
00282 try
00283 {
00284 u32 args[4] = {0,}, res[4] = {0,};
00285 doSimpleCallingInterfaceSmi(which, 0, args, res);
00286
00287 if( (res[0] & 0xFF) == 1 || ( res[0] & 0xFF ) == 3)
00288 return false;
00289 return true;
00290 }
00291 catch(const exception &)
00292 {
00293
00294 }
00295 u8 max,min,props;
00296 return getPasswordPropertiesII(which,max,min,props);
00297 }
00298
00299 static u32 getAuthenticationKeyII(const string &password)
00300 {
00301 u32 authKey = 0;
00302
00303 DCERR( "getAuthenticationKeyII()" << endl );
00304
00305 u16 toCheck[2] = { class_admin_password, class_user_password };
00306 DCERR( " trying auth keys" << endl);
00307
00308
00309 for( int i=0; i<2; i++ )
00310 {
00311 DCERR( " trying class code: " << toCheck[i] << endl);
00312
00313 u8 maxLen=0, minLen=0, props=0;
00314
00315 try
00316 {
00317 if( ! getPasswordPropertiesII(toCheck[i], maxLen, minLen, props) )
00318 continue;
00319 }
00320 catch( const exception & )
00321 {
00322
00323
00324
00325 continue;
00326 }
00327
00328 DCERR("has a password." << hex << endl);
00329 DCERR( " max len: " << (int)maxLen << endl);
00330 DCERR( " min len: " << (int)minLen << endl);
00331 DCERR( " props : " << hex << props << endl);
00332
00333 u32 args[4] = {0,};
00334
00335 std::auto_ptr<smi::IDellCallingInterfaceSmi> smi(setupCallingInterfaceSmi(toCheck[i], 4, args));
00336 smi->setBufferSize(maxLen);
00337 strncpy( reinterpret_cast<char*>(smi->getBufferPtr()), password.c_str(), maxLen);
00338 smi->setArgAsPhysicalAddress( 0, 0 );
00339 smi->execute();
00340
00341 DCERR("after verify:"<< endl);
00342 DCERR("res[0]: " << smi->getRes(0) << endl; );
00343 DCERR("res[1]: " << smi->getRes(1) << endl; );
00344 DCERR("res[2]: " << smi->getRes(2) << endl; );
00345 DCERR("res[3]: " << smi->getRes(3) << endl; );
00346
00347 if(! smi->getRes(0))
00348 authKey = smi->getRes(1);
00349 else
00350 throw PasswordVerificationFailedImpl("BIOS setup password enabled, but given password does not match.");
00351
00352
00353
00354 break;
00355 }
00356
00357 return authKey;
00358 }
00359
00360 u32 getAuthenticationKey(const string &password)
00361 {
00362 u32 authKey = 0;
00363
00364 DCERR("getAuthenticationKey(" << password << ")" << endl);
00365
00366
00367 u16 toCheck[2] = { class_admin_password, class_user_password };
00368 DCERR(" trying auth keys" << endl);
00369
00370 for( int i=0; i<2; i++ )
00371 {
00372 DCERR(" trying class code: " << toCheck[i] << endl);
00373 try
00374 {
00375 u32 args[4] = {0,}, res[4] = {0,};
00376 doSimpleCallingInterfaceSmi(toCheck[i], 0, args, res);
00377
00378
00379 if( res[0] != 0 )
00380 continue;
00381 }
00382 catch(const SmiException &)
00383 {
00384
00385
00386
00387
00388 continue;
00389 }
00390
00391
00392
00393
00394 DCERR(" password installed" << endl);
00395
00396 u32 args[4] = {0}, res[4] = {0,};
00397 strncpy(reinterpret_cast<char *>(args), password.c_str(), 2 * sizeof(u32));
00398
00399 DCERR(" args are : 0x" << args[0] << " 0x" << args[1] << " 0x" << args[2] << " 0x" << args[3] << endl);
00400
00401
00402 doSimpleCallingInterfaceSmi(toCheck[i], 1, args, res);
00403
00404 DCERR(" res was : 0x" << res[0] << " 0x" << res[1] << " 0x" << res[2] << " 0x" << res[3] << endl);
00405 if( res[0] == 0 )
00406 authKey = res[1];
00407 else
00408 throw PasswordVerificationFailedImpl("BIOS setup password enabled, but given password does not match.");
00409
00410
00411
00412 break;
00413 }
00414
00415
00416 if( ! authKey )
00417 authKey = getAuthenticationKeyII( password );
00418
00419 return authKey;
00420 }
00421
00422 password_format_enum getPasswordFormat()
00423 {
00424 password_format_enum format = PW_FORMAT_UNKNOWN;
00425
00426 try
00427 {
00428 u32 args[4] = {0,}, res[4] = {0,};
00429 doSimpleCallingInterfaceSmi(class_admin_password, 0, args, res);
00430 format = PW_FORMAT_SCAN_CODE;
00431 goto out;
00432 }
00433 catch(const exception &)
00434 { }
00435
00436 try
00437 {
00438 u32 args[4] = {0,}, res[4] = {0,};
00439 doSimpleCallingInterfaceSmi(class_user_password, 0, args, res);
00440 format = PW_FORMAT_SCAN_CODE;
00441 goto out;
00442 }
00443 catch(const exception &)
00444 { }
00445
00446 try
00447 {
00448 u8 maxLen=0, minLen=0, props=0;
00449 getPasswordPropertiesII(class_admin_password, maxLen, minLen, props);
00450 format = PW_FORMAT_SCAN_CODE;
00451 if (props & 0x01)
00452 format = PW_FORMAT_ASCII;
00453 goto out;
00454 }
00455 catch(const exception &)
00456 { }
00457
00458 try
00459 {
00460 u8 maxLen=0, minLen=0, props=0;
00461 getPasswordPropertiesII(class_user_password, maxLen, minLen, props);
00462 format = PW_FORMAT_SCAN_CODE;
00463 if (props & 0x01)
00464 format = PW_FORMAT_ASCII;
00465 goto out;
00466 }
00467 catch(const exception &)
00468 { }
00469
00470 out:
00471 return format;
00472 }
00473
00474 static u32 readSetting(u16 select, u32 location, u32 *minValue, u32 *maxValue)
00475 {
00476 u32 args[4] = {location, 0,}, res[4] = {0,};
00477 doSimpleCallingInterfaceSmi(0, select, args, res);
00478 if(minValue)
00479 *minValue = res[2];
00480 if(maxValue)
00481 *maxValue = res[3];
00482 return res[1];
00483 }
00484
00485 u32 readNVStorage(u32 location, u32 *minValue, u32 *maxValue)
00486 {
00487 return readSetting(0, location, minValue, maxValue);
00488 }
00489
00490 u32 readBatteryModeSetting(u32 location, u32 *minValue, u32 *maxValue)
00491 {
00492 return readSetting(1, location, minValue, maxValue);
00493 }
00494
00495 u32 readACModeSetting(u32 location, u32 *minValue, u32 *maxValue)
00496 {
00497 return readSetting(2, location, minValue, maxValue);
00498 }
00499
00500 u32 readSystemStatus(u32 *failingSensorHandle)
00501 {
00502
00503
00504
00505 return readSetting(3, 0, failingSensorHandle, 0);
00506 }
00507
00508
00509 static u32 writeSetting(const std::string &password, u16 select, u32 location, u32 newValue, u32 *minValue, u32 *maxValue)
00510 {
00511 u32 args[4] = {location, newValue,}, res[4] = {0,};
00512
00513
00514 for(int i=0; i<2; i++)
00515 {
00516 try
00517 {
00518
00519 DCERR("Try #" << i << " for writeSetting()" << endl);
00520 DCERR(" args are : 0x" << args[0] << " 0x" << args[1] << " 0x" << args[2] << " 0x" << args[3] << endl);
00521 doSimpleCallingInterfaceSmi(1, select, args, res);
00522 DCERR(" res was : 0x" << res[0] << " 0x" << res[1] << " 0x" << res[2] << " 0x" << res[3] << endl);
00523 break;
00524 }
00525 catch(const SmiExecutedWithError &)
00526 {
00527
00528 if(i==1)
00529 throw;
00530
00531 DCERR("Executed with error, try password..." << endl);
00532 args[2] = getAuthenticationKey(password);
00533 }
00534 }
00535
00536 if(minValue)
00537 *minValue = res[2];
00538 if(maxValue)
00539 *maxValue = res[3];
00540 return res[1];
00541 }
00542
00543 u32 writeNVStorage(const std::string &password, u32 location, u32 value, u32 *minValue, u32 *maxValue)
00544 {
00545 return writeSetting(password, 0, location, value, minValue, maxValue);
00546 }
00547
00548 u32 writeBatteryModeSetting(const std::string &password, u32 location, u32 value, u32 *minValue, u32 *maxValue)
00549 {
00550 return writeSetting(password, 1, location, value, minValue, maxValue);
00551 }
00552
00553 u32 writeACModeSetting(const std::string &password, u32 location, u32 value, u32 *minValue, u32 *maxValue)
00554 {
00555 return writeSetting(password, 2, location, value, minValue, maxValue);
00556 }
00557
00558 void getDisplayType(u32 &type, u32 &resolution, u32 &memSizeX256kb)
00559 {
00560 u32 args[4] = {0,}, res[4] = {0,};
00561 doSimpleCallingInterfaceSmi(4, 0, args, res);
00562
00563 type = (res[1] & 0x00FF);
00564 resolution = (res[1] & 0xFF00) >> 8;
00565 memSizeX256kb = res[2];
00566 }
00567
00568 void getPanelResolution(u32 &horiz, u32 &vert)
00569 {
00570 u32 args[4] = {0,}, res[4] = {0,};
00571 doSimpleCallingInterfaceSmi(4, 1, args, res);
00572
00573 horiz = (res[1] & 0x0000FFFF);
00574 vert = (res[1] & 0xFFFF0000) >> 16;
00575 }
00576
00577 void getActiveDisplays(u32 &bits)
00578 {
00579 u32 args[4] = {0,}, res[4] = {0,};
00580 doSimpleCallingInterfaceSmi(4, 2, args, res);
00581
00582 bits = res[1];
00583 }
00584
00585 void setActiveDisplays(u32 &bits)
00586 {
00587 u32 args[4] = {bits, 0,}, res[4] = {0,};
00588 doSimpleCallingInterfaceSmi(4, 3, args, res);
00589 }
00590
00591 void getPropertyOwnershipTag(char *tagBuf, size_t size)
00592 {
00593 u32 args[4] = {0,};
00594
00595 std::auto_ptr<smi::IDellCallingInterfaceSmi> smi(setupCallingInterfaceSmi(20, 0, args));
00596 smi->setBufferSize(120);
00597 smi->setArgAsPhysicalAddress( 0, 0 );
00598 smi->execute();
00599 strncpy( tagBuf, reinterpret_cast<char*>(smi->getBufferPtr()), size < 80? size:80);
00600 }
00601
00602 void setPropertyOwnershipTag(const string password, const char *newTag, size_t size)
00603 {
00604 u32 args[4] = {0,};
00605
00606 for(int i=0; i<2; i++)
00607 {
00608 try
00609 {
00610
00611 std::auto_ptr<smi::IDellCallingInterfaceSmi> smi(setupCallingInterfaceSmi(20, 1, args));
00612 smi->setBufferSize(120);
00613 strncpy( reinterpret_cast<char*>(smi->getBufferPtr()), newTag, size < 80? size:80);
00614 smi->setArgAsPhysicalAddress( 0, 0 );
00615 smi->execute();
00616 break;
00617 }
00618 catch(const SmiExecutedWithError &)
00619 {
00620
00621 if(i==1)
00622 throw;
00623
00624
00625 args[1] = getAuthenticationKey(password);
00626 }
00627 }
00628 }
00629
00630
00631
00632
00633 const int Bluetooth_Devices_Disable = 0x0153;
00634 const int Bluetooth_Devices_Enable = 0x0152;
00635 const int Cellular_Radio_Disable = 0x017B;
00636 const int Cellular_Radio_Enable = 0x017C;
00637 const int WiFi_Locator_Disable = 0x017D;
00638 const int WiFi_Locator_Enable = 0x017E;
00639 const int Wireless_LAN_Disable = 0x017F;
00640 const int Wireless_LAN_Enable = 0x0180;
00641 const int Wireless_Switch_Bluetooth_Control_Disable = 0x0181;
00642 const int Wireless_Switch_Bluetooth_Control_Enable = 0x0182;
00643 const int Wireless_Switch_Cellular_Control_Disable = 0x0183;
00644 const int Wireless_Switch_Cellular_Control_Enable = 0x0184;
00645 const int Wireless_Switch_Wireless_LAN_Control_Disable = 0x0185;
00646 const int Wireless_Switch_Wireless_LAN_Control_Enable = 0x0186;
00647 const int Radio_Transmission_Enable = 0x010c;
00648 const int Radio_Transmission_Disable = 0x010d;
00649 const int Wireless_Device_Disable = 0x0114;
00650 const int Wireless_Device_App_Control = 0x0115;
00651 const int Wireless_Device_App_Or_Hotkey_Control = 0x0116;
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672 void wirelessRadioControl(bool enable, bool boot, bool runtime, int enable_token, int disable_token, int radioNum, std::string password)
00673 {
00674 if (boot)
00675 smbios::activateToken( (enable ?
00676 enable_token :
00677 disable_token),
00678 password
00679 );
00680 if (runtime)
00681 {
00682 if (enable && !smbios::isTokenActive(enable_token))
00683 throw ConfigErrorImpl("boot time config disabled, runtime setting has no effect.");
00684
00685 u32 disable = enable ? 0:1;
00686 u32 args[4] = {(1 | (static_cast<u32>(radioNum)<<8) | ((disable)<<16)), 0, 0, 0};
00687 u32 res[4] = {0,};
00688 doSimpleCallingInterfaceSmi(17, 11, args, res);
00689 }
00690 }
00691
00692
00693 static void switchControl(u32 whichConfig, u32 whichSwitch, bool enable)
00694 {
00695 std::auto_ptr<smi::ISmi> smi = smi::SmiFactory::getFactory()->makeNew(smi::SmiFactory::DELL_CALLING_INTERFACE_SMI);
00696 smi::IDellCallingInterfaceSmi *ci = dynamic_cast<smi::IDellCallingInterfaceSmi *>(smi.get());
00697 ci->setClass( 17 );
00698 ci->setSelect( 11 );
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723 ci->setArg(smi::cbARG1, 0x2);
00724 ci->execute();
00725
00726 u32 oldConfig = ci->getRes(smi::cbRES2);
00727 if (whichConfig == 1)
00728 oldConfig &= 0xFF;
00729 else if (whichConfig == 2)
00730 oldConfig = ((oldConfig>>8) & 0xFF);
00731
00732 u32 newConfig = (oldConfig & ~whichSwitch) | ((enable?1:0) * whichSwitch);
00733 ci->setArg(smi::cbARG1, (0x2 | (whichConfig << 8) | (newConfig << 16)));
00734 ci->execute();
00735 }
00736
00737 void wirelessSwitchControl(bool enable, bool boot, bool runtime, int enable_token, int disable_token, int switchNum, std::string password)
00738 {
00739 int intSwitchConfig = 0, intSwitchNum = 0;
00740 switch(switchNum)
00741 {
00742 case WLAN_SWITCH_CTL:
00743 intSwitchConfig = 1;
00744 intSwitchNum = 1;
00745 break;
00746 case BLUETOOTH_SWITCH_CTL:
00747 intSwitchConfig = 1;
00748 intSwitchNum = 2;
00749 break;
00750 case WWAN_SWITCH_CTL:
00751 intSwitchConfig = 1;
00752 intSwitchNum = 4;
00753 break;
00754 case LOCATOR_SWITCH_CTL:
00755 intSwitchConfig = 2;
00756 intSwitchNum = 1;
00757 break;
00758 default:
00759 throw ParameterErrorImpl("Invalid switch number passed to wirelessSwitchControl()");
00760 }
00761
00762 if (boot)
00763 smbios::activateToken( (enable ?
00764 enable_token :
00765 disable_token),
00766 password
00767 );
00768 if (runtime)
00769 switchControl(intSwitchConfig, intSwitchNum, enable);
00770 }
00771
00772 radioStatusCode wirelessRadioStatus(radioNum which, std::ostream &cout, u32 defRes2)
00773 {
00774 radioStatusCode ret = STATUS_UNKNOWN;
00775 try
00776 {
00777 u32 args[4] = {0,}, res[4] ={0,};
00778 if (!defRes2)
00779 smi::doSimpleCallingInterfaceSmi(17, 11, args, res);
00780 else
00781 res[smi::cbRES2] = defRes2;
00782
00783 int supported_bit=0, installed_bit=0, disabled_bit=0;
00784 string name;
00785 switch(which)
00786 {
00787 case smi::WLAN_RADIO_NUM:
00788 supported_bit = 2;
00789 installed_bit = 8;
00790 disabled_bit = 17;
00791 name = "WLAN";
00792 break;
00793 case smi::BLUETOOTH_RADIO_NUM:
00794 supported_bit = 3;
00795 installed_bit = 9;
00796 disabled_bit = 18;
00797 name = "Bluetooth";
00798 break;
00799 case smi::WWAN_RADIO_NUM:
00800 supported_bit = 4;
00801 installed_bit = 10;
00802 disabled_bit = 19;
00803 name = "WWAN";
00804 break;
00805 }
00806
00807 cout << "Radio Status for " << name << ":" << endl;
00808 if (res[smi::cbRES2] & (1 << supported_bit))
00809 {
00810 cout << "\t" << name << " supported" << endl;
00811 cout << "\t" << name << " " << ((res[smi::cbRES2] & (1 << installed_bit)) ? "installed":"not installed") << endl;
00812 cout << "\t" << name << " " << ((res[smi::cbRES2] & (1 << disabled_bit)) ? "disabled" : "enabled") << endl;
00813
00814 ret = STATUS_DISABLED;
00815 if (!(res[smi::cbRES2] & (1 << installed_bit)))
00816 ret = STATUS_NOT_PRESENT;
00817 else if (!(res[smi::cbRES2] & (1 << disabled_bit)))
00818 ret = STATUS_ENABLED;
00819 } else {
00820 cout << "\t" << name << " not supported" << endl;
00821 ret = STATUS_UNSUPPORTED;
00822 }
00823 cout << "\tStatus Code: " << ret << endl;
00824 } catch (smi::UnsupportedSmi &) {
00825
00826 }
00827 return ret;
00828 }
00829
00830 }