Exemple #1
0
//------------------------------------------------------------------------------
//
//  Function:  OEMSetAlarmTime
//
//  This function is called by the kernel to set the real-time clock alarm.
//
BOOL
OEMSetAlarmTime(
    SYSTEMTIME *pSystemTime
    ) 
{
    BOOL rc = FALSE;

    OALMSG(OAL_TIMER && OAL_FUNC, (L"+OEMSetAlarmTime(%s)\r\n", SystemTimeToString(pSystemTime)));

    if (s_rtc.initialized)
        {
        // Save time to global structure
        EnterCriticalSection(&s_rtc.cs);

        if (g_ResumeRTC)
    		{
            OALIoCtlHalRtcTime(0, NULL, 0, NULL, 0, NULL);
            g_ResumeRTC = FALSE;
	    	}

        // Round to seconds
        pSystemTime->wMilliseconds = 0;

        // Convert to filetime
        if (NKSystemTimeToFileTime(pSystemTime, (FILETIME*)&s_rtc.alarmFiletime))
            {
            UCHAR   status;
            UCHAR   bcdTime[6];

            //  Adjust alarm time by secure offset
            s_rtc.alarmFiletime  = s_rtc.alarmFiletime - s_rtc.baseOffset;

            //  Convert to BCD time format
            FiletimeToHWTime( s_rtc.alarmFiletime, bcdTime );

            //  Write alarm registers
            TWLWriteByteReg(s_rtc.hTWL, TWL_ALARM_YEARS_REG, bcdTime[5]);
            TWLWriteByteReg(s_rtc.hTWL, TWL_ALARM_MONTHS_REG, bcdTime[4]);
            TWLWriteByteReg(s_rtc.hTWL, TWL_ALARM_DAYS_REG, bcdTime[3]);
            TWLWriteByteReg(s_rtc.hTWL, TWL_ALARM_HOURS_REG, bcdTime[2]);
            TWLWriteByteReg(s_rtc.hTWL, TWL_ALARM_MINUTES_REG, bcdTime[1]);
            TWLWriteByteReg(s_rtc.hTWL, TWL_ALARM_SECONDS_REG, bcdTime[0]);

            //  Set toggle bit to latch alarm registers
            TWLReadByteReg(s_rtc.hTWL, TWL_RTC_CTRL_REG, &status);

            status |= TWL_RTC_CTRL_RUN | TWL_RTC_CTRL_GET_TIME;
            TWLWriteByteReg(s_rtc.hTWL, TWL_RTC_CTRL_REG, status);

            // Done
            rc = TRUE;
            }

        LeaveCriticalSection(&s_rtc.cs);
        }
    
    return rc;
}
Exemple #2
0
//------------------------------------------------------------------------------
//
//  Function:  OEMSetRealTime
//
//  This function is called by the kernel to set the real-time clock. A secure
//  timer requirement means that the time change is noted in baseOffset and
//  used to compute the time delta from the non-alterable RTC in T2
//
BOOL
OEMSetRealTime(
    SYSTEMTIME *pSystemTime
    ) 
{
    BOOL        rc = FALSE;
    ULONGLONG   fileTime;
    DWORD       tickDelta;

    OALMSG(OAL_TIMER && OAL_FUNC, (L"+OEMSetRealTime(%s)\r\n", SystemTimeToString(pSystemTime)));

    if (s_rtc.initialized)
        {
        // Save time to global structure
        EnterCriticalSection(&s_rtc.cs);

        if (g_ResumeRTC)
    		{
            OALIoCtlHalRtcTime(0, NULL, 0, NULL, 0, NULL);
            g_ResumeRTC = FALSE;
	    	}
		
        // Round to seconds
        pSystemTime->wMilliseconds = 0;

        // Convert to filetime
        if (NKSystemTimeToFileTime(pSystemTime, (FILETIME*)&fileTime))
            {
            // Compute the tick delta (indicates the time in the RTC)
            tickDelta = OEMGetTickCount() - s_rtc.baseTickCount;
            
            // Update all the parameters
            s_rtc.baseFiletime  = s_rtc.baseFiletime + ((ULONGLONG)tickDelta)*10000;
            s_rtc.baseOffset    = fileTime - s_rtc.baseFiletime;
            s_rtc.baseTickCount = OEMGetTickCount();

            //  Save off base offset to the backup regs
            WriteBaseOffset( &s_rtc.baseOffset ); 

            // Done
            rc = TRUE;
            }

        LeaveCriticalSection(&s_rtc.cs);
        }
    
    OALMSG(OAL_TIMER && OAL_FUNC, (L"-OEMSetRealTime\r\n"));

    return rc;
}
Exemple #3
0
//------------------------------------------------------------------------------
//
//  Function:  OEMGetRealTime
//
//  This function is called by the kernel to retrieve the time from
//  the real-time clock.
//
BOOL
OEMGetRealTime(
    SYSTEMTIME *pSystemTime
    ) 
{
    DWORD       delta;
    ULONGLONG   time;

    OALMSG(OAL_TIMER && OAL_FUNC, (L"+OEMGetRealTime()\r\n"));

    if (!s_rtc.initialized)
        {
        // Return default time if RTC isn't initialized
        pSystemTime->wYear   = RTC_BASE_YEAR_MIN;
        pSystemTime->wMonth  = 1;
        pSystemTime->wDay    = 1;
        pSystemTime->wHour   = 0;
        pSystemTime->wMinute = 0;
        pSystemTime->wSecond = 0;
        pSystemTime->wDayOfWeek    = 0;
        pSystemTime->wMilliseconds = 0;
        }
    else
        {
        EnterCriticalSection(&s_rtc.cs);
        if (g_ResumeRTC)
    		{
            // suspend/resume occured, sync RTC
            OALIoCtlHalRtcTime(0, NULL, 0, NULL, 0, NULL);
            g_ResumeRTC = FALSE;
	    	}
        delta = OEMGetTickCount() - s_rtc.baseTickCount;
        time = s_rtc.baseFiletime + s_rtc.baseOffset + ((ULONGLONG)delta) * 10000;
        NKFileTimeToSystemTime((FILETIME*)&time, pSystemTime);
        pSystemTime->wMilliseconds = 0;
        LeaveCriticalSection(&s_rtc.cs);
        }

    OALMSG(OAL_TIMER && OAL_FUNC, (L"-OEMGetRealTime() = %s\r\n", SystemTimeToString(pSystemTime)));

    return TRUE;
}
Exemple #4
0
VOID
DumpAfdConnection(
    PAFD_CONNECTION Connection,
    DWORD ActualAddress
)

/*++

Routine Description:

    Dumps the specified AFD_CONNECTION structures.

Arguments:

    Connection - Points to the AFD_CONNECTION structure to dump.

    ActualAddress - The actual address where the structure resides on the
        debugee.

Return Value:

    None.

--*/

{

    UCHAR address[MAX_TRANSPORT_ADDR];
    ULONG result;

    dprintf(
        "AFD_CONNECTION @ %08lx:\n",
        ActualAddress
    );

    dprintf(
        "    Type                         = %04X (%s)\n",
        Connection->Type,
        StructureTypeToString( Connection->Type )
    );

    dprintf(
        "    ReferenceCount               = %d\n",
        Connection->ReferenceCount
    );

    dprintf(
        "    State                        = %08X (%s)\n",
        Connection->State,
        ConnectionStateToString( Connection->State )
    );

    dprintf(
        "    Handle                       = %08lx\n",
        Connection->Handle
    );

    dprintf(
        "    FileObject                   = %08lx\n",
        Connection->FileObject
    );

    dprintf(
        "    ConnectTime                  = %s\n",
        SystemTimeToString( Connection->ConnectTime )
    );

    if( Connection->TdiBufferring )
    {
        dprintf(
            "    ReceiveBytesIndicated        = %s\n",
            LongLongToString( Connection->Common.Bufferring.ReceiveBytesIndicated.QuadPart )
        );

        dprintf(
            "    ReceiveBytesTaken            = %s\n",
            LongLongToString( Connection->Common.Bufferring.ReceiveBytesTaken.QuadPart )
        );

        dprintf(
            "    ReceiveBytesOutstanding      = %s\n",
            LongLongToString( Connection->Common.Bufferring.ReceiveBytesOutstanding.QuadPart )
        );

        dprintf(
            "    ReceiveExpeditedBytesIndicated   = %s\n",
            LongLongToString( Connection->Common.Bufferring.ReceiveExpeditedBytesIndicated.QuadPart )
        );

        dprintf(
            "    ReceiveExpeditedBytesTaken       = %s\n",
            LongLongToString( Connection->Common.Bufferring.ReceiveExpeditedBytesTaken.QuadPart )
        );

        dprintf(
            "    ReceiveExpeditedBytesOutstanding = %s\n",
            LongLongToString( Connection->Common.Bufferring.ReceiveExpeditedBytesOutstanding.QuadPart )
        );

        dprintf(
            "    NonBlockingSendPossible      = %s\n",
            BooleanToString( Connection->Common.Bufferring.NonBlockingSendPossible )
        );

        dprintf(
            "    ZeroByteReceiveIndicated     = %s\n",
            BooleanToString( Connection->Common.Bufferring.ZeroByteReceiveIndicated )
        );
    }
    else
    {
        if( IS_LIST_EMPTY(
                    ActualAddress,
                    Connection,
                    Common.NonBufferring.ReceiveIrpListHead ) ) {

            dprintf(
                "    ReceiveIrpListHead           = EMPTY\n"
            );

        } else {

            dprintf(
                "    ReceiveIrpListHead           @ %08lx\n",
                ACTUAL_ADDRESS(
                    ActualAddress,
                    Connection,
                    Common.NonBufferring.ReceiveIrpListHead
                )
            );

        }

        if( IS_LIST_EMPTY(
                    ActualAddress,
                    Connection,
                    Common.NonBufferring.ReceiveBufferListHead ) ) {

            dprintf(
                "    ReceiveBufferListHead        = EMPTY\n"
            );

        } else {

            dprintf(
                "    ReceiveBufferListHead        @ %08lx\n",
                ACTUAL_ADDRESS(
                    ActualAddress,
                    Connection,
                    Common.NonBufferring.ReceiveBufferListHead
                )
            );

        }

        if( IS_LIST_EMPTY(
                    ActualAddress,
                    Connection,
                    Common.NonBufferring.SendIrpListHead ) ) {

            dprintf(
                "    SendIrpListHead              = EMPTY\n"
            );

        } else {

            dprintf(
                "    SendIrpListHead              @ %08lx\n",
                ACTUAL_ADDRESS(
                    ActualAddress,
                    Connection,
                    Common.NonBufferring.SendIrpListHead
                )
            );

        }

        dprintf(
            "    BufferredReceiveBytes        = %lu\n",
            Connection->Common.NonBufferring.BufferredReceiveBytes
        );

        dprintf(
            "    BufferredExpeditedBytes      = %lu\n",
            Connection->Common.NonBufferring.BufferredExpeditedBytes
        );

        dprintf(
            "    BufferredReceiveCount        = %u\n",
            Connection->Common.NonBufferring.BufferredReceiveCount
        );

        dprintf(
            "    BufferredExpeditedCount      = %u\n",
            Connection->Common.NonBufferring.BufferredExpeditedCount
        );

        dprintf(
            "    ReceiveBytesInTransport      = %lu\n",
            Connection->Common.NonBufferring.ReceiveBytesInTransport
        );

        dprintf(
            "    BufferredSendBytes           = %lu\n",
            Connection->Common.NonBufferring.BufferredSendBytes
        );

        dprintf(
            "    ReceiveCountInTransport      = %u\n",
            Connection->Common.NonBufferring.ReceiveCountInTransport
        );

        dprintf(
            "    BufferredSendCount           = %u\n",
            Connection->Common.NonBufferring.BufferredSendCount
        );

        dprintf(
            "    DisconnectIrp                = %08lx\n",
            Connection->Common.NonBufferring.DisconnectIrp
        );
    }

    dprintf(
        "    Endpoint                     = %08lx\n",
        Connection->Endpoint
    );

    dprintf(
        "    MaxBufferredReceiveBytes     = %lu\n",
        Connection->MaxBufferredReceiveBytes
    );

    dprintf(
        "    MaxBufferredSendBytes        = %lu\n",
        Connection->MaxBufferredSendBytes
    );

    dprintf(
        "    MaxBufferredReceiveCount     = %u\n",
        Connection->MaxBufferredReceiveCount
    );

    dprintf(
        "    MaxBufferredSendCount        = %u\n",
        Connection->MaxBufferredSendCount
    );

    dprintf(
        "    ConnectDataBuffers           = %08lx\n",
        Connection->ConnectDataBuffers
    );

    dprintf(
        "    OwningProcess                = %08lx\n",
        Connection->OwningProcess
    );

    dprintf(
        "    DeviceObject                 = %08lx\n",
        Connection->DeviceObject
    );

    dprintf(
        "    RemoteAddress                = %08lx\n",
        Connection->RemoteAddress
    );

    dprintf(
        "    RemoteAddressLength          = %lu\n",
        Connection->RemoteAddressLength
    );

    if( Connection->RemoteAddressLength <= sizeof(address) &&
            Connection->RemoteAddress != NULL ) {

        if( ReadMemory(
                    (DWORD)Connection->RemoteAddress,
                    address,
                    sizeof(address),
                    &result
                ) ) {

            DumpTransportAddress(
                "    ",
                (PTRANSPORT_ADDRESS)address,
                (DWORD)Connection->RemoteAddress
            );

        }

    }

    dprintf(
        "    DisconnectIndicated          = %s\n",
        BooleanToString( Connection->DisconnectIndicated )
    );

    dprintf(
        "    AbortIndicated               = %s\n",
        BooleanToString( Connection->AbortIndicated )
    );

    dprintf(
        "    TdiBufferring                = %s\n",
        BooleanToString( Connection->TdiBufferring )
    );

    dprintf(
        "    ConnectedReferenceAdded      = %s\n",
        BooleanToString( Connection->ConnectedReferenceAdded )
    );

    dprintf(
        "    SpecialCondition             = %s\n",
        BooleanToString( Connection->SpecialCondition )
    );

    dprintf(
        "    CleanupBegun                 = %s\n",
        BooleanToString( Connection->CleanupBegun )
    );

    dprintf(
        "    ClosePendedTransmit          = %s\n",
        BooleanToString( Connection->ClosePendedTransmit )
    );

    if( IsCheckedAfd ) {

        dprintf(
            "    CurrentReferenceSlot         = %lu\n",
            Connection->CurrentReferenceSlot % MAX_REFERENCE
        );

        dprintf(
            "    ReferenceDebug               = %08lx\n",
            ACTUAL_ADDRESS(
                ActualAddress,
                Connection,
                ReferenceDebug
            )
        );

    }

    dprintf( "\n" );

}   // DumpAfdConnection