summaryrefslogtreecommitdiff
path: root/nfc/NfcCxSample/windows-drivertemplate-nfc/Device.h
blob: 5d373d118272f7dd62e905f55461061d09ecb0f9 (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
73
74
#pragma once

#include <windows.h>
#include <wdf.h>
#include <NfcCx.h>

class DeviceContext
{
public:
    // Implementation of `EvtDriverDeviceAdd`.
    static NTSTATUS AddDevice(
        _In_ WDFDRIVER Driver,
        _Inout_ PWDFDEVICE_INIT DeviceInit);

private:
    DeviceContext(_In_ WDFDEVICE Device);
    ~DeviceContext() = default;

    // Implementation of `EvtDestroyCallback`.
    static void Destroy(
        _In_ WDFOBJECT Object);

    // Implementation of `EvtDevicePrepareHardware`.
    static NTSTATUS PrepareHardware(
        _In_ WDFDEVICE Device,
        _In_ WDFCMRESLIST ResourcesRaw,
        _In_ WDFCMRESLIST ResourcesTranslated);

    // Implementation of `EvtDeviceReleaseHardware`.
    static NTSTATUS ReleaseHardware(
        _In_ WDFDEVICE Device,
        _In_ WDFCMRESLIST ResourcesTranslated);

    // Implementation of `EvtDeviceD0Entry`.
    static NTSTATUS D0Entry(
        _In_ WDFDEVICE Device,
        _In_ WDF_POWER_DEVICE_STATE PreviousState);

    // Implementation of `EvtDeviceD0Exit`.
    static NTSTATUS D0Exit(
        _In_ WDFDEVICE Device,
        _In_ WDF_POWER_DEVICE_STATE TargetState);

    // Implementation of `EvtNfcCxSequenceHandler`.
    static void SequenceHandler(
        _In_ WDFDEVICE Device,
        _In_ NFC_CX_SEQUENCE Sequence,
        _In_ PFN_NFC_CX_SEQUENCE_COMPLETION_ROUTINE CompletionRoutine,
        _In_opt_ WDFCONTEXT CompletionContext);

    static void IoControl(
        _In_ WDFDEVICE Device,
        _In_ WDFREQUEST Request,
        _In_ size_t OutputBufferLength,
        _In_ size_t InputBufferLength,
        _In_ ULONG IoControlCode);

    // Implementation of `EvtNfcCxWriteNciPacket`.
    static void WriteNciPacket(
        _In_ WDFDEVICE Device,
        _In_ WDFREQUEST Request);

    NTSTATUS ReadNciPacket(
        _In_reads_bytes_(nciPacketLength) void* nciPacket,
        _In_ size_t nciPacketLength);

    const WDFDEVICE _Device = nullptr;
    WDFMEMORY _NciReadMemory = nullptr;
};

// Define the DeviceGetContext() function which can be used to get a pointer the DeviceContext from a WDFDEVICE object.
// Equivalent to:
//   DeviceContext* DeviceGetContext(WDFOBJECT Handle) { ... }
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DeviceContext, DeviceGetContext);