bool IOFWController::publishProperties()
{
    bool			ret = false;
    IOFWAddress		addr;
    OSDictionary	*dict;

    do {
        // Let the superclass publish properties first.

        if (super::publishProperties() == false)
            break;

        // Publish the controller's FireWire address.

        if ( (getHardwareAddress(&addr) != kIOReturnSuccess) ||
             (setProperty(kIOMACAddress,  (void *) &addr,
                          kIOFWAddressSize) == false) )
        {
            break;
        }

        // Publish FireWire defined packet filters.
        
        dict = OSDynamicCast(OSDictionary, getProperty(kIOPacketFilters));
        if ( dict )
        {
            UInt32			filters;
            OSNumber		*num;
            OSDictionary	*newdict;
			
            
            if ( getPacketFilters(gIOEthernetWakeOnLANFilterGroup,
                                  &filters) != kIOReturnSuccess )
            {
                break;
            }

            num = OSNumber::withNumber(filters, sizeof(filters) * 8);
            if (num == 0)
                break;

			//to avoid race condition with external threads we'll modify a copy of dictionary
			newdict = OSDictionary::withDictionary(dict); //copy the dictionary
			if(newdict)
			{
				ret = newdict->setObject(gIOEthernetWakeOnLANFilterGroup, num); //and add the WOL group to it
				setProperty(kIOPacketFilters, newdict); //then replace the property with the new dictionary
				newdict->release();
			}
            num->release();
        }
    }
    while (false);

    return ret;
}
Exemplo n.º 2
0
WLCard::
WLCard(void* ioBase, void* klBase, IOService* parent) : _ioBase(ioBase),
                                     _keyLargoBase(klBase),
        			     _interrupts(0),
                                     _isEnabled(false),
                                      _parent(parent)
{
    _powerOn();
    IODelay(200 * 1000);
    _reset();

    /*
     * Get firmware vendor and version
     */
    WLIdentity ident;
    if (getIdentity(&ident) != kIOReturnSuccess) {
        WLLogErr("WLCard::WLCard: Couldn't read card identity\n");
        return;
    }

    WLLogNotice("WLCard: Firmware vendor %d, variant %d, version %d.%d\n",
                ident.vendor, ident.variant, ident.major, ident.minor);

    WLHardwareAddress macAddr;
    if (getHardwareAddress(&macAddr) != kIOReturnSuccess) {
        WLLogErr("WLCard::WLCard: Couldn't read MAC address\n");
        return;
    }
    
    _workLoop = _parent->getWorkLoop();
    if (!_workLoop) {
        WLLogErr("WLCard::WLCard: Failed to create workloop.\n");
        return;
    }
    
    _timedSendSource = IOTimerEventSource::timerEventSource(_parent, &WLCard::_myTimeoutHandler);
    if (!_timedSendSource) {
        WLLogErr("WLCard::WLCard: Failed to create timer event source.\n");
        return;
    }

    if (_workLoop->addEventSource(_timedSendSource) != kIOReturnSuccess) {
        WLLogErr("WLCard::WLCard: Failed to register timer event source.\n");
        return;
    }
}
/**
 * @return
 * the MAC address of the main IP address
 */
unsigned char * getMainIpMacAddress(void) {
	if (!macSet) {
		struct ifreq ifr;
		unsigned char * macInIfr;

		struct interface *mainInterface = if_ifwithaddr(&olsr_cnf->main_addr);
		if (!mainInterface) {
			pudError(true, "Could not get the main interface");
			return NULL;
		}
		macInIfr = getHardwareAddress(mainInterface->int_name, olsr_cnf->ip_version, &ifr);
		if (!macInIfr) {
			pudError(true, "Could not get the MAC address of the main interface");
			return NULL;
		}
		memcpy(&mac[0], &macInIfr[0], PUD_NODEIDTYPE_MAC_BYTES);
		macSet = true;
	}

	return &mac[0];
}
IOReturn
IOFWController::getHardwareAddress(void *   addr,
                                         UInt32 * inOutAddrBytes)
{
    UInt32 bufBytes;

    if (inOutAddrBytes == 0)
        return kIOReturnBadArgument;

    // Cache the size of the caller's buffer, and replace it with the
    // number of bytes required.

    bufBytes        = *inOutAddrBytes;
    *inOutAddrBytes = kIOFWAddressSize;

    // Make sure the buffer is large enough for a single FireWire
    // hardware address.

    if ((addr == 0) || (bufBytes < kIOFWAddressSize))
        return kIOReturnNoSpace;

    return getHardwareAddress((IOFWAddress *) addr);
}