summaryrefslogtreecommitdiff
path: root/gnss/gnssUmdf/FixHandler.cpp
blob: 52b09a8299d2661ceba86bc065bb72a3dd044d3a (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*++

Copyright (c) Microsoft Corporation.  All rights reserved.

Module Name:

    fixhandler.cpp

Abstract:

    This file contains the Fix handler and contains logic to provide position.

Environment:

    Windows User-Mode Driver Framework

--*/

#include "precomp.h"
#include "Trace.h"
#include "Defaults.h"
#include "FixSession.h"
#include "FixHandler.h"

#include "FixHandler.tmh" 


NTSTATUS
CFixHandler::Initialize(
    _In_ WDFQUEUE Queue
)
{
    NTSTATUS status = STATUS_SUCCESS;

    status = _SingleShotSession.Initialize(Queue);

    return status;
}

NTSTATUS
CFixHandler::StartFix(
    _In_ WDFREQUEST Request,
    _In_ BOOL LocationServiceEnabled
)
{
    NTSTATUS status = STATUS_SUCCESS;
    PGNSS_FIXSESSION_PARAM fixSessionParameters = nullptr;

    // For privacy reasons, the location stack notifies the driver when user toggles the location device controls.
    // When set to off, the driver must not entertain any new location sessions.
    if (!LocationServiceEnabled)
    {
        status = STATUS_UNSUCCESSFUL;
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_FIX, "Location master switch is off, we do not start a fix session");
        goto Exit;
    }

    status = WdfRequestRetrieveInputBuffer(Request, sizeof(GNSS_FIXSESSION_PARAM), (void**)&fixSessionParameters, nullptr);
    if (!NT_SUCCESS(status))
    {
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_FIX, "WdfRequestRetrieveInputBuffer failed with %!STATUS!", status);
        goto Exit;
    }

    //
    // FIX ME:
    // This sample currently supports only single shot session fix.
    // If you support another session type, e.g., distance tracking, update the logic below accordingly.
    //
    if (fixSessionParameters->SessionType != GNSS_FixSession_SingleShot)
    {
        status = STATUS_UNSUCCESSFUL;
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_FIX, "Session type is not GNSS_FixSession_SingleShot");
        goto Exit;
    }

    _CurrentSinglsShotSessionId = fixSessionParameters->FixSessionID;

    status = _SingleShotSession.StartAcquiringFix(fixSessionParameters);
    if (!NT_SUCCESS(status))
    {
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_FIX, "StartFix failed with %!STATUS!", status);
        goto Exit;
    }

Exit:
    return status;
}

NTSTATUS
CFixHandler::StopFix(
    _In_ WDFREQUEST Request
)
{
    NTSTATUS status = STATUS_SUCCESS;
    PGNSS_STOPFIXSESSION_PARAM stopFixSessionParam = nullptr;

    status = WdfRequestRetrieveInputBuffer(Request, sizeof(GNSS_STOPFIXSESSION_PARAM), (void**)&stopFixSessionParam, nullptr);
    if (!NT_SUCCESS(status))
    {
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_FIX, "WdfRequestRetrieveInputBuffer failed with %!STATUS!", status);
        goto Exit;
    }

    // Send the session parameters to the right session based on the ID
    if (stopFixSessionParam->FixSessionID != _CurrentSinglsShotSessionId)
    {
        status = STATUS_UNSUCCESSFUL;
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_FIX, "Session type is not GNSS_FixSession_SingleShot");
        goto Exit;
    }

    _CurrentSinglsShotSessionId = INVALID_SESSION_ID;

    status = _SingleShotSession.StopAcquiringFix(stopFixSessionParam);
    if (!NT_SUCCESS(status))
    {
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_FIX, "StopFix failed with %!STATUS!", status);
        goto Exit;
    }

Exit:
    return status;
}

NTSTATUS
CFixHandler::StopExistingSinglsShotFix()
{
    NTSTATUS status = STATUS_SUCCESS;
    PGNSS_STOPFIXSESSION_PARAM stopFixSessionParam = nullptr;
    
    if (_CurrentSinglsShotSessionId == INVALID_SESSION_ID)
    {
        TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FIX, "There is no single shot session to stop");
        goto Exit;
    }

    _CurrentSinglsShotSessionId = INVALID_SESSION_ID;
    
    INIT_POD_GNSS_STRUCT(stopFixSessionParam);
    status = _SingleShotSession.StopAcquiringFix(stopFixSessionParam);
    if (!NT_SUCCESS(status))
    {
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_FIX, "StopFix failed with %!STATUS!", status);
        goto Exit;
    }

Exit:
    return status;
}

NTSTATUS
CFixHandler::ModifyFix(
    _In_ WDFREQUEST Request
)
{
    NTSTATUS status = STATUS_SUCCESS;
    PGNSS_FIXSESSION_PARAM fixSessionParameters = nullptr;

    status = WdfRequestRetrieveInputBuffer(Request, sizeof(GNSS_FIXSESSION_PARAM), (void**)&fixSessionParameters, nullptr);
    if (!NT_SUCCESS(status))
    {
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_FIX, "WdfRequestRetrieveInputBuffer failed with %!STATUS!", status);
        goto Exit;
    }

    //
    // FIX ME:
    // We currently support only single shot session fix.
    // If you support another session type, e.g., distance tracking, update the logic below accordingly.
    //
    if (fixSessionParameters->SessionType != GNSS_FixSession_SingleShot)
    {
        status = STATUS_UNSUCCESSFUL;
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_FIX, "Session type is not GNSS_FixSession_SingleShot");
        goto Exit;
    }
    
    //
    // FIX ME:
    // Since only single session is supported, use _SingleShotSession instance.
    // If multiple sessions, get the right session pointer searched by the session ID.
    //
    _SingleShotSession.ModifyAcquiringFix(fixSessionParameters);

    if (!NT_SUCCESS(status))
    {
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_FIX, "ModifyFix failed with %!STATUS!", status);
        goto Exit;
    }

Exit:
    return status;
}

NTSTATUS
CFixHandler::GetFixRequest(
    _In_ WDFREQUEST Request
)
{
    NTSTATUS status = STATUS_SUCCESS;
    ULONG sessionId = INVALID_SESSION_ID;
    ULONG *pSessionId = nullptr;

    // Get the session ID this get fix is for
    status = WdfRequestRetrieveInputBuffer(Request, sizeof(sessionId), (void**)&pSessionId, nullptr);
    if (!NT_SUCCESS(status))
    {
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_FIX, "Could not retrieve input sessionID for request");
        goto Exit;
    }

    //
    // FIX ME:
    // Single session is only option now, but if multiple sessions, this sample should do this check at the FixHandler Level.
    //
    sessionId = *pSessionId;

    status = _SingleShotSession.GetFix(Request);
    if (!NT_SUCCESS(status))
    {
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_FIX, "SinglShotSession.GetFix failed with %!STATUS!", status);
        goto Exit;
    }

Exit:
    return status;
}