bool CompareDeviceUsage( IOService * owner, OSDictionary * matching, SInt32 * score, SInt32 increment) { // We return success if we match the key in the dictionary with the key in // the property table, or if the prop isn't present // OSObject * usage; OSObject * usagePage; OSArray * functions; OSDictionary * pair; bool matches = true; int count; usage = matching->getObject( kIOHIDDeviceUsageKey ); usagePage = matching->getObject( kIOHIDDeviceUsagePageKey ); functions = OSDynamicCast(OSArray, owner->copyProperty( kIOHIDDeviceUsagePairsKey )); if ( functions ) { if ( usagePage || usage ) { count = functions->getCount(); for (int i=0; i<count; i++) { if ( !(pair = (OSDictionary *)functions->getObject(i)) ) continue; if ( !usagePage || !(matches = usagePage->isEqualTo(pair->getObject(kIOHIDDeviceUsagePageKey))) ) continue; if ( score && !usage ) { *score += increment / 2; break; } if ( !usage || !(matches = usage->isEqualTo(pair->getObject(kIOHIDDeviceUsageKey))) ) continue; if ( score ) *score += increment; break; } } functions->release(); } else { matches = false; } return matches; }
//--------------------------------------------------------------------------- // Compare the properties in the supplied table to this object's properties. bool CompareProperty( IOService * owner, OSDictionary * matching, const char * key, SInt32 * score, SInt32 increment) { // We return success if we match the key in the dictionary with the key in // the property table, or if the prop isn't present // OSObject * value; OSObject * property; bool matches = true; value = matching->getObject( key ); if( value) { property = owner->copyProperty( key ); if ( property ) { matches = value->isEqualTo( property ); if (matches && score) *score += increment; property->release(); } else matches = false; } return matches; }
bool IOUSBNub::USBCompareProperty( OSDictionary * matching, const OSSymbol * key ) { // We return success iff we match the key in the dictionary with the key in // the property table. // OSObject *value; bool matches = false; OSObject *myProperty = NULL; value = matching->getObject( key ); if ( value) { myProperty = copyProperty(key); if (myProperty) { matches = value->isEqualTo( myProperty); myProperty->release(); } } else matches = false; return matches; }
bool IOFireWireMagicMatchingNub::matchPropertyTable( OSDictionary * table ) { OSObject *clientClass; clientClass = table->getObject("IOClass"); if(!clientClass) return false; return clientClass->isEqualTo( getProperty( "IODesiredChild" ) ); }
bool FakeSMC::start(IOService *provider) { if (!super::start(provider)) return false; int arg_value = 1; // Check if we have SMC already if (OSDictionary *matching = serviceMatching("IOACPIPlatformDevice")) { if (OSIterator *iterator = getMatchingServices(matching)) { OSString *smcNameProperty = OSString::withCString("APP0001"); while (IOService *service = (IOService*)iterator->getNextObject()) { OSObject *serviceNameProperty = service->getProperty("name"); if (serviceNameProperty && serviceNameProperty->isEqualTo(smcNameProperty)) { HWSensorsFatalLog("SMC device detected, will not create another one"); return false; } } OSSafeRelease(iterator); } OSSafeRelease(matching); } if (!smcDevice->initAndStart(provider, this)) { HWSensorsInfoLog("failed to initialize SMC device"); return false; } registerService(); // Load keys from NVRAM if (PE_parse_boot_argn("-fakesmc-use-nvram", &arg_value, sizeof(arg_value))) { if (UInt32 count = smcDevice->loadKeysFromNVRAM()) HWSensorsInfoLog("%d key%s loaded from NVRAM", count, count == 1 ? "" : "s"); else HWSensorsInfoLog("NVRAM will be used to store system written keys..."); } return true; }
bool FakeSMC::start(IOService *provider) { if (!super::start(provider)) return false; if (!(keyStore = OSDynamicCast(FakeSMCKeyStore, waitForMatchingService(serviceMatching(kFakeSMCKeyStoreService), kFakeSMCDefaultWaitTimeout)))) { HWSensorsInfoLog("still waiting for FakeSMCKeyStore..."); return false; // HWSensorsDebugLog("creating FakeSMCKeyStore"); // // if (!(keyStore = new FakeSMCKeyStore)) { // HWSensorsInfoLog("failed to create FakeSMCKeyStore"); // return false; // } // // HWSensorsDebugLog("initializing FakeSMCKeyStore"); // // if (keyStore->initAndStart(this, configuration)) { // keyStore->setProperty("IOUserClientClass", "FakeSMCKeyStoreUserClient"); // } // else { // keyStore->release(); // HWSensorsFatalLog("failed to initialize FakeSMCKeyStore device"); // return false; // } } // if (IOService *resources = waitForMatchingService(serviceMatching("IOResources"), 0)) // this->attach(resources); OSDictionary *configuration = OSDynamicCast(OSDictionary, getProperty("Configuration")); // Load preconfigured keys HWSensorsDebugLog("loading keys..."); if (!configuration) { HWSensorsFatalLog("no configuration node found!"); return false; } if (UInt32 count = keyStore->addKeysFromDictionary(OSDynamicCast(OSDictionary, configuration->getObject("Keys")))) { HWSensorsInfoLog("%d preconfigured key%s added", count, count == 1 ? "" : "s"); } else { HWSensorsWarningLog("no preconfigured keys found"); } // Load wellknown type names HWSensorsDebugLog("loading types..."); keyStore->addWellKnownTypesFromDictionary(OSDynamicCast(OSDictionary, configuration->getObject("Types"))); // Set Clover platform keys if (OSDictionary *dictionary = OSDynamicCast(OSDictionary, configuration->getObject("Clover"))) { UInt32 count = 0; if (IORegistryEntry* cloverPlatformNode = fromPath("/efi/platform", gIODTPlane)) { if (OSIterator *iterator = OSCollectionIterator::withCollection(dictionary)) { while (OSString *name = OSDynamicCast(OSString, iterator->getNextObject())) { if (OSData *data = OSDynamicCast(OSData, cloverPlatformNode->getProperty(name))) { if (OSArray *items = OSDynamicCast(OSArray, dictionary->getObject(name))) { OSString *key = OSDynamicCast(OSString, items->getObject(0)); OSString *type = OSDynamicCast(OSString, items->getObject(1)); if (keyStore->addKeyWithValue(key->getCStringNoCopy(), type->getCStringNoCopy(), data->getLength(), data->getBytesNoCopy())) count++; } } } OSSafeRelease(iterator); } } if (count) HWSensorsInfoLog("%d key%s exported by Clover EFI", count, count == 1 ? "" : "s"); } // Check if we have SMC already bool smcDeviceFound = false; if (OSDictionary *matching = serviceMatching("IOACPIPlatformDevice")) { if (OSIterator *iterator = getMatchingServices(matching)) { OSString *smcNameProperty = OSString::withCString("APP0001"); while (IOService *service = (IOService*)iterator->getNextObject()) { OSObject *serviceNameProperty = service->getProperty("name"); if (serviceNameProperty && serviceNameProperty->isEqualTo(smcNameProperty)) { smcDeviceFound = true; } } OSSafeRelease(iterator); } OSSafeRelease(matching); } if (!smcDeviceFound) { if (!(smcDevice = new FakeSMCDevice)) { HWSensorsInfoLog("failed to create SMC device"); return false; } IOService *platformExpert = waitForMatchingService(serviceMatching("IOACPIPlatformExpert"), kFakeSMCDefaultWaitTimeout); if (!smcDevice->initAndStart(platformExpert, this)) { HWSensorsFatalLog("failed to initialize SMC device"); return false; } } else { HWSensorsInfoLog("found physical SMC device, will not create virtual one. Providing only basic plugins functionality"); } int arg_value = 1; // Load keys from NVRAM if (PE_parse_boot_argn("-fakesmc-use-nvram", &arg_value, sizeof(arg_value))) { if (UInt32 count = keyStore->loadKeysFromNVRAM()) HWSensorsInfoLog("%d key%s loaded from NVRAM", count, count == 1 ? "" : "s"); else HWSensorsInfoLog("NVRAM will be used to store system written keys..."); } registerService(); return true; }