void	ApplePS2CypressTouchPad::cypressSimulateEvent(char button)
{
  uint64_t	now_abs;

  clock_get_uptime(&now_abs);
  dispatchRelativePointerEventX(0, 0, button, now_abs);
  if (_activeDragLock)
    return ;
  clock_get_uptime(&now_abs);
  dispatchRelativePointerEventX(0, 0, 0x00, now_abs);
}
Пример #2
0
IOService* BrcmPatchRAM::probe(IOService *provider, SInt32 *probeScore)
{
    extern kmod_info_t kmod_info;
    uint64_t start_time, end_time, nano_secs;
    
    DebugLog("probe\n");
    
    AlwaysLog("Version %s starting on OS X Darwin %d.%d.\n", kmod_info.version, version_major, version_minor);

    clock_get_uptime(&start_time);

    mWorkLock = IOLockAlloc();
    if (!mWorkLock)
        return NULL;

    mCompletionLock = IOLockAlloc();
    if (!mCompletionLock)
        return NULL;

    mDevice = OSDynamicCast(IOUSBDevice, provider);
    if (!mDevice)
    {
        AlwaysLog("Provider is not a USB device.\n");
        return NULL;
    }
    mDevice->retain();
    
    initBrcmStrings();
    OSString* displayName = OSDynamicCast(OSString, getProperty(kDisplayName));
    if (displayName)
        provider->setProperty(kUSBProductString, displayName);
    
    mVendorId = mDevice->GetVendorID();
    mProductId = mDevice->GetProductID();

    // get firmware here to pre-cache for eventual use on wakeup or now
    if (BrcmFirmwareStore* firmwareStore = getFirmwareStore())
        firmwareStore->getFirmware(OSDynamicCast(OSString, getProperty(kFirmwareKey)));

    uploadFirmware();
    publishPersonality();

    clock_get_uptime(&end_time);
    absolutetime_to_nanoseconds(end_time - start_time, &nano_secs);
    uint64_t milli_secs = nano_secs / 1000000;
    AlwaysLog("Processing time %llu.%llu seconds.\n", milli_secs / 1000, milli_secs % 1000);
    
    return this;
}
Пример #3
0
bool driver::start(IOService *provider) {
 uint32_t rc;
   
 chkpoint("begin");
 if (super::start(provider)==false) return(false);	// Start our superclass first

 // Get our workloop?
 createWorkLoop();

 if (!workLoop) fail("workLoop");
   

 // Set up a timer event source for performance monitoring
 perfTimer = IOTimerEventSource::timerEventSource(this, (IOTimerEventSource::Action)&perfTimerWrapper);
 if (!perfTimer) fail("perfTimer");
 if (workLoop->addEventSource(perfTimer) != kIOReturnSuccess) fail("workLoop->addEventSource(perfTimer)");
 
 // Set driver status
 driverStatus = driverPark;

 stepCurrent = num_speeds - 1;
 
 driverStatus = driverDrive;
 
 perfTimer->setTimeoutMS(1024);
 clock_get_uptime(&lastTimer);

 chkpoint("success");
 return(true);
 
 fail:
 stop(provider);
 return(false);
}
Пример #4
0
inline void NDAS_clock_get_uptime(uint64_t *time)
{
#ifdef __KPI_SOCKET__	// BUG BUG BUG!!!
	/*
	uint64_t	absoluteTime;
	
	clock_get_uptime(&absoluteTime);
	
	absolutetime_to_nanoseconds(absoluteTime, time);
	*/
	
	uint32_t	secpart, nsecpart;
	
	clock_get_system_nanotime(&secpart, &nsecpart);
	*time = nsecpart + (1000000000ULL * secpart); //convert seconds to  nanoseconds.
	
#else 
	AbsoluteTime	absoluteTime;
	
	clock_get_uptime(&absoluteTime);
	
	//AbsoluteTime_to_scalar((AbsoluteTime*)time);
	
	absolutetime_to_nanoseconds(absoluteTime, time);
#endif
}
Пример #5
0
IOReturn BrcmPatchRAM::setPowerState(unsigned long which, IOService *whom)
{
    DebugLog("setPowerState: which = 0x%lx\n", which);
    
    if (which == kMyOffPowerState)
    {
        // consider firmware no longer loaded
        mDevice->removeProperty(kFirmwareLoaded);

        // in the case the instance is shutting down, don't do anything
        if (mFirmwareStore)
        {
            // unload native bluetooth driver
            IOReturn result = gIOCatalogue->terminateDriversForModule(brcmBundleIdentifier, false);
            if (result != kIOReturnSuccess)
                AlwaysLog("[%04x:%04x]: failure terminating native Broadcom bluetooth (%08x)\n", mVendorId, mProductId, result);
            else
                DebugLog("[%04x:%04x]: success terminating native Broadcom bluetooth\n", mVendorId, mProductId);

            // unpublish native bluetooth personality
            removePersonality();
        }
    }
    else if (which == kMyOnPowerState)
    {
        clock_get_uptime(&wake_time);
        // start loading firmware for case probe is never called after wake
        if (!mDevice->getProperty(kFirmwareLoaded))
            mTimer->setTimeoutMS(400); // longest time seen in normal re-probe was ~200ms
    }

    return IOPMAckImplied;
}
void ApplePS2SynapticsTouchPad::
     dispatchRelativePointerEventWithPacket( UInt8 * packet,
                                             UInt32  packetSize )
{
    //
    // Process the three byte relative format packet that was retreived from the
    // trackpad. The format of the bytes is as follows:
    //
    //  7  6  5  4  3  2  1  0
    // -----------------------
    // YO XO YS XS  1  M  R  L
    // X7 X6 X5 X4 X3 X3 X1 X0  (X delta)
    // Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0  (Y delta)
    //

    UInt32       buttons = 0;
    SInt32       dx, dy;
    AbsoluteTime now;

    if ( (packet[0] & 0x1) ) buttons |= 0x1;  // left button   (bit 0 in packet)
    if ( (packet[0] & 0x2) ) buttons |= 0x2;  // right button  (bit 1 in packet)
    if ( (packet[0] & 0x4) ) buttons |= 0x4;  // middle button (bit 2 in packet)
    
    dx = ((packet[0] & 0x10) ? 0xffffff00 : 0 ) | packet[1];
    dy = -(((packet[0] & 0x20) ? 0xffffff00 : 0 ) | packet[2]);

    clock_get_uptime(&now);
    
    dispatchRelativePointerEvent(dx, dy, buttons, now);
}
Пример #7
0
bool REACConnection::start() {
    if (NULL == timerEventSource || workLoop->addEventSource(timerEventSource) != kIOReturnSuccess) {
        IOLog("REACConnection::start() - Error: Failed to add timer event source to work loop!\n");
        return false;
    }


    timerEventSource->setTimeout(timeoutNS);

    uint64_t time;
    clock_get_uptime(&time);
    absolutetime_to_nanoseconds(time, &nextTime);
    nextTime += timeoutNS;

    iff_filter filter;
    filter.iff_cookie = this;
    filter.iff_name = "REAC driver input filter";
    filter.iff_protocol = 0;
    filter.iff_input = &REACConnection::filterInputFunc;
    filter.iff_output = NULL;
    filter.iff_event = NULL;
    filter.iff_ioctl = NULL;
    filter.iff_detached = &REACConnection::filterDetachedFunc;

    if (0 != iflt_attach(interface, &filter, &filterRef)) {
        return false;
    }

    started = true;

    return true;
}
Пример #8
0
int
Rules::DeactivateRule(UInt32 ruleId)
{
    int result = -1;

    IOLockLock(lock);
    Rule* workRule = this->root;
    while (workRule)
    {
        if(workRule->id == ruleId)
        {
            if(workRule->state == RuleStateInactive)
            {
                workRule->state = RuleStateActive;
                clock_get_uptime(&lastChangedTime);
                result = 0;
            }
            else
            {
                result = 1;//alredy inactive
            }
            break;
        }

        workRule = workRule->next;
    }

    IOLockUnlock(lock);
    return result;
}
//==============================================================================
// IOHIDEvent::initWithCapacity
//==============================================================================
bool IOHIDEvent::initWithCapacity(IOByteCount capacity)
{
    if (!super::init())
        return false;

    if (_data && (!capacity || _capacity < capacity) ) {
        // clean out old data's storage if it isn't big enough
        IOFree(_data, _capacity);
        _data = 0;
    }

    _capacity = capacity;

    if ( !_capacity )
        return false;

    if ( !_data && !(_data = (IOHIDEventData *) IOMalloc(_capacity)))
        return false;

    bzero(_data, _capacity);
    _data->size = _capacity;
    _children = NULL;
    
    clock_get_uptime(&_creationTimeStamp);

    return true;
}
Пример #10
0
IOReturn eqMac2DriverEngine::performAudioEngineStart()
{
    //IOLog("eqMac2DriverEngine[%p]::performAudioEngineStart()\n", this);

    // When performAudioEngineStart() gets called, the audio engine should be started from the beginning
    // of the sample buffer.  Because it is starting on the first sample, a new timestamp is needed
    // to indicate when that sample is being read from/written to.  The function takeTimeStamp() 
    // is provided to do that automatically with the current time.
    // By default takeTimeStamp() will increment the current loop count in addition to taking the current
    // timestamp.  Since we are starting a new audio engine run, and not looping, we don't want the loop count
    // to be incremented.  To accomplish that, false is passed to takeTimeStamp(). 
    
    // The audio engine will also have to take a timestamp each time the buffer wraps around
    // How that is implemented depends on the type of hardware - PCI hardware will likely
    // receive an interrupt to perform that task
    
    takeTimeStamp(false);
    currentBlock = 0;
    
    timerEventSource->setTimeout(blockTimeoutNS);
    
    uint64_t time;
    clock_get_uptime(&time);
    absolutetime_to_nanoseconds(time, &nextTime);

    nextTime += blockTimeoutNS;
    
    return kIOReturnSuccess;
}
Пример #11
0
void eqMac2DriverEngine::ourTimerFired(OSObject *target, IOTimerEventSource *sender)
{
    if (target) {
        eqMac2DriverEngine	*audioEngine = OSDynamicCast(eqMac2DriverEngine, target);
		UInt64				thisTimeNS;
		uint64_t			time;
		SInt64				diff;
        
        if (audioEngine) {
			// make sure we have a client, and thus new data so we don't keep on 
			// just looping around the last client's last buffer!    
            IOAudioStream *outStream = audioEngine->getAudioStream(kIOAudioStreamDirectionOutput, 1);
            if (outStream->numClients == 0) {
                // it has, so clean the buffer 
                memset((UInt8*)audioEngine->mThruBuffer, 0, audioEngine->mBufferSize);
            }
                    
			audioEngine->currentBlock++;
            if (audioEngine->currentBlock >= audioEngine->numBlocks) {
                audioEngine->currentBlock = 0;
                audioEngine->takeTimeStamp();
            }
            
            // calculate next time to fire, by taking the time and comparing it to the time we requested.                                 
            clock_get_uptime(&time);
            absolutetime_to_nanoseconds(time, &thisTimeNS);
			// this next calculation must be signed or we will introduce distortion after only a couple of vectors
			diff = ((SInt64)audioEngine->nextTime - (SInt64)thisTimeNS);
            sender->setTimeout(audioEngine->blockTimeoutNS + diff);
            audioEngine->nextTime += audioEngine->blockTimeoutNS;
        }
    }
}
Пример #12
0
uint8_t soap_rpc_whm(uint8_t len, soap_data_t *args, soap_data_t *result)
{
  if (len != 0) return 1;	/* we don't want args. */

  result->type = SOAP_TYPE_UINT32;
  result->u.d_uint32 = clock_get_uptime();
  return 0;
}
Пример #13
0
void ml_ppc_sleep(void)
{
    struct per_proc_info *proc_info;
    boolean_t dohalt;

    proc_info = getPerProc();
    if (!proc_info->hibernate)
    {
	ml_ppc_do_sleep();
	return;
    }

    {
        uint64_t start, end, nsec;

	HIBLOG("mapping_hibernate_flush start\n");
	clock_get_uptime(&start);

	mapping_hibernate_flush();

	clock_get_uptime(&end);
	absolutetime_to_nanoseconds(end - start, &nsec);
	HIBLOG("mapping_hibernate_flush time: %qd ms\n", nsec / 1000000ULL);
    }

    dohalt = hibernate_write_image();

    if (dohalt)
    {
	// off
	HIBLOG("power off\n");
	if (PE_halt_restart) 
	    (*PE_halt_restart)(kPEHaltCPU);
    }
    else
    {
	// sleep
	HIBLOG("sleep\n");

	// should we come back via regular wake, set the state in memory.
	PerProcTable[0].ppe_vaddr->hibernate = 0;

	PE_cpu_machine_quiesce(proc_info->cpu_id);
	return;
    }
}
void	ApplePS2CypressTouchPad::cypressSimulateLastEvents()
{
  uint64_t	now_abs;

  clock_get_uptime(&now_abs);
#ifdef DEBUG
  if (_frameType >= 0)
    DEBUG_LOG("CYPRESS: _frameType = %d, _frameCounter = %d, _frameTimer %llu, diff %llu\n", _frameType, _frameCounter, _frameTimer, now_abs - _frameTimer);
#endif
  if (_clicking && _frameType == 1 && _frameCounter > 0 && ((now_abs - _frameTimer) < _onefingermaxtaptime)) // 200 ms, all value less than that should be considered as a tap
    {
      // simulate a tap here
      if ((now_abs - _lastOneTap) < 250000000) // 250ms for triple tap drag locking
	_oneTapCounter++;
      else
	{
	  _oneTapCounter = 0;
	  _activeDragLock = false;
	}
      if (_dragLock && _oneTapCounter >= 2)
	_activeDragLock = true;
      this->cypressSimulateEvent(0x01);
      DEBUG_LOG("CYPRESS: one finger tap detected (_oneTapCounter = %d, _lastOneTap = %llu, diff = %llu)\n", _oneTapCounter, _lastOneTap, now_abs - _lastOneTap);
      _lastOneTap = now_abs;
    }
  if (_twoFingerRightClick && _frameType == 2 && _frameCounter > 0 && ((now_abs - _frameTimer) < _twofingermaxtaptime)) // 200 ms, all value less than that should be considered as a tap
    {
      // simulate a tap right click here
      this->cypressSimulateEvent(0x02);
      DEBUG_LOG("CYPRESS: two fingers tap detected\n");
    }
  if (_frameType > 1)
    {
      _kalX.resetFilter();
      _kalY.resetFilter();
    }
  _kalZ.resetFilter();
//   if (_frameType == 3 && _frameCounter > 0 && ((now_abs - _frameTimer) < _threefingermaxtaptime)) // 200 ms, all value less than that should be considered as a tap
//     {
//       // simulate a tap here
//       this->cypressSimulateEvent(0x01);
//       DEBUG_LOG("CYPRESS: three fingers tap detected\n");
//     }
  // Finally thinking that it may not be a good idea to implement a third action on 5 fingers ... may be confusing use between screenlock and show desktop ...
  // More generally, adding more than 2 time based actions on the same finger count may be a bad idea ... so commenting out this code
//   if (_fiveFingerShowDesktop && _frameType == 5 && (now_abs - _frameTimer) < _fivefingermaxtaptime) // 100ms
//     {
//       // Show Desktop here
//       _device->dispatchKeyboardMessage(kPS2M_showDesktop, &now_abs);
//       DEBUG_LOG("CYPRESS: 5 fingers short frame (tap) detected (size=%d), Showing Desktop\n", _frameCounter);
//     }
  if (_fiveFingerScreenLock && _frameType == 5 && (now_abs - _frameTimer) > _fivefingerscreenlocktime && _slept == false) // 800ms, a bit less than 1 sec
    {
      // Lock Screen here
      _device->dispatchKeyboardMessage(kPS2M_screenLock, &now_abs);
      DEBUG_LOG("CYPRESS: 5 fingers long frame detected (size=%d), locking screen\n", _frameCounter);
    }
}
Пример #15
0
uint8_t
uptime_reaction(uint8_t * ptr, struct snmp_varbinding * bind, void *userdata)
{
  if (bind->len != 0)
  {
    return 0;
  }
  return encode_timeticks(ptr, clock_get_uptime());
}
Пример #16
0
void net_habitue_device_SC101::retryResolve()
{
  UInt64 now;
  clock_get_uptime(&now);
  
  if (now - _lastResolve > _resolveInterval &&
      now - _lastReply > _resolveInterval)
  {
    resolve();
  }
}
Пример #17
0
int EInterfaces::update_time_since_last_send(ifnet_t ifref)
{
	int n;
	
	// Iterate over all our interfaces looking for ifref
	for(n=0; n<numberof(m_aInterfaces); n++)
		if ( ifref==m_aInterfaces[n].m_ifnet )
		{
			clock_get_uptime(&m_aInterfaces[n].m_TimeSinceLastSend);
			return 0;
		}
	
	return -1;
}
bool AutoThrottler::setup(OSObject* owner) {
	if (setupDone) return true;
	
	workLoop = IOWorkLoop::workLoop();
	if (workLoop == 0) return false;
	
	perfTimer = IOTimerEventSource::timerEventSource(owner, (IOTimerEventSource::Action) &perfTimerWrapper);
	if (perfTimer == 0) return false;
	
	/* from Superhai (modified by mercurysquad) */
	cpu_count = 0; OSDictionary* service;
	mach_timespec_t serviceTimeout = { 60, 0 }; // in seconds
	totalTimerEvents = 0;
	
	IOService* firstCPU = IOService::waitForService(IOService::serviceMatching("IOCPU"), &serviceTimeout);

	if (!firstCPU) {
		warn("IOKit CPUs not found. Auto-throttle may not work.\n");
		return false;
	} else {
		// we got first cpu, so the others should also be available by now. get them
		service = IOService::serviceMatching("IOCPU");
	}
	
	OSIterator* iterator = IOService::getMatchingServices(service);
	
	if (!iterator) {
		warn("IOKit CPU iterator couldn't be created. Auto-throttle may not work.\n");
		return false;
	}

	IOCPU * cpu;
	while ((cpu = OSDynamicCast(IOCPU, iterator->getNextObject())))
	{
		/*dbg("Got I/O Kit CPU %d (%u) named %s", cpu_count, (unsigned int)(cpu->getCPUNumber(), cpu->getCPUName()->getCStringNoCopy());
    */
		mach_cpu[cpu_count] = cpu->getMachProcessor();
		if (cpu_count++ > max_cpus) break;
	}
	selfHost = host_priv_self();
	if (workLoop->addEventSource(perfTimer) != kIOReturnSuccess) return false;
	currentPState = NumberOfPStates - 1;
	perfTimer->setTimeoutMS(throttleQuantum * (1 + currentPState));
	clock_get_uptime(&lastTime);
	if (!targetCPULoad) targetCPULoad = defaultTargetLoad; // % x10
	sysctl_register_oid(&sysctl__kern_cputhrottle_targetload);
	sysctl_register_oid(&sysctl__kern_cputhrottle_auto);
	setupDone = true;
	return true;
}
Пример #19
0
void REACConnection::timerFired(OSObject *target, IOTimerEventSource *sender) {
    REACConnection *proto = OSDynamicCast(REACConnection, target);
    if (NULL == proto) {
        // This should never happen
        IOLog("REACConnection::timerFired(): Internal error!\n");
        return;
    }

    UInt64            thisTimeNS;
    uint64_t          time;
    SInt64            diff;

    do {
        if (proto->isConnected()) {
            if ((proto->connectionCounter - proto->lastSeenConnectionCounter)*proto->timeoutNS >
                    (UInt64)REAC_TIMEOUT_UNTIL_DISCONNECT*1000000) {
                proto->connected = false;
                if (NULL != proto->connectionCallback) {
                    proto->connectionCallback(proto, &proto->cookieA, &proto->cookieB, NULL);
                }
            }

            proto->connectionCounter++;
        }

        if (REAC_MASTER == proto->mode) {
            proto->getAndSendSamples();
        }
        else if (REAC_SPLIT == proto->mode) {
            proto->lastSentAnnouncementCounter++;
            if (proto->lastSentAnnouncementCounter*proto->timeoutNS >= 1000000000) {
                proto->lastSentAnnouncementCounter = 0;
                proto->sendSplitAnnouncementPacket();
            }
        }

        // Calculate next time to fire, by taking the time and comparing it to the time we requested.
        clock_get_uptime(&time);
        absolutetime_to_nanoseconds(time, &thisTimeNS);
        proto->nextTime += proto->timeoutNS;
        // This next calculation must be signed
        diff = ((SInt64)proto->nextTime - (SInt64)thisTimeNS);

        if (diff < -((SInt64)proto->timeoutNS)*10) {
            // TODO After a certain amount of lost packets we probably ought to skip output packets
            IOLog("REACConnection::timerFired(): Lost the time by %lld us\n", diff/1000);
        }
    } while (diff < 0);
    sender->setTimeout((UInt64)diff);
}
Пример #20
0
void BrcmPatchRAM::stop(IOService* provider)
{
    uint64_t stop_time, nano_secs;
    clock_get_uptime(&stop_time);
    absolutetime_to_nanoseconds(stop_time - wake_time, &nano_secs);
    uint64_t milli_secs = nano_secs / 1000000;
    AlwaysLog("Time since wake %llu.%llu seconds.\n", milli_secs / 1000, milli_secs % 1000);


    DebugLog("stop\n");

    OSSafeReleaseNULL(mFirmwareStore);

    IOWorkLoop* workLoop = getWorkLoop();
    if (workLoop)
    {
        if (mTimer)
        {
            mTimer->cancelTimeout();
            workLoop->removeEventSource(mTimer);
            mTimer->release();
            mTimer = NULL;
        }
        if (mWorkSource)
        {
            workLoop->removeEventSource(mWorkSource);
            mWorkSource->release();
            mWorkSource = NULL;
            mWorkPending = 0;
        }
    }

    PMstop();

    if (mCompletionLock)
    {
        IOLockFree(mCompletionLock);
        mCompletionLock = NULL;
    }
    if (mWorkLock)
    {
        IOLockFree(mWorkLock);
        mWorkLock = NULL;
    }

    OSSafeReleaseNULL(mDevice);

    super::stop(provider);
}
Пример #21
0
/*
 * Receive hotkey event (only down) and send keyboard down and up event
 * Limits the rate of event send to HID stack, otherwise the system slow down and the sound/sun bezel lags.
 */
IOReturn WMIHIKeyboard::message( UInt32 type, IOService * provider, void * argument)
{
	if (type == kIOACPIMessageDeviceNotification)
	{
		clock_sec_t  secs, deltaSecs;
		clock_usec_t microsecs, deltaMicrosecs;
		clock_get_system_microtime(&secs,&microsecs);
		deltaSecs = secs - lastEventSecs;
		
		if (deltaSecs < 2)
		{
			deltaMicrosecs = microsecs + (1000000 * deltaSecs) - lastEventMicrosecs;
			if (deltaMicrosecs < 125000) // rate limiter to 125 ms
				return kIOReturnSuccess;
		}
		lastEventSecs =		 secs;
		lastEventMicrosecs = microsecs;
		
		{
			UInt32 code = *((UInt32 *) argument);
			
			AbsoluteTime now;
            uint64_t* pnow = reinterpret_cast<uint64_t*>(&now);
			clock_get_uptime(pnow);
			dispatchKeyboardEvent( code,
								  /*direction*/ true,
								  /*timeStamp*/ now );
			
			clock_get_uptime(pnow);
			dispatchKeyboardEvent( code,
								  /*direction*/ false,
								  /*timeStamp*/ now );
		}
	}
	return kIOReturnSuccess;
}
Пример #22
0
void net_habitue_device_SC101::handleResolvePacket(sockaddr_in *addr, mbuf_t m, size_t len, outstanding *out, void *ctx)
{
  clock_get_uptime(&_lastReply);
  
  if (mbuf_len(m) < out->len &&
      mbuf_pullup(&m, out->len) != 0)
  {
    KINFO("pullup failed");
    return;
  }
  
  KDEBUG("resolve succeeded!");
  
  psan_resolve_response_t *res = (psan_resolve_response_t *)mbuf_data(m);
  
  sockaddr_in part;
  bzero(&part, sizeof(part));
  part.sin_len = sizeof(part);
  part.sin_family = AF_INET;
  part.sin_port = htons(PSAN_PORT);
  part.sin_addr = res->ip4;
  
  OSData *partData = OSData::withBytes(&part, sizeof(part));
  if (partData)
  {
    setProperty(gSC101DevicePartitionAddressKey, partData);
    partData->release();
  }
  
  OSData *rootData = OSData::withBytes(addr, sizeof(*addr));
  if (rootData)
  {
    setProperty(gSC101DeviceRootAddressKey, rootData);
    rootData->release();
  }
  
  IODelete(out, outstanding, 1);
  
  mbuf_freem(m);

  if (!getProperty(gSC101DeviceSizeKey))
    disk();
}
Пример #23
0
void IOHIKeyboard::close(IOService * client, IOOptionBits)
{
    // kill autorepeat task
    // do this before we issue keyup for any other keys 
    // that are down.
    AbsoluteTime ts;
    clock_get_uptime(&ts);
    if (_codeToRepeat != ((unsigned)-1))
        dispatchKeyboardEvent(_codeToRepeat, false, ts);
    
    // now get rid of any other keys that might be down
    UInt32 i, maxKeys = maxKeyCodes();
    for (i=0; i<maxKeys; i++)
        if ( EVK_IS_KEYDOWN(i,_keyState) )
            dispatchKeyboardEvent(i, false, ts);

    // continue to issue zero'ed out flags changed events
    // just in case any of the flag bits were manually set
    _updateEventFlags(this, 0);

    _keyboardSpecialEvent(  this, 
                            NX_SYSDEFINED, 
                            0, 
                            NX_NOSPECIALKEY, 
                            NX_SUBTYPE_STICKYKEYS_RELEASE, 
                            _guid, 
                            0, 
                            _lastEventTime);

    bzero(_keyState, _keyStateSize);

    _keyboardEventAction        = NULL;
    _keyboardEventTarget        = 0;
    _keyboardSpecialEventAction = NULL;
    _keyboardSpecialEventTarget = 0;
    _updateEventFlagsAction     = NULL;
    _updateEventFlagsTarget     = 0;
    
    super::close(client);
}
Пример #24
0
void net_habitue_device_SC101::handleAsyncIOPacket(sockaddr_in *addr, mbuf_t m, size_t len, outstanding *out, void *ctx)
{  
  clock_get_uptime(&_lastReply);
  
  outstanding_io *io = (outstanding_io *)ctx;
  bool isWrite = (io->buffer->getDirection() == kIODirectionOut);
  UInt32 ioLen = (io->nblks * SECTOR_SIZE);
  
  IOStorageCompletion completion = io->completion;
  IOReturn status = kIOReturnError;
  IOByteCount wrote = ioLen;
  
  if (isWrite)
  {
    //KDEBUG("%p write %d %d", io, io->block, io->nblks);

    status = kIOReturnSuccess;
  }
  else
  {
    //KDEBUG("%p read %d %d", io, io->block, io->nblks);

    if (mbuf_buffer(io->buffer, 0, m, sizeof(psan_get_response_t), ioLen))
      status = kIOReturnSuccess;
    else
      KINFO("mbuf_buffer failed");
  }
  
  if (status != kIOReturnSuccess)
    KINFO("%p FAILED", io);

  completeIO(io);
  io->addr->release();
  IODelete(io, outstanding_io, 1);
  
  mbuf_freem(m);
  
  IOStorage::complete(completion, status, wrote);
}
Пример #25
0
void net_habitue_device_SC101::resolve()
{
  KDEBUG("resolving");
  clock_get_uptime(&_lastResolve);
  
  sockaddr_in addr;
  bzero(&addr, sizeof(addr));
  addr.sin_len = sizeof(addr);
  addr.sin_family = AF_INET;
  addr.sin_port = htons(PSAN_PORT);
  addr.sin_addr.s_addr = INADDR_BROADCAST;

  psan_resolve_t req;
  bzero(&req, sizeof(req));
  req.ctrl.cmd = PSAN_RESOLVE;
  req.ctrl.seq = ((net_habitue_driver_SC101 *)getProvider())->getSequenceNumber();
  strncpy(req.id, getID()->getCStringNoCopy(), sizeof(req.id));
  
  outstanding *out = IONewZero(outstanding, 1);
  out->seq = ntohs(req.ctrl.seq);
  out->len = sizeof(psan_resolve_response_t);
  out->cmd = PSAN_RESOLVE_RESPONSE;
  out->packetHandler = OSMemberFunctionCast(PacketHandler, this, &net_habitue_device_SC101::handleResolvePacket);
  out->timeoutHandler = OSMemberFunctionCast(TimeoutHandler, this, &net_habitue_device_SC101::handleResolveTimeout);
  out->target = this;
  out->timeout_ms = RESOLVE_TIMEOUT_MS;
  
  mbuf_t m;

  if (mbuf_allocpacket(MBUF_WAITOK, sizeof(psan_resolve_t), NULL, &m) != 0)
    KINFO("mbuf_allocpacket failed!"); // TODO(iwade) handle

  if (mbuf_copyback(m, 0, sizeof(req), &req, MBUF_WAITOK) != 0)
    KINFO("mbuf_copyback failed!"); // TODO(iwade) handle
  
  ((net_habitue_driver_SC101 *)getProvider())->sendPacket(&addr, m, out);
}
Пример #26
0
int
Rules::DeleteRule(UInt32 ruleId)
{
    int result = -1;
    IOLockLock(lock);
    Rule* workRule = this->root;
    while (workRule)
    {
        if(workRule->id == ruleId)
        {
            workRule->state = RuleStateDeleted;
            RemoveFromChain(workRule);

            clock_get_uptime(&lastChangedTime);
            result = 0;
            break;
        }

        workRule = workRule->next;
    }

    IOLockUnlock(lock);
    return result;
}
bool ApplePS2Keyboard::dispatchKeyboardEventWithScancode(UInt8 scanCode)
{
  //
  // Parses the given scan code, updating all necessary internal state, and
  // should a new key be detected, the key event is dispatched.
  //
  // Returns true if a key event was indeed dispatched.
  //

  unsigned int keyCode;
  bool         goingDown;
  AbsoluteTime now;

    //
    //Accidental Input Keys
    //
    switch (scanCode & ~kSC_UpBit)
    {
        case 0X01://ESC
        case 0X0f://Tab
        case 0x3a://CapsLock
        case 0x2a://Shift
        case 0x36://
        case 0x1d://Cntrl
        case 0x5b://Window
        case 0x38://Alt
        case 0x5d://ContextMenu
        case 0x45://NumLock
        case 0x1c://Enter
        case 0x0e://Backspace
        case 0x64://Arrows
        case 0x65://
        case 0x66://
        case 0x67://
            _accidentalInputKeysException = true;
            break;
        case 0x52:/* 0........9 */
        case 0x4f:
        case 0x50:
        case 0x51:
        case 0x4b:
        case 0x4c:
        case 0x4d:
        case 0x47:
        case 0x48:
        case 0x49:
        case 0x53:/* ". / * - + ENTER" */
        case 0x63:
        case 0x37:
        case 0x4a:
        case 0x4e:
        case 0x62:
            _keyPadKeys = true;
            break;
        default:
            break;
    }

  //
  // See if this scan code introduces an extended key sequence.  If so, note
  // it and then return.  Next time we get a key we'll finish the sequence.
  //

  if (scanCode == kSC_Extend)
  {
    _extendCount = 1;
    return false;
  }

  //
  // See if this scan code introduces an extended key sequence for the Pause
  // Key.  If so, note it and then return.  The next time we get a key, drop
  // it.  The next key we get after that finishes the Pause Key sequence.
  //
  // The sequence actually sent to us by the keyboard for the Pause Key is:
  //
  // 1. E1  Extended Sequence for Pause Key
  // 2. 1D  Useless Data, with Up Bit Cleared
  // 3. 45  Pause Key, with Up Bit Cleared
  // 4. E1  Extended Sequence for Pause Key
  // 5. 9D  Useless Data, with Up Bit Set
  // 6. C5  Pause Key, with Up Bit Set
  //
  // The reason items 4 through 6 are sent with the Pause Key is because the
  // keyboard hardware never generates a release code for the Pause Key and
  // the designers are being smart about it.  The sequence above translates
  // to this parser as two separate events, as it should be -- one down key
  // event and one up key event (for the Pause Key).
  //

  if (scanCode == kSC_Pause)
  {
    _extendCount = 2;
    return false;
  }

  //
  // Convert the scan code into a key code.
  //

  if (_extendCount == 0)
  {
    keyCode = scanCode & ~kSC_UpBit;

    // from "The Undocumented PC" chapter 8, The Keyboard System some
    // keyboard scan codes are single byte, some are multi-byte
    // 3023805:  I want to swap alt and windows, since the windows
    // key is located where the alt/option key is on an Apple PowerBook
    // or USB keyboard, and the alt key is where the Apple/Command
    // key is on the PB or USB keyboard. Left alt is a single scan
    // code byte, right alt is a double scan code byte. Left and
    // right windows keys are double bytes.  This is all set by an
    // entry in Info.plist for ApplePS2Keyboard.kext
    switch (keyCode)
    {
      case 0x3A: 
	if (emacsMode == true) {
	  keyCode = 0x60; 
	}
	break;			// caps lock becomes ctrl
      case 0x38: 
	if (macintoshMode == true) {
	  keyCode = 0x70; 
	}
	break;		// left alt becomes left windows
    }
  }
  else
  {
    _extendCount--;
    if (_extendCount)  return false;
      
      
    //
    // Convert certain extended codes on the PC keyboard into single scancodes.
    // Refer to the conversion table in defaultKeymapOfLength.
    //

    switch (scanCode & ~kSC_UpBit)
    {
      // scancodes from running showkey -s (under Linux) for extra keys on keyboard
      case 0x30: keyCode = 0x7d; break;		   // E030 = volume up
      case 0x2e: keyCode = 0x7e; break;		   // E02E = volume down
      case 0x20: keyCode = 0x7f; break;		   // E020 = volume mute

      case 0x5e: keyCode = 0x7c; break;            // E05E = power
      case 0x5f:                                   // E05F = sleep
        keyCode = 0;
        if (!(scanCode & kSC_UpBit))
        {
          IOPMrootDomain * rootDomain = getPMRootDomain();
          if (rootDomain)
            rootDomain->receivePowerNotification( kIOPMSleepNow );
        }
        break;

      case 0x1D: keyCode = 0x60; break;            // ctrl
      case 0x38:             			   // right alt may become right command
	if (macintoshMode == true) {
	  keyCode = 0x71; 
	} else {
	  keyCode = 0x61;			  
	}
	break;
      case 0x1C: keyCode = 0x62; break;            // enter
      case 0x35: keyCode = 0x63; break;            // /
      case 0x48: keyCode = 0x64; break;            // up arrow
      case 0x50: keyCode = 0x65; break;            // down arrow
      case 0x4B: keyCode = 0x66; break;            // left arrow
      case 0x4D: keyCode = 0x67; break;            // right arrow
      case 0x52: keyCode = 0x68; break;            // insert
      case 0x53: keyCode = 0x69; break;            // delete
      case 0x49: keyCode = 0x6A; break;            // page up
      case 0x51: keyCode = 0x6B; break;            // page down
      case 0x47: keyCode = 0x6C; break;            // home
      case 0x4F: keyCode = 0x6D; break;            // end
      case 0x37: keyCode = 0x6E; break;            // PrintScreen
      case 0x45: keyCode = 0x6F; break;            // Pause
      case 0x5B: 				   // left Windows key may become alt
	if (macintoshMode == true) {
	  keyCode = 0x38; 			   // alt 
	} else {
	  keyCode = 0x70;			   // Left command
	}
	break;
      case 0x5d:  				   //right context click key becomes alt (right Windows key may become alt)
	if (macintoshMode == true) {
	  keyCode = 0x61; 			   // alt
	} else {
	  keyCode = 0x71; 			   // Right command
	}
	break;
      //case 0x5D: keyCode = 0x72; break;            // Application
      case 0x2A:             // header or trailer for PrintScreen
      default: return false;
    }
  }

  if (keyCode == 0)  return false;

  //
  // Update our key bit vector, which maintains the up/down status of all keys.
  //

  goingDown = !(scanCode & kSC_UpBit);

  if (goingDown)
  {
    //
    // Verify that this is not an autorepeated key -- discard it if it is.
    //

    if (KBV_IS_KEYDOWN(keyCode, _keyBitVector))  return false;

    KBV_KEYDOWN(keyCode, _keyBitVector);
  }
  else
  {
    KBV_KEYUP(keyCode, _keyBitVector);
  }

  //
  // We have a valid key event -- dispatch it to our superclass.
  //
    
  //IOLog("Keyboard key Code %x %d\n",keyCode,keyCode);
  //Sending PS2 Notification to Mouse/Touchpad
    if(goingDown)
    if(!_accidentalInputKeysException && !_keyPadKeys)
        _device->dispatchPS2Notification(kPS2C_DisableTouchpad);
    
  clock_get_uptime((uint64_t *)&now);

    //NUM LOCK and Print Screen Fix
    if(keyCode == 0x45 && goingDown)
    {
        setNumLockFeedback(_numKeypadLocked);
        _numKeypadLocked = !_numKeypadLocked;

    }
    else if(keyCode == 0x6e && goingDown)//Print Screen Simulation
    {
        dispatchKeyboardEvent( 55,
                              /*direction*/ true,
                              /*timeStamp*/ now );
        clock_get_uptime((uint64_t *)&now);
        dispatchKeyboardEvent( 56,
                              /*direction*/ true,
                              /*timeStamp*/ now );
        clock_get_uptime((uint64_t *)&now);
        dispatchKeyboardEvent( 21,
                              /*direction*/ true,
                              /*timeStamp*/ now );
        clock_get_uptime((uint64_t *)&now);
        dispatchKeyboardEvent( 21,
                              /*direction*/ false,
                              /*timeStamp*/ now );
        clock_get_uptime((uint64_t *)&now);
        dispatchKeyboardEvent( 56,
                              /*direction*/ false,
                              /*timeStamp*/ now );
        clock_get_uptime((uint64_t *)&now);
        dispatchKeyboardEvent( 55,
                              /*direction*/ false,
                              /*timeStamp*/ now );
    }
    else if(!((keyCode == 0x45 || keyCode == 0x6e) ||//NumLock & PrintScreen
            //Keypad Buttons
            ((keyCode == 0x52 || keyCode == 0x53 || keyCode == 0x62 || keyCode == 0x4f || keyCode == 0x50 ||
            keyCode == 0x51 || keyCode == 0x4b || keyCode == 0x4c || keyCode == 0x4d || keyCode == 0x47 ||
            keyCode == 0x48 || keyCode == 0x49 || keyCode == 0x63 || keyCode == 0x37 || keyCode == 0x4a ||
            keyCode == 0x4e)  && _numKeypadLocked)))
        dispatchKeyboardEvent( PS2ToADBMap[keyCode],  //Dispatch of Keyboard Events
           /*direction*/ goingDown,
           /*timeStamp*/ now );

   
    
    //PS2 Notification
    if(!goingDown && !_accidentalInputKeysException && !_keyPadKeys)
        _device->dispatchPS2Notification(kPS2C_EnableTouchpad);
    
    if(_accidentalInputKeysException)
        _accidentalInputKeysException = false;
    if(_keyPadKeys)
        _keyPadKeys = false;

        /*if(keyCode != 0x2a && keyCode != 0x36 && keyCode != 0x1d && keyCode != 0x60 &&
           keyCode != 0x70 && keyCode != 0x71 && keyCode != 0x38 && keyCode != 0x61 &&
           keyCode != 0x72 && keyCode != 0x0f && keyCode != 0x45 && keyCode != 0x6e && !(keyCode>0x3f && keyCode<0x44))*/
    
  return true;
}
bool ApplePS2Keyboard::dispatchKeyboardEventWithScancode(UInt8 scanCode)
{
  //
  // Parses the given scan code, updating all necessary internal state, and
  // should a new key be detected, the key event is dispatched.
  //
  // Returns true if a key event was indeed dispatched.
  //

  unsigned int keyCode;
  bool         goingDown;
  AbsoluteTime now;

  //
  // See if this scan code introduces an extended key sequence.  If so, note
  // it and then return.  Next time we get a key we'll finish the sequence.
  //

  if (scanCode == kSC_Extend)
  {
    _extendCount = 1;
    return false;
  }

  //
  // See if this scan code introduces an extended key sequence for the Pause
  // Key.  If so, note it and then return.  The next time we get a key, drop
  // it.  The next key we get after that finishes the Pause Key sequence.
  //
  // The sequence actually sent to us by the keyboard for the Pause Key is:
  //
  // 1. E1  Extended Sequence for Pause Key
  // 2. 1D  Useless Data, with Up Bit Cleared
  // 3. 45  Pause Key, with Up Bit Cleared
  // 4. E1  Extended Sequence for Pause Key
  // 5. 9D  Useless Data, with Up Bit Set
  // 6. C5  Pause Key, with Up Bit Set
  //
  // The reason items 4 through 6 are sent with the Pause Key is because the
  // keyboard hardware never generates a release code for the Pause Key and
  // the designers are being smart about it.  The sequence above translates
  // to this parser as two separate events, as it should be -- one down key
  // event and one up key event (for the Pause Key).
  //

  if (scanCode == kSC_Pause)
  {
    _extendCount = 2;
    return false;
  }

  //
  // Convert the scan code into a key code.
  //

	//IOLog("key 0x%x scan 0x%x ex %d\n",(scanCode & ~kSC_UpBit),scanCode,_extendCount);

  if (_extendCount == 0)
  {
    keyCode = scanCode & ~kSC_UpBit;

    // from "The Undocumented PC" chapter 8, The Keyboard System some
    // keyboard scan codes are single byte, some are multi-byte
    // 3023805:  I want to swap alt and windows, since the windows
    // key is located where the alt/option key is on an Apple PowerBook
    // or USB keyboard, and the alt key is where the Apple/Command
    // key is on the PB or USB keyboard. Left alt is a single scan
    // code byte, right alt is a double scan code byte. Left and
    // right windows keys are double bytes.  This is all set by an
    // entry in Info.plist for ApplePS2Keyboard.kext
    switch (keyCode)
    {
      case 0x3A: 
	if (emacsMode == true) {
	  keyCode = 0x60; 
	}
	break;			// caps lock becomes ctrl
      case 0x38: 
	if (macintoshMode == true) {
	  keyCode = 0x70; 
	}
	break;		// left alt becomes left windows
/* CFR: Nope...this is the code for =+
		case 0xd: // ²		
		if(scanCode==0xd) 
		{
			_extendCount=1; dispatchKeyboardEventWithScancode(0x5b);
			dispatchKeyboardEventWithScancode(0x56);
		}
		else
		{
			_extendCount=1; dispatchKeyboardEventWithScancode(0xdb);
			dispatchKeyboardEventWithScancode(0xd6);
		}
		return true;
*/
// CFR		case 0x56: keyCode = 0x29; break;            // <
// CFR		case 0x1a: keyCode = 0xd; break;            // +
// CFR		case 0x28: keyCode = 0x1a; break;            // ¼ »
// CFR		case 0x2b: keyCode = 0x28; break;            // ~
// CFR		case 0x29: keyCode = 0x2b; break;            
		case 0x8:
		if (keyi==true)	
		{
			if(scanCode==0x8) 
			{
				dispatchKeyboardEventWithScancode(0x2a);
			}
			else
			{
				dispatchKeyboardEventWithScancode(0xaa);
			}
			keyCode = 0x9;
		}
		break;
		case 0xb: 
		if (keyi==true)	
		{
			if(scanCode==0xb) 
			{
				dispatchKeyboardEventWithScancode(0x2a);
			}
			else
			{
				dispatchKeyboardEventWithScancode(0xaa);
			}
			keyCode = 0xa;
		}
		break;
		case 0x12: 
		if (keyi==true)	keyCode = 0x4;
		break;
		case 0x4: 
		if (keyi==true)	keyCode = 0x5;
		break; 
		case 0x5:
		if (keyi==true)	keyCode = 0xc;
		break;

    }
  }
  else
  {
    _extendCount--;
    if (_extendCount)  return false;

    //
    // Convert certain extended codes on the PC keyboard into single scancodes.
    // Refer to the conversion table in defaultKeymapOfLength.
    //

    switch (scanCode & ~kSC_UpBit)
    {	  	  

	  case 0x33: // Û
	  if(scanCode==0x33) 
		{
			dispatchKeyboardEventWithScancode(0x38);
			dispatchKeyboardEventWithScancode(0x10);
		}
		else
		{
			dispatchKeyboardEventWithScancode(0xb8);
			dispatchKeyboardEventWithScancode(0x90);
		}
		return true;
	  case 0x34: // $ = F12 - press and hold to eject cd rom
	  if (scanCode==0x34) 
	  {
		dispatchKeyboardEventWithScancode(0x58); 
		//dispatchKeyboardEventWithScancode(0x58); 
	  }
	  else 
	  {
		dispatchKeyboardEventWithScancode(0xd8); 
		//dispatchKeyboardEventWithScancode(0x58); 
	  }
	  return true;

	   
		 // scancodes from running showkey -s (under Linux) for extra keys on keyboard
      case 0x30: keyCode = 0x7d; break;		   // E030 = volume up
      case 0x2e: keyCode = 0x7e; break;		   // E02E = volume down
      case 0x20: keyCode = 0x7f; break;		   // E020 = volume mute

      case 0x5e: keyCode = 0x7c; break;            // E05E = power
      case 0x5f:                                   // E05F = sleep
        keyCode = 0;
        if (!(scanCode & kSC_UpBit))
        {
          IOPMrootDomain * rootDomain = getPMRootDomain();
          if (rootDomain)
            rootDomain->receivePowerNotification( kIOPMSleepNow );
        }
        break;

      case 0x1D: keyCode = 0x60; break;            // ctrl
      case 0x38:             			   // right alt may become right command
	if (macintoshMode == true) {
	  keyCode = 0x71; 
	} else {
	  keyCode = 0x61;			  
	}
	break;

      case 0x1C: keyCode = 0x62; break;            // enter
      case 0x35: keyCode = 0x63; break;            // /
      case 0x48: keyCode = 0x64; break;            // up arrow
      case 0x50: keyCode = 0x65; break;            // down arrow
      case 0x4B: keyCode = 0x66; break;            // left arrow
      case 0x4D: keyCode = 0x67; break;            // right arrow
      case 0x52: keyCode = 0x68; break;            // insert 0x68
      case 0x53: keyCode = 0x69; break;            // delete
      case 0x49: keyCode = 0x6A; break;            // page up
      case 0x51: keyCode = 0x6B; break;            // page down
      case 0x47: keyCode = 0x6C; break;            // home
      case 0x4F: keyCode = 0x6D; break;            // end
      case 0x37: //keyCode = 0x6E; break;            // PrintScreen
	  if(scanCode==0x37) 
		{
			dispatchKeyboardEventWithScancode(0x1d);
			dispatchKeyboardEventWithScancode(0x38);
			dispatchKeyboardEventWithScancode(0x2a);
			dispatchKeyboardEventWithScancode(0x5); 
		}
		else
		{
			dispatchKeyboardEventWithScancode(0x9d);
			dispatchKeyboardEventWithScancode(0xb8);
			dispatchKeyboardEventWithScancode(0xaa);
			dispatchKeyboardEventWithScancode(0x85); 
		}
		return true;
      case 0x45: //keyCode = 0x6F; break;            // Pause
       if(scanCode==0x45) 
		{
			dispatchKeyboardEventWithScancode(0x1d);
			dispatchKeyboardEventWithScancode(0x2e);
		}
		else
		{
			dispatchKeyboardEventWithScancode(0x9d);
			dispatchKeyboardEventWithScancode(0xae);
		}
		return true;
	  case 0x5B: 				   // left Windows key may become alt
	if (macintoshMode == true) {
	  keyCode = 0x38; 
	   if (scanCode==0x5B) keyi=true; else keyi=false;			   // alt 
	} else {
	  keyCode = 0x70;			   // Left command
	}
	break;
      case 0x5c:  				   // right Windows key may become alt
	if (macintoshMode == true) {
	  keyCode = 0x61; 			   // alt
	} else {
	  keyCode = 0x71; 			   // Right command
	}
	break;
      case 0x5D: keyCode = 0x38; if (scanCode==0x5D) keyi=true; else keyi=false; break;            // Application 0x72
      case 0x2A:             // header or trailer for PrintScreen
      default: return false;
    }
  }

	//IOLog("keycode 0x%x\n",keyCode);


  if (keyCode == 0)  return false;

  //
  // Update our key bit vector, which maintains the up/down status of all keys.
  //

  goingDown = !(scanCode & kSC_UpBit);

  if (goingDown)
  {
    //
    // Verify that this is not an autorepeated key -- discard it if it is.
    //

    if (KBV_IS_KEYDOWN(keyCode, _keyBitVector))  return false;

    KBV_KEYDOWN(keyCode, _keyBitVector);
  }
  else
  {
    KBV_KEYUP(keyCode, _keyBitVector);
  }

  //
  // We have a valid key event -- dispatch it to our superclass.
  //

  clock_get_uptime((uint64_t *)&now);

  dispatchKeyboardEvent( PS2ToADBMap[keyCode],
           /*direction*/ goingDown,
           /*timeStamp*/ now );

  return true;
}
Пример #29
0
void ApplePS2Mouse::dispatchRelativePointerEventWithPacket(UInt8 * packet,
                                                           UInt32  packetSize)
{
  //
  // Process the three byte mouse packet that was retreived from the mouse.
  // The format of the bytes is as follows:
  //
  // 7  6  5  4  3  2  1  0
  // YO XO YS XS 1  M  R  L
  // X7 X6 X5 X4 X3 X3 X1 X0
  // Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
  // Z7 Z6 Z5 Z4 Z3 Z2 Z1 Z0 <- fourth byte returned only for Intellimouse type
  //
  //  0  0 B5 B4 Z3 Z2 Z1 Z0 <- fourth byte for 5-button wheel mouse mode
  //

  UInt32       buttons = 0;
  SInt32       dx;
  SInt32       dy;
  SInt16       dz = 0;
  AbsoluteTime now;

  if ( (packet[0] & 0x1) ) buttons |= 0x1;  // left button   (bit 0 in packet)
  if ( (packet[0] & 0x2) ) buttons |= 0x2;  // right button  (bit 1 in packet)
  if ( (packet[0] & 0x4) ) buttons |= 0x4;  // middle button (bit 2 in packet)

  dx = ((packet[0] & 0x10) ? 0xffffff00 : 0 ) | packet[1];
  dy = -(((packet[0] & 0x20) ? 0xffffff00 : 0 ) | packet[2]);

  clock_get_uptime((uint64_t *)&now);

  if ( packetSize > 3 )
  {
    // Pull out fourth and fifth buttons.
    if (_type == kMouseTypeIntellimouseExplorer)
    {
      if (packet[3] & 0x10) buttons |= 0x8;  // fourth button (bit 4 in packet)
      if (packet[3] & 0x20) buttons |= 0x10; // fifth button  (bit 5 in packet)
    }
    dispatchRelativePointerEvent(dx, dy, buttons, now);

    //
    // We treat the 4th byte in the packet as a 8-bit signed Z value.
    // There are mice that can report only 4-bits for the Z data, and
    // use two of the remaining 4 bits for buttons 4 and 5. To enable
    // the 5-button mouse mode, the command sequence should be:
    //
    // setMouseSampleRate(200);
    // setMouseSampleRate(200);
    // setMouseSampleRate(80);
    //
    // Those devices will return 0x04 for the device ID.
    //
    // %%KCD - As it turns out, the valid range for scroll data from
    // PS2 mice is -8 to +7, thus the upper four bits are just a sign
    // bit.  If we just sign extend the lower four bits, the scroll
    // calculation works for normal scrollwheel mice and five button mice.
    dz = (SInt16)(((SInt8)(packet[3] << 4)) >> 4);
    if ( dz )
    {
      //
      // The Z counter is negative on an upwards scroll (away from the user),
      // and positive when scrolling downwards. Invert this before passing to
      // HID/CG.
      //
      dispatchScrollWheelEvent(-dz, 0, 0, now);
    }
  }
  else
  {
void ApplePS2Keyboard::receiveMouseTouchpadNotifications(UInt32 data)
{
    AbsoluteTime now;
    
    clock_get_uptime((uint64_t *)&now);
    
    switch (data) {
        
        
        case kPS2C_SwipeLeft:// cmd + [
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 33,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 33,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            break;
        case kPS2C_SwipeRight://cmd + ]
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 30,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 30,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            break;
        case kPS2C_ZoomPlus://cmd + +
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 69,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 69,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            break;
        case kPS2C_ZoomMinus://cmd + -
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 78,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 78,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            break;
        case kPS2C_SwipeDown://cmd + tab
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 48,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 48,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            break;
        case  kPS2C_SwipeUp://Launchpad
            dispatchKeyboardEvent( 131,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 131,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            break;
        case kPS2C_RotateLeft://cmd + L
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 37,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            //clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 37,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            //clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );

            break;
        case kPS2C_RotateRight://cmd + R
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 15,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            // clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 15,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            //clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );

            break;
            case kPS2C_TwoFingersPress://cmd + 0
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 29,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 29,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            break;
            case kPS2C_ReleaseKey://Just to release cmd after sleep and after swipe down
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            
            break;
          
        //If Command Key was modified at Modifier keys of Keyboard pane then we set command key
        case kCommandKeyPos_0:
            _commandKey = 55;
            break;
        case kCommandKeyPos_1:
            _commandKey = 58;
            break;
        case kCommandKeyPos_2:
            _commandKey = 59;
            break;
        case kCommandKeyPos_3:
            _commandKey = 57;
            break;
            
        //Three Finger Swipe Action Options
        case kPS2C_SwipeAction_1://Switch Applications Switch Tab + cmd
            dispatchKeyboardEvent( _commandKey,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 48,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 48,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            break;
        case kPS2C_SwipeAction_2://Launchpad
            dispatchKeyboardEvent( 131,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 131,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );

            break;
        case kPS2C_SwipeAction_3://Dashboard & Switching Desktop Left Cntrl + Arrow
            dispatchKeyboardEvent( 59,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 123,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 123,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 59,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            break;
            
        case kPS2C_SwipeAction_4://Switching Desktop Left Cntrl + Right Arrow
            dispatchKeyboardEvent( 59,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 124,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 124,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 59,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );

            break;
            

        case kPS2C_SwipeAction_5://Show Application Windows Control + Down Arrow
            dispatchKeyboardEvent( 59,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 125,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 125,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 59,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            

            break;
        case kPS2C_SwipeAction_6://Mission Control
            dispatchKeyboardEvent( 160,
                                  /*direction*/ true,
                                  /*timeStamp*/ now );
            
            clock_get_uptime((uint64_t *)&now);
            dispatchKeyboardEvent( 160,
                                  /*direction*/ false,
                                  /*timeStamp*/ now );
            

            break;
            
            //For Future
        case kPS2C_SwipeAction_7:
            break;
        case kPS2C_SwipeAction_8:
            break;
        case kPS2C_SwipeAction_9:
            break;
        case kPS2C_SwipeAction_10:
            break;
            
        case kPS2C_NumLock:
            //Invoking Num Lock LED
            setNumLockFeedback(_numKeypadLocked);
            _numKeypadLocked = !_numKeypadLocked;
            break;
            
        default:
            break;
    }

    
    return;
}