#include <libkern/OSByteOrder.h>
#include <libkern/c++/OSDictionary.h>
#include <IOKit/IOMemoryDescriptor.h>
#include <libkern/c++/OSData.h>
#include <IOKit/usb/USB.h>
#include <IOKit/usb/IOUSBController.h>
#include <IOKit/usb/IOUSBNub.h>
#include <IOKit/usb/IOUSBPipe.h>
#define DEBUGGING_LEVEL 0
#if DEBUGGING_LEVEL > 0
#define USBExpertStatusLevel(a, b, c, d) if (IOUSBController::_log) IOUSBController::_log->AddStatusLevel((UInt32)a, (UInt32)b, (char*)c, (UInt32)d)
#else
#define USBExpertStatusLevel(a, b, c, d)
#endif
#define super IOService
#if 0
static const
IOUSBDescriptorHeader *NextDescriptor(const void *desc)
{
const UInt8 *next = (const UInt8 *)desc;
UInt8 length = next[0];
next = &next[length];
return((const IOUSBDescriptorHeader *)next);
}
const IOUSBDescriptorHeader*
IOUSBNub::FindNextDescriptor(const void *cur, UInt8 descType)
{
const IOUSBDescriptorHeader *hdr;
hdr = (const IOUSBDescriptorHeader *)cur;
do {
hdr = NextDescriptor(hdr);
if(hdr->length == 0)
break;
if(descType == 0)
return hdr; else if(hdr->descriptorType == descType)
return hdr;
}
while(true);
return NULL; }
#endif
OSDefineMetaClass( IOUSBNub, IOService )
OSDefineAbstractStructors(IOUSBNub, IOService)
bool
IOUSBNub::USBCompareProperty( OSDictionary * matching, const char * key )
{
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
IOUSBNub::IsWildCardMatch( OSDictionary * matching, const char * key )
{
OSString * theString;
bool matches;
theString = OSDynamicCast(OSString, matching->getObject( key ));
if( theString)
matches = theString->isEqualTo("*");
else
matches = false;
return matches;
}
bool
IOUSBNub::USBComparePropertyWithMask( OSDictionary *matching, const char *key, const char * maskKey )
{
OSNumber * registryProperty = NULL;
OSNumber * dictionaryProperty = NULL;
OSNumber * dictionaryMask = NULL;
registryProperty = OSDynamicCast(OSNumber, getProperty(key));
dictionaryProperty = OSDynamicCast(OSNumber, matching->getObject(key));
dictionaryMask = OSDynamicCast(OSNumber, matching->getObject(maskKey));
if ( registryProperty && dictionaryProperty && dictionaryMask )
{
UInt32 registryValue = registryProperty->unsigned32BitValue();
UInt32 dictionaryValue = dictionaryProperty->unsigned32BitValue();
UInt32 mask = dictionaryMask->unsigned32BitValue();
if ( (registryValue & mask) == (dictionaryValue & mask) )
{
return true;
}
}
return false;
}