NTSTATUS DriverEntry (_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath) { HID_MINIDRIVER_REGISTRATION hid; int i; /* The dispatch table should pass through all the IRPs, * but IRP_MJ_POWER is special because we need to start * the next power IRP immediately. * IRP_MJ_INTERNAL_DEVICE_CONTROL is forwarded to the * parent device to handle HID IOCTLs. */ for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) { if (i == IRP_MJ_INTERNAL_DEVICE_CONTROL) { DriverObject->MajorFunction[i] = HidPassthroughDispatchIoctl; } else if (i == IRP_MJ_POWER) { DriverObject->MajorFunction[i] = HidPassthroughDispatchPower; } else { DriverObject->MajorFunction[i] = HidPassthroughDispatch; } } DriverObject->DriverExtension->AddDevice = HidPassthroughAddDevice; DriverObject->DriverUnload = HidPassthroughUnload; RtlZeroMemory(&hid, sizeof(HID_MINIDRIVER_REGISTRATION)); hid.Revision = HID_REVISION; hid.DriverObject = DriverObject; hid.RegistryPath = RegistryPath; return HidRegisterMinidriver(&hid); }
NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject ,IN PUNICODE_STRING RegistryPath ) { // 変数宣言 NTSTATUS Status; SETTING Setting; HID_MINIDRIVER_REGISTRATION HIDMiniDriverRegistration; // ドライバ エントリ ポイントを設定する DriverObject->DriverExtension->AddDevice = AddDevice; DriverObject->DriverUnload = DriverUnload; DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = InternalDeviceControl; DriverObject->MajorFunction[IRP_MJ_PNP] = PnP; DriverObject->MajorFunction[IRP_MJ_POWER] = Power; // 設定を取得する LoadSetting( &Setting ); DevicesArePolled = Setting.DevicesArePolled; LimitationMode = Setting.LimitationMode; // HID Minidriver を登録する RtlZeroMemory( &HIDMiniDriverRegistration, sizeof( HIDMiniDriverRegistration ) ); HIDMiniDriverRegistration.Revision = HID_REVISION; HIDMiniDriverRegistration.DriverObject = DriverObject; HIDMiniDriverRegistration.RegistryPath = RegistryPath; HIDMiniDriverRegistration.DeviceExtensionSize = sizeof( DEVICE_EXTENSION ); HIDMiniDriverRegistration.DevicesArePolled = DevicesArePolled; Status = HidRegisterMinidriver( &HIDMiniDriverRegistration ); return( Status ); }
NTSTATUS EXTERNAL DriverEntry( __in PDRIVER_OBJECT DrvObj, __in PUNICODE_STRING RegPath ) { NTSTATUS status = STATUS_SUCCESS; HID_MINIDRIVER_REGISTRATION hidMinidriverRegistration = {0}; TEnter(Func,("(DrvObj=%p,RegPath=%p)\n", DrvObj, RegPath)); gDriverObj = DrvObj; DrvObj->MajorFunction[IRP_MJ_CREATE] = DrvObj->MajorFunction[IRP_MJ_CLOSE] = HbtnCreateClose; DrvObj->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = HbtnInternalIoctl; DrvObj->MajorFunction[IRP_MJ_PNP] = HbtnPnp; DrvObj->MajorFunction[IRP_MJ_POWER] = HbtnPower; DrvObj->DriverUnload = HbtnUnload; DrvObj->DriverExtension->AddDevice = HbtnAddDevice; // // Register with HIDCLASS.SYS module // RtlZeroMemory(&hidMinidriverRegistration, sizeof(hidMinidriverRegistration)); hidMinidriverRegistration.Revision = HID_REVISION; hidMinidriverRegistration.DriverObject = DrvObj; hidMinidriverRegistration.RegistryPath = RegPath; hidMinidriverRegistration.DeviceExtensionSize = sizeof(DEVICE_EXTENSION); hidMinidriverRegistration.DevicesArePolled = FALSE; status = HidRegisterMinidriver(&hidMinidriverRegistration); if (!NT_SUCCESS(status)) { LogError(ERRLOG_MINIDRV_REG_FAILED, status, UNIQUE_ERRID(0x10), NULL, NULL); TErr(("failed to register mini driver.\n")); } TExit(Func,("=%x\n", status)); return status; } //DriverEntry
NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject, IN PUNICODE_STRING pRegistryPath) { NTSTATUS status = STATUS_SUCCESS; HID_MINIDRIVER_REGISTRATION hidMinidriverRegistration; pDriverObject->MajorFunction[IRP_MJ_CREATE] = 0;//XBCDCreate; pDriverObject->MajorFunction[IRP_MJ_CLOSE] = 1;//XBCDClose; pDriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = 2;//XBCDDispatchIntDevice; pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = 3;//XBCDDispatchDevice; pDriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = 4;//XBCDDispatchSystem; pDriverObject->MajorFunction[IRP_MJ_POWER] = 5;//XBCDDispatchPower; pDriverObject->MajorFunction[IRP_MJ_PNP] = 6;//XBCDDispatchPnp; pDriverObject->DriverUnload = 7;//XBCDUnload; pDriverObject->DriverExtension->AddDevice = 8;//XBCDAddDevice; RtlZeroMemory(&hidMinidriverRegistration, sizeof(HID_MINIDRIVER_REGISTRATION)); hidMinidriverRegistration.Revision = HID_REVISION; hidMinidriverRegistration.DriverObject = pDriverObject; hidMinidriverRegistration.RegistryPath = pRegistryPath; /* The size of this driver's own 'device extension'. With this, enough memory will be allocated by the system automatically */ hidMinidriverRegistration.DeviceExtensionSize = sizeof(DEVICE_EXTENSION); hidMinidriverRegistration.DevicesArePolled = TRUE; status = HidRegisterMinidriver(&hidMinidriverRegistration); if (NT_SUCCESS(status)) { KdPrint(("Minidriver Registration Worked")); /*RegistryPath.Buffer = (PWSTR) ExAllocatePool(PagedPool, pRegistryPath->Length + sizeof(WCHAR)); RegistryPath.MaximumLength = pRegistryPath->Length + sizeof(WCHAR); RtlCopyUnicodeString(&RegistryPath, pRegistryPath); RegistryPath.Buffer[pRegistryPath->Length/sizeof(WCHAR)] = 0;*/ KdPrint(("%ws", pRegistryPath->Buffer)); } else { KdPrint(("Minidriver Registration Failed")); } return status; }
NTSTATUS DriverEntry ( __in PDRIVER_OBJECT DriverObject, __in PUNICODE_STRING RegistryPath ) /*++ Routine Description: Installable driver initialization entry point. This entry point is called directly by the I/O system. Arguments: DriverObject - pointer to the driver object RegistryPath - pointer to a unicode string representing the path, to driver-specific key in the registry. Return Value: STATUS_SUCCESS if successful, STATUS_UNSUCCESSFUL otherwise. --*/ { HID_MINIDRIVER_REGISTRATION hidMinidriverRegistration; NTSTATUS status; ULONG i; KdPrint(("Enter DriverEntry()\n")); // // Initialize the dispatch table to pass through all the IRPs. // for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) { DriverObject->MajorFunction[i] = HidKmdfPassThrough; } // // Special case power irps so that we call PoCallDriver instead of IoCallDriver // when sending the IRP down the stack. // DriverObject->MajorFunction[IRP_MJ_POWER] = HidKmdfPowerPassThrough; DriverObject->DriverExtension->AddDevice = HidKmdfAddDevice; DriverObject->DriverUnload = HidKmdfUnload; RtlZeroMemory(&hidMinidriverRegistration, sizeof(hidMinidriverRegistration)); // // Revision must be set to HID_REVISION by the minidriver // hidMinidriverRegistration.Revision = HID_REVISION; hidMinidriverRegistration.DriverObject = DriverObject; hidMinidriverRegistration.RegistryPath = RegistryPath; hidMinidriverRegistration.DeviceExtensionSize = 0; // // if "DevicesArePolled" is False then the hidclass driver does not do // polling and instead reuses a few Irps (ping-pong) if the device has // an Input item. Otherwise, it will do polling at regular interval. USB // HID devices do not need polling by the HID classs driver. Some leagcy // devices may need polling. // hidMinidriverRegistration.DevicesArePolled = FALSE; // // Register with hidclass // status = HidRegisterMinidriver(&hidMinidriverRegistration); if (!NT_SUCCESS(status) ){ KdPrint(("HidRegisterMinidriver FAILED, returnCode=%x\n", status)); } return status; }
NTSTATUS DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { NTSTATUS ntStatus; HID_MINIDRIVER_REGISTRATION hidMinidriverRegistration; PPJOY_DBGPRINT (FILE_PPORTJOY|PPJOY_WARN, ("Built " __DATE__ " at " __TIME__) ); PPJOY_DBGPRINT (FILE_PPORTJOY|PPJOY_FENTRY, ("DriverEntry (DriverObject=0x%p,RegistryPath=0x%p)",DriverObject,RegistryPath) ); /* First setup global parameters memory structure */ RtlZeroMemory(&Globals, sizeof(Globals)); /* Setup copy of DriverObject first so we can use it for event log function */ Globals.DriverObject= DriverObject; /* Allocate buffer to store registry path to the parameters registry key */ Globals.ParamRegistryPath.MaximumLength= RegistryPath->Length+sizeof(UNICODE_NULL)+sizeof(PARAM_KEY_NAME); Globals.ParamRegistryPath.Length= RegistryPath->Length; Globals.ParamRegistryPath.Buffer= ExAllocatePoolWithTag (PagedPool,Globals.ParamRegistryPath.MaximumLength,PPJOY_POOL_TAG); if (!Globals.ParamRegistryPath.Buffer) { ntStatus= STATUS_INSUFFICIENT_RESOURCES; PPortJoy_WriteEventLog (PPJ_MSG_ERRORALLOCMEM,&ntStatus,sizeof(ntStatus),L""); goto Exit; } /* Copy driver registry path and append the parameters subkey name */ RtlCopyUnicodeString (&Globals.ParamRegistryPath,RegistryPath); RtlAppendUnicodeToString (&Globals.ParamRegistryPath,PARAM_KEY_NAME); #ifdef USE_SCAN_THREAD ntStatus= PPJoy_StartScanThread(); if (!NT_SUCCESS (ntStatus)) { PPJOY_DBGPRINT (FILE_PPORTJOY|PPJOY_ERROR, ("Error creating async joystick read thread. ntStatus(0x%x)",ntStatus) ); PPortJoy_WriteEventLog (PPJ_MSG_ERRORTHREAD,&ntStatus,sizeof(ntStatus),L""); return ntStatus; } #endif /* Set up pointers to our other entry points in the DeviceObject */ DriverObject->DriverUnload= PPJoy_Unload; DriverObject->DriverExtension->AddDevice= PPJoy_AddDevice; DriverObject->MajorFunction[IRP_MJ_PNP]= PPJoy_PnP; DriverObject->MajorFunction[IRP_MJ_POWER]= PPJoy_Power; DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL]= PPJoy_InternalIoctl; /* Setup HID registration structure */ RtlZeroMemory(&hidMinidriverRegistration, sizeof(hidMinidriverRegistration)); hidMinidriverRegistration.DeviceExtensionSize= sizeof(DEVICE_EXTENSION); hidMinidriverRegistration.Revision= HID_REVISION; hidMinidriverRegistration.DriverObject= DriverObject; hidMinidriverRegistration.RegistryPath= RegistryPath; //hidMinidriverRegistration.DevicesArePolled= FALSE; // Setting False makes biiiiig mess. hidMinidriverRegistration.DevicesArePolled= TRUE; PPJOY_DBGPRINT (FILE_PPORTJOY|PPJOY_BABBLE2, ("DeviceExtensionSize= %d",hidMinidriverRegistration.DeviceExtensionSize) ); /* Register with HID.SYS module */ ntStatus= HidRegisterMinidriver(&hidMinidriverRegistration); PPJOY_DBGPRINT (FILE_PPORTJOY|PPJOY_BABBLE2, ("Registered with HID.SYS, returnCode=%x",ntStatus) ); if (!NT_SUCCESS (ntStatus)) { PPortJoy_WriteEventLog (PPJ_MSG_ERRORHIDREG,&ntStatus,sizeof(ntStatus),L""); goto Exit; } /* Make a copy of the dispatch table, after hid.sys modified it */ RtlCopyMemory (HIDMajorFunctions,DriverObject->MajorFunction,sizeof(HIDMajorFunctions)); /* Now we modify it back to our routines :-) */ DriverObject->MajorFunction[IRP_MJ_CREATE]= PPJoy_Ctl_CreateClose; DriverObject->MajorFunction[IRP_MJ_CLOSE]= PPJoy_Ctl_CreateClose; DriverObject->MajorFunction[IRP_MJ_PNP]= PPJoy_Ctl_PnP; DriverObject->MajorFunction[IRP_MJ_POWER]= PPJoy_Ctl_Power; DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL]= PPJoy_Ctl_InternalIoctl; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]= PPJoy_Ctl_Ioctl; /* Note, there is no "un-Initialise" routine for the SpinLock */ KeInitializeSpinLock (&Globals.SpinLock); PPortJoy_WriteEventLog (PPJ_MSG_DRIVERSTARTEDVER,&ntStatus,sizeof(ntStatus),LVER_PRODUCTVERSION_STR); Exit: PPJOY_EXITPROC (FILE_PPORTJOY|PPJOY_FEXIT_STATUSOK, "DriverEntry",ntStatus); return ntStatus; }