1 /* 2 * PROJECT: ReactOS Drivers 3 * LICENSE: BSD - See COPYING.ARM in the top level directory 4 * FILE: drivers/sac/driver/init.c 5 * PURPOSE: Driver for the Server Administration Console (SAC) for EMS 6 * PROGRAMMERS: ReactOS Portable Systems Group 7 */ 8 9 /* INCLUDES *******************************************************************/ 10 11 #include "sacdrv.h" 12 13 /* FUNCTIONS ******************************************************************/ 14 15 NTSTATUS 16 NTAPI 17 DriverEntry(IN PDRIVER_OBJECT DriverObject, 18 IN PUNICODE_STRING RegistryPath) 19 { 20 HEADLESS_RSP_QUERY_INFO HeadlessInformation; 21 SIZE_T InfoSize = sizeof(HeadlessInformation); 22 NTSTATUS Status; 23 UNICODE_STRING DriverName; 24 PDEVICE_OBJECT DeviceObject; 25 PSAC_DEVICE_EXTENSION DeviceExtension; 26 PAGED_CODE(); 27 SAC_DBG(SAC_DBG_ENTRY_EXIT, "Entering.\n"); 28 29 /* Check if EMS is enabled in the kernel */ 30 HeadlessDispatch(HeadlessCmdQueryInformation, 31 NULL, 32 0, 33 &HeadlessInformation, 34 &InfoSize); 35 if ((HeadlessInformation.PortType != HeadlessUndefinedPortType) && 36 ((HeadlessInformation.PortType != HeadlessSerialPort) || 37 (HeadlessInformation.Serial.TerminalAttached))) 38 { 39 /* It is, so create the device */ 40 RtlInitUnicodeString(&DriverName, L"\\Device\\SAC"); 41 Status = IoCreateDevice(DriverObject, 42 sizeof(SAC_DEVICE_EXTENSION), 43 &DriverName, 44 FILE_DEVICE_UNKNOWN, 45 FILE_DEVICE_SECURE_OPEN, 46 FALSE, 47 &DeviceObject); 48 if (NT_SUCCESS(Status)) 49 { 50 /* Setup the device extension */ 51 DeviceExtension = DeviceObject->DeviceExtension; 52 DeviceExtension->Initialized = FALSE; 53 54 /* Initialize the driver object */ 55 RtlFillMemoryUlong(DriverObject->MajorFunction, 56 RTL_NUMBER_OF(DriverObject->MajorFunction), 57 (ULONG_PTR)Dispatch); 58 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DispatchDeviceControl; 59 DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = DispatchShutdownControl; 60 DriverObject->FastIoDispatch = NULL; 61 DriverObject->DriverUnload = UnloadHandler; 62 63 /* Initialize driver data */ 64 if (InitializeGlobalData(RegistryPath, DriverObject)) 65 { 66 /* Initialize device data */ 67 if (InitializeDeviceData(DeviceObject)) 68 { 69 /* We're all good, register a shutdown notification */ 70 IoRegisterShutdownNotification(DeviceObject); 71 return Status; 72 } 73 } 74 75 /* One of the initializations failed, bail out */ 76 Status = STATUS_INSUFFICIENT_RESOURCES; 77 } 78 else 79 { 80 /* Print a debug statement if enabled */ 81 SAC_DBG(SAC_DBG_INIT, "unable to create device object: %X\n", Status); 82 } 83 84 /* Free any data we may have allocated and exit with failure */ 85 FreeGlobalData(); 86 SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting with status 0x%x\n", Status); 87 return Status; 88 } 89 90 /* EMS is not enabled */ 91 return STATUS_PORT_DISCONNECTED; 92 } 93