summaryrefslogtreecommitdiff
path: root/serial/VirtualSerial2/driver.c
blob: bb7f4c733ade1085a90b25b79b5295de96eb6e14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*++

Copyright (C) Microsoft Corporation, All Rights Reserved.

Module Name:

    Driver.c

Abstract:

    This module contains the implementation of the VirtualSerial Sample's
    core driver callback object.

Environment:

    Windows Driver Framework

--*/

#include <initguid.h>
#include "internal.h"

NTSTATUS
DriverEntry(
    _In_  PDRIVER_OBJECT    DriverObject,
    _In_  PUNICODE_STRING   RegistryPath
    )
{
    NTSTATUS                status;
    WDF_DRIVER_CONFIG       driverConfig;

    WDF_DRIVER_CONFIG_INIT(&driverConfig,
                            EvtDeviceAdd);

    status = WdfDriverCreate(DriverObject,
                            RegistryPath,
                            WDF_NO_OBJECT_ATTRIBUTES,
                            &driverConfig,
                            WDF_NO_HANDLE);
    if (!NT_SUCCESS(status)) {
        Trace(TRACE_LEVEL_ERROR,
            "Error: WdfDriverCreate failed 0x%x", status);
        return status;
    }

    return status;
}

NTSTATUS
EvtDeviceAdd(
    _In_  WDFDRIVER         Driver,
    _Inout_ PWDFDEVICE_INIT DeviceInit
    )
{
    NTSTATUS                status;
    PDEVICE_CONTEXT         deviceContext;

    status = DeviceCreate(Driver,
                            DeviceInit,
                            &deviceContext);
    if (!NT_SUCCESS(status)) {
        return status;
    }

    status = DeviceConfigure(deviceContext);
    if (!NT_SUCCESS(status)) {
        return status;
    }

    return status;
}