IOFireWireLocalNode.cpp [plain text]
#import <IOKit/firewire/IOFireWireBus.h>
#import <IOKit/firewire/IOFireWireController.h>
#import "IOFireWireMagicMatchingNub.h"
#import "IOFireWireLocalNode.h"
OSDefineMetaClassAndStructors(IOFireWireLocalNodeAux, IOFireWireNubAux);
OSMetaClassDefineReservedUnused(IOFireWireLocalNodeAux, 0);
OSMetaClassDefineReservedUnused(IOFireWireLocalNodeAux, 1);
OSMetaClassDefineReservedUnused(IOFireWireLocalNodeAux, 2);
OSMetaClassDefineReservedUnused(IOFireWireLocalNodeAux, 3);
#pragma mark -
bool IOFireWireLocalNodeAux::init( IOFireWireLocalNode * primary )
{
bool success = true;
if( !IOFireWireNubAux::init( primary ) )
success = false;
if( success )
{
}
return success;
}
void IOFireWireLocalNodeAux::free()
{
IOFireWireNubAux::free();
}
#pragma mark -
OSDefineMetaClassAndStructors(IOFireWireLocalNode, IOFireWireNub)
bool IOFireWireLocalNode::init(OSDictionary * propTable)
{
if(!IOFireWireNub::init(propTable))
return false;
fMaxReadROMPackLog = 11;
fMaxReadPackLog = 11;
fMaxWritePackLog = 11;
return true;
}
IOFireWireNubAux * IOFireWireLocalNode::createAuxiliary( void )
{
IOFireWireLocalNodeAux * auxiliary;
auxiliary = new IOFireWireLocalNodeAux;
if( auxiliary != NULL && !auxiliary->init(this) )
{
auxiliary->release();
auxiliary = NULL;
}
return auxiliary;
}
bool IOFireWireLocalNode::attach(IOService * provider )
{
assert(OSDynamicCast(IOFireWireController, provider));
if( !IOFireWireNub::attach(provider))
return (false);
fControl = (IOFireWireController *)provider;
fControl->retain();
return(true);
}
void IOFireWireLocalNode::setNodeProperties(UInt32 gen, UInt16 nodeID,
UInt32 *selfIDs, int numSelfIDs, IOFWSpeed maxSpeed )
{
OSObject *prop;
fLocalNodeID = fNodeID = nodeID;
fGeneration = gen;
prop = OSNumber::withNumber(nodeID, 16);
setProperty(gFireWireNodeID, prop);
prop->release();
prop = OSData::withBytes(selfIDs, numSelfIDs*sizeof(UInt32));
setProperty(gFireWireSelfIDs, prop);
prop->release();
prop = OSNumber::withNumber(maxSpeed, 32);
setProperty(gFireWireSpeed, prop);
prop->release();
}
IOReturn IOFireWireLocalNode::message( UInt32 mess, IOService * provider,
void * argument )
{
if( kIOFWMessagePowerStateChanged == mess )
{
messageClients( mess );
return kIOReturnSuccess;
}
if( kIOFWMessageTopologyChanged == mess )
{
messageClients( mess );
return kIOReturnSuccess;
}
return IOService::message(mess, provider, argument );
}
bool IOFireWireLocalNode::handleOpen( IOService * forClient,
IOOptionBits options,
void * arg )
{
bool ok = true ;
if ( fOpenCount == 0)
ok = IOFireWireNub::handleOpen( this, 0, NULL ) ;
if ( ok )
fOpenCount++ ;
return ok;
}
void IOFireWireLocalNode::handleClose( IOService * forClient,
IOOptionBits options )
{
if ( fOpenCount )
{
fOpenCount-- ;
if ( fOpenCount == 0)
IOFireWireNub::handleClose( this, 0 );
}
}
bool IOFireWireLocalNode::handleIsOpen( const IOService * forClient ) const
{
return (fOpenCount > 0 ) ;
}
IOReturn IOFireWireLocalNode::setProperties( OSObject * properties )
{
OSDictionary *dict = OSDynamicCast(OSDictionary, properties);
OSDictionary *summon;
if(!dict)
return kIOReturnUnsupported;
summon = OSDynamicCast(OSDictionary, dict->getObject("SummonNub"));
if(!summon) {
return kIOReturnBadArgument;
}
IOFireWireMagicMatchingNub *nub = NULL;
IOReturn ret = kIOReturnBadArgument;
do {
nub = new IOFireWireMagicMatchingNub;
if(!nub->init(summon))
break;
if (!nub->attach(this))
break;
nub->registerService(kIOServiceSynchronous);
if(!nub->getClient()) {
nub->detach(this);
}
ret = kIOReturnSuccess;
} while (0);
if(nub)
nub->release();
return ret;
}