Exemple #1
0
VOID UnloadRoutine(IN PDRIVER_OBJECT pDriverObject)
{
    PDEVICE_OBJECT	pNextDevObj;
    int i;

    KLog(LInfo, "UnloadRoutine");

	MonitorStop(NULL);

	pNextDevObj = pDriverObject->DeviceObject;

    for(i = 0; pNextDevObj != NULL; i++)
    {
        PMDEVICE_EXTENSION DevExt = (PMDEVICE_EXTENSION)pNextDevObj->DeviceExtension;
        PDEVICE_OBJECT DevObj = pNextDevObj;
        pNextDevObj = pNextDevObj->NextDevice;
        if (DevExt != NULL) {
            KLog(LInfo, "Deleted device ext %p device %p", DevExt, DevExt->DeviceObject);
            KLog(LInfo, "Deleted symlink = %wZ", &DevExt->SymLinkName);
            IoDeleteSymbolicLink(&DevExt->SymLinkName);
        }

        IoDeleteDevice(DevObj);
    }

	KLog(LInfo, "UnloadRoutine completed");
    KLoggingRelease();
}
Exemple #2
0
/****************************************************************
 * This interrupt handler is set up by AcquireInit to check
 * for the events that begin a data logging. This is when the voltage
 * exceeds a changeable threshold or
 * the accelerometer z-axis changes g by more than 0.5.
 *****************************************************************/
void MonitorShockISR() {
    ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
    //
    // Toggle the flag for the second timer.
    //
    HWREGBITW(&g_ui32Flags, 1) ^= 1;
	// If ADC has not converted yet, exit ISR.
   	if (!ADCIntStatus(ADC1_BASE, 3, false)) {
   		return;
   	}
   	ADCIntClear(ADC1_BASE, 3);
	ADCSequenceDataGet(ADC1_BASE, 3, puiADC1Buffer);
	ADCProcessorTrigger(ADC1_BASE, 3);
	if (first_entry) {
		first_entry = false;
		prev1_value = ReadAccel(puiADC1Buffer[0]);
	} else {
		puiADC1Buffer[0] = ReadAccel(puiADC1Buffer[0]);
		// Shock monitor detects a change of more than 2.4g
		if (abs((int)puiADC1Buffer[0] - prev1_value) > 240) {
//			UARTprintf("Shock! : %d \r",puiADC1Buffer[0]);
			MonitorStop();
			// Start LED
			ROM_TimerEnable(TIMER2_BASE, TIMER_A);
			// Start logging waveform.
			ROM_IntMasterDisable();
			psuiConfig->isShocked = true;
			ROM_IntMasterEnable();
		} else {
			ROM_IntMasterDisable();
			psuiConfig->isShocked = false;
			ROM_IntMasterEnable();
		}
		prev1_value = puiADC1Buffer[0];
	}
}
Exemple #3
0
NTSTATUS DriverDeviceControlHandler( IN PDEVICE_OBJECT fdo, IN PIRP Irp )
{
    NTSTATUS Status = STATUS_SUCCESS;
    PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp);
    ULONG ControlCode = IrpStack->Parameters.DeviceIoControl.IoControlCode;
    ULONG method = ControlCode & 0x3;
    ULONG ResultLength = 0;
    ULONG InputLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength;
    ULONG OutputLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength;
    PVOID Buffer = Irp->AssociatedIrp.SystemBuffer;

	KeEnterGuardedRegion();

    KLOG(LInfo, "IoControl fdo %p, ioctl %x", fdo, ControlCode);
	if (OutputLength < InputLength) {
		KLog(LError, "invalid outputlen=%x vs inputlen=%x", OutputLength, InputLength);
		Status = STATUS_INVALID_PARAMETER;
		goto complete;
	}
	
	ResultLength = InputLength;

    switch( ControlCode) {
        case IOCTL_KMON_INIT:
            {   
				PKMON_INIT initData = (PKMON_INIT)Buffer;
				if (InputLength < sizeof(KMON_INIT)) {
					Status = STATUS_BUFFER_TOO_SMALL;
					goto complete;
				}

                KLog(LInfo, "IOCTL_KMON_INIT");
				Status = MonitorStart(initData);
                break;
            }
        case IOCTL_KMON_RELEASE:
            {
				PKMON_RELEASE releaseData = (PKMON_RELEASE)Buffer;
				if (InputLength < sizeof(KMON_RELEASE)) {
					Status = STATUS_BUFFER_TOO_SMALL;
					goto complete;
				}
                KLog(LInfo, "IOCTL_KMON_RELEASE");
				Status = MonitorStop(releaseData);
                break;
            }
		case IOCTL_KMON_OPEN_WINSTA:
			{
				POPEN_WINSTA openWinsta = (POPEN_WINSTA)Buffer;
				if (InputLength < sizeof(OPEN_WINSTA)) {
					Status = STATUS_BUFFER_TOO_SMALL;
					goto complete;
				}
				Status = MonitorOpenWinsta(openWinsta);
				break;
			}
		case IOCTL_KMON_OPEN_DESKTOP:
		{
				POPEN_DESKTOP openDeskop = (POPEN_DESKTOP)Buffer;
				if (InputLength < sizeof(OPEN_DESKTOP)) {
					Status = STATUS_BUFFER_TOO_SMALL;
					goto complete;
				}
				Status = MonitorOpenDesktop(openDeskop);
				break;
		}
		case IOCTL_KMON_SCREENSHOT:
		{
				PKMON_SCREENSHOT screenShot = (PKMON_SCREENSHOT)Buffer;
				if (InputLength < sizeof(KMON_SCREENSHOT)) {
					Status = STATUS_BUFFER_TOO_SMALL;
					goto complete;
				}
				Status = MonitorScreenshot(screenShot);
				break;
		}
        default: Status = STATUS_INVALID_DEVICE_REQUEST;
    }


complete:
	KeLeaveGuardedRegion();
	KLog(LInfo, "dev=%p IoControl: %x bytes: %x, Status=%x", fdo, ControlCode, ResultLength, Status);

    return CompleteIrp(Irp, Status, ResultLength);
}