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
|
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
PURPOSE.
Module Name:
Echo.c
Abstract:
Contains echo related functionality
Environment:
Kernel mode only
--*/
#include "clisrv.h"
#include "device.h"
#include "server.h"
#include "echo.h"
#if defined(EVENT_TRACING)
#include "echo.tmh"
#endif
void
BthEchoSrvWriteCompletion(
_In_ WDFREQUEST Request,
_In_ WDFIOTARGET Target,
_In_ PWDF_REQUEST_COMPLETION_PARAMS Params,
_In_ WDFCONTEXT Context
)
/*++
Description:
Completion routine for echo L2Ca transfer
Arguments:
Request - Request that completed
Target - Target to which request was sent
Params - Request completion parameters
Context - We receive connection as the context
--*/
{
NTSTATUS status;
UNREFERENCED_PARAMETER(Target);
UNREFERENCED_PARAMETER(Context);
status = Params->IoStatus.Status;
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_CONNECT,
"Write completion, status: %!STATUS!", status);
WdfObjectDelete(Request);
//
// We don't attempt to disconnect in case of failure
// here because we expect the failure only be due to
// device/channel disconnect, in which case disconnect
// would happen anyway.
//
// Without taking a reference on the connection object
// while submitting echo write
// we cannot touch connection object here as connection could get
// disconnected and connection object could get freed.
//
}
_IRQL_requires_max_(DISPATCH_LEVEL)
VOID
BthEchoSrvSendEcho(
_In_ PBTHECHOSAMPLE_DEVICE_CONTEXT_HEADER DevCtxHdr,
_In_ PBTHECHO_CONNECTION Connection,
_In_ PVOID SrcBuffer,
_In_ size_t SrcBufferLength
)
/*++
Routine Description:
Performs L2Cap transfer to client to do the echo.
This routine is invoked by continuous reader read completion callback
(BthEchoSrvConnectionObjectContReaderReadCompletedCallback).
Arguments:
DevCtxHdr - Device context
Connection - Connection whose continous reader had read completion
SrcBuffer - Source buffer for the echo
SrcBufferLength - Length of the source buffer
--*/
{
NTSTATUS status;
WDF_OBJECT_ATTRIBUTES attributes;
WDFREQUEST request = NULL;
WDFMEMORY memory = NULL;
PVOID dataBuffer = NULL;
struct _BRB_L2CA_ACL_TRANSFER *brb = NULL;
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = DevCtxHdr->Device;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, BRB);
status = WdfRequestCreate(
&attributes,
DevCtxHdr->IoTarget,
&request
);
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_CONT_READER,
"Creating request for echo failed, Status code %!STATUS!\n",
status
);
goto exit;
}
if (SrcBufferLength <= 0)
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_CONT_READER,
"SrcBufferLength has an invalid value: %I64d\n",
SrcBufferLength
);
status = STATUS_INVALID_PARAMETER;
goto exit;
}
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = request;
status = WdfMemoryCreate(
&attributes,
NonPagedPoolNx,
POOLTAG_BTHECHOSAMPLE,
SrcBufferLength,
&memory,
&dataBuffer
);
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, DBG_CONT_READER,
"Creating memory for pending read failed, Status code %!STATUS!\n",
status
);
goto exit;
}
memcpy(dataBuffer, SrcBuffer, SrcBufferLength);
brb = (struct _BRB_L2CA_ACL_TRANSFER *)GetEchoRequestContext(request);
status = BthEchoConnectionObjectFormatRequestForL2CaTransfer(
Connection,
request,
&brb,
memory,
ACL_TRANSFER_DIRECTION_OUT
);
if (!NT_SUCCESS(status))
{
goto exit;
}
//
// Set a CompletionRoutine callback function.
//
WdfRequestSetCompletionRoutine(
request,
BthEchoSrvWriteCompletion,
Connection
);
if (FALSE == WdfRequestSend(
request,
DevCtxHdr->IoTarget,
NULL
))
{
status = WdfRequestGetStatus(request);
TraceEvents(TRACE_LEVEL_ERROR, DBG_CONT_READER,
"Request send failed for request 0x%p, Brb 0x%p, Status code %!STATUS!\n",
request,
brb,
status
);
goto exit;
}
exit:
if (!NT_SUCCESS(status))
{
if (NULL != request)
{
WdfObjectDelete(request);
}
//
// If we failed disconnect
//
BthEchoSrvDisconnectConnection(Connection);
}
}
|