summaryrefslogtreecommitdiff
path: root/pos/drivers/MagneticStripeReader/IoRead.cpp
blob: c19ee7432a7919e23bb708149febd4b0083b38ce (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
#include <pch.h>

/*
** Driver TODO: Add logic to EvtIoRead to handle read requests from applications that don't use the Windows.Devices.PointOfService APIs.
**
** This is the callback for the IO queue that handles file read requests.  In the POS magnetic
** stripe reader model, the application will always queue a read request in order to receive events
** such as the data received event, or the release-claim requested event.
**
** Note that apps that are developed against the Windows.Devices.PointOfService APIs will always
** expect event data to be returned by read requests.  It is up to the driver to determine the
** behavior of ReadFile when the driver is opened by other types of applications.
*/
VOID EvtIoRead(_In_ WDFQUEUE Queue, _In_ WDFREQUEST Request, _In_ size_t Length)
{
    NTSTATUS status;
    WDFDEVICE device = WdfIoQueueGetDevice(Queue);
    WDFFILEOBJECT fileObject = WdfRequestGetFileObject(Request);

    UNREFERENCED_PARAMETER(Length);

    // Check the flag that may have been set by PosCxMarkPosApp in Ioctl.cpp.
    if (!PosCxIsPosApp(device, fileObject))
    {
        // An application has opened a handle to this device without using the Windows.Devices.PointOfService APIs.
        // You may change this to handle the read request differently.

        // In this example, just complete the read request with a failure.
        WdfRequestComplete(Request, STATUS_UNSUCCESSFUL);
    }
    else
    {
        // If this returns success, it has taken ownership of Request
        status = PosCxGetPendingEvent(device, Request);

        if (!NT_SUCCESS(status))
        {
            WdfRequestComplete(Request, status);
        }
    }
}