forked from nefarius/BthPS3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
L2CAP.h
369 lines (323 loc) · 11.9 KB
/
L2CAP.h
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/**********************************************************************************
* *
* BthPS3PSM - Windows kernel-mode BTHUSB lower filter driver *
* *
* BSD 3-Clause License *
* *
* Copyright (c) 2018-2021, Nefarius Software Solutions e.U. *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, this *
* list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, *
* this list of conditions and the following disclaimer in the documentation *
* and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" *
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE *
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
**********************************************************************************/
#pragma once
/**
* \typedef enum _L2CAP_SIGNALLING_COMMAND_CODE
*
* \brief Defines an alias representing an L2CAP signaling command code.
*/
typedef enum _L2CAP_SIGNALLING_COMMAND_CODE
{
L2CAP_Reserved = 0x00,
L2CAP_Command_Reject = 0x01,
/// <summary>
/// A Connection Request packet has been received.
/// </summary>
L2CAP_Connection_Request = 0x02,
/// <summary>
/// A Connection Response packet has been received with a positive result indicating that the connection has been
/// established.
/// </summary>
L2CAP_Connection_Response = 0x03,
/// <summary>
/// A Configuration Request packet has been received indicating the remote endpoint wishes to engage in negotiations
/// concerning channel parameters.
/// </summary>
L2CAP_Configuration_Request = 0x04,
/// <summary>
/// A Configuration Response packet has been received indicating the remote endpoint agrees with all the parameters
/// being negotiated.
/// </summary>
L2CAP_Configuration_Response = 0x05,
/// <summary>
/// A Disconnection Request packet has been received and the channel must initiate the disconnection process. Following
/// the completion of an L2CAP channel disconnection process, an L2CAP entity should return the corresponding local CID
/// to the pool of “unassigned” CIDs.
/// </summary>
L2CAP_Disconnection_Request = 0x06,
/// <summary>
/// A Disconnection Response packet has been received. Following the receipt of this signal, the receiving L2CAP entity
/// may return the corresponding local CID to the pool of unassigned CIDs. There is no corresponding negative response
/// because the Disconnect Request must succeed.
/// </summary>
L2CAP_Disconnection_Response = 0x07,
L2CAP_Echo_Request = 0x08,
L2CAP_Echo_Response = 0x09,
L2CAP_Information_Request = 0x0A,
L2CAP_Information_Response = 0x0B
} L2CAP_SIGNALLING_COMMAND_CODE;
/**
* \typedef enum _L2CAP_CONFIGURATION_RESPONSE_RESULT
*
* \brief Defines an alias representing an L2CAP configuration response result.
*/
typedef enum _L2CAP_CONFIGURATION_RESPONSE_RESULT
{
/// <summary>
/// Success
/// </summary>
L2CAP_ConfigurationResponseResult_Success = 0x0000,
/// <summary>
/// Failure – unacceptable parameters
/// </summary>
L2CAP_ConfigurationResponseResult_FailureUnacceptableParameters = 0x0001,
/// <summary>
/// Failure – rejected (no reason provided)
/// </summary>
L2CAP_ConfigurationResponseResult_FailureRejected = 0x0002,
/// <summary>
/// Failure – unknown options
/// </summary>
L2CAP_ConfigurationResponseResult_FailureUnknownOptions = 0x0003
} L2CAP_CONFIGURATION_RESPONSE_RESULT;
/**
* \typedef enum _L2CAP_CONNECTION_RESPONSE_RESULT
*
* \brief Defines an alias representing an L2CAP connection response result.
*/
typedef enum _L2CAP_CONNECTION_RESPONSE_RESULT
{
/// <summary>
/// Connection successful.
/// </summary>
L2CAP_ConnectionResponseResult_ConnectionSuccessful = 0x0000,
/// <summary>
/// Connection pending.
/// </summary>
L2CAP_ConnectionResponseResult_ConnectionPending = 0x0001,
/// <summary>
/// Connection refused – PSM not supported.
/// </summary>
L2CAP_ConnectionResponseResult_ConnectionRefusedPsmNotSupported = 0x0002,
/// <summary>
/// Connection refused – security block.
/// </summary>
L2CAP_ConnectionResponseResult_ConnectionRefusedSecurityBlock = 0x0003,
/// <summary>
/// Connection refused – no resources available.
/// </summary>
L2CAP_ConnectionResponseResult_ConnectionRefusedNoResourcesAvailable = 0x0004
} L2CAP_CONNECTION_RESPONSE_RESULT;
/**
* \typedef enum _L2CAP_CONNECTION_RESPONSE_STATUS
*
* \brief Defines an alias representing an L2CAP connection response status.
*/
typedef enum _L2CAP_CONNECTION_RESPONSE_STATUS
{
/// <summary>
/// No further information available.
/// </summary>
L2CAP_ConnectionResponseStatus_NoFurtherInformationAvailable = 0x0000,
/// <summary>
/// Authentication pending.
/// </summary>
L2CAP_ConnectionResponseStatus_AuthenticationPending = 0x0001,
/// <summary>
/// Authorisation pending.
/// </summary>
L2CAP_ConnectionResponseStatus_AuthorisationPending = 0x0002
} L2CAP_CONNECTION_RESPONSE_STATUS;
/**
* \typedef enum _L2CAP_PSM
*
* \brief Defines an alias representing an L2CAP Protocol/Service Multiplexer.
*/
typedef enum _L2CAP_PSM
{
L2CAP_PSM_HID_Command = 0x11,
L2CAP_PSM_HID_Interrupt = 0x13
} L2CAP_PSM;
/**
* \typedef struct _L2CAP_CID
*
* \brief Defines an alias representing an L2CAP Channel Identifier.
*/
typedef struct _L2CAP_CID
{
BYTE Lsb;
BYTE Msb;
} L2CAP_CID, *PL2CAP_CID;
/**
* \typedef struct _L2CAP_SIGNALLING_COMMAND_REJECT
*
* \brief Defines an alias representing data attached to COMMAND REJECT.
*/
typedef struct _L2CAP_SIGNALLING_COMMAND_REJECT
{
BYTE Code;
BYTE Identifier;
USHORT Length;
USHORT Reason;
} L2CAP_SIGNALLING_COMMAND_REJECT, *PL2CAP_SIGNALLING_COMMAND_REJECT;
/**
* \typedef struct _L2CAP_SIGNALLING_CONNECTION_REQUEST
*
* \brief Defines an alias representing data attached to CONNECTION REQUEST.
*/
typedef struct _L2CAP_SIGNALLING_CONNECTION_REQUEST
{
BYTE Code;
BYTE Identifier;
USHORT Length;
USHORT PSM;
L2CAP_CID SCID;
} L2CAP_SIGNALLING_CONNECTION_REQUEST, *PL2CAP_SIGNALLING_CONNECTION_REQUEST;
/**
* \typedef struct _L2CAP_SIGNALLING_CONNECTION_RESPONSE
*
* \brief Defines an alias representing data attached to CONNECTION RESPONSE.
*/
typedef struct _L2CAP_SIGNALLING_CONNECTION_RESPONSE
{
BYTE Code;
BYTE Identifier;
USHORT Length;
L2CAP_CID DCID;
L2CAP_CID SCID;
USHORT Result;
USHORT Status;
} L2CAP_SIGNALLING_CONNECTION_RESPONSE, *PL2CAP_SIGNALLING_CONNECTION_RESPONSE;
/**
* \typedef struct _L2CAP_SIGNALLING_CONFIGURATION_REQUEST
*
* \brief Defines an alias representing data attached to CONFIGURATION REQUEST.
*/
typedef struct _L2CAP_SIGNALLING_CONFIGURATION_REQUEST
{
BYTE Code;
BYTE Identifier;
USHORT Length;
L2CAP_CID DCID;
USHORT Flags;
ULONG Options;
} L2CAP_SIGNALLING_CONFIGURATION_REQUEST, *PL2CAP_SIGNALLING_CONFIGURATION_REQUEST;
/**
* \typedef struct _L2CAP_SIGNALLING_CONFIGURATION_RESPONSE
*
* \brief Defines an alias representing data attached to CONFIGURATION RESPONSE.
*/
typedef struct _L2CAP_SIGNALLING_CONFIGURATION_RESPONSE
{
BYTE Code;
BYTE Identifier;
USHORT Length;
L2CAP_CID SCID;
USHORT Flags;
USHORT Result;
USHORT Options;
} L2CAP_SIGNALLING_CONFIGURATION_RESPONSE, *PL2CAP_SIGNALLING_CONFIGURATION_RESPONSE;
/**
* \typedef struct _L2CAP_SIGNALLING_DISCONNECTION_REQUEST
*
* \brief Defines an alias representing data attached to DISCONNECTION REQUEST.
*/
typedef struct _L2CAP_SIGNALLING_DISCONNECTION_REQUEST
{
BYTE Code;
BYTE Identifier;
USHORT Length;
L2CAP_CID DCID;
L2CAP_CID SCID;
} L2CAP_SIGNALLING_DISCONNECTION_REQUEST, *PL2CAP_SIGNALLING_DISCONNECTION_REQUEST;
/**
* \typedef struct _L2CAP_SIGNALLING_DISCONNECTION_RESPONSE
*
* \brief Defines an alias representing data attached to DISCONNECTION RESPONSE.
*/
typedef struct _L2CAP_SIGNALLING_DISCONNECTION_RESPONSE
{
BYTE Code;
BYTE Identifier;
USHORT Length;
L2CAP_CID DCID;
L2CAP_CID SCID;
} L2CAP_SIGNALLING_DISCONNECTION_RESPONSE, *PL2CAP_SIGNALLING_DISCONNECTION_RESPONSE;
/**
* \def L2CAP_IS_CONTROL_CHANNEL(_buf_) ((BOOLEAN)_buf_[6] == 0x01 && _buf_[7] == 0x00)
*
* \brief A macro that identifies the control channel.
*
* \author Benjamin "Nefarius" Höglinger
* \date 18.09.2017
*
* \param _buf_ The buffer.
*/
#define L2CAP_IS_CONTROL_CHANNEL(_buf_) ((BOOLEAN)_buf_[6] == 0x01 && _buf_[7] == 0x00)
/**
* \def L2CAP_IS_HID_INPUT_REPORT(_buf_) ((BOOLEAN)_buf_[8] == 0xA1 && _buf_[9] == 0x01)
*
* \brief A macro that identifies a HID input report.
*
* \author Benjamin "Nefarius" Höglinger
* \date 18.09.2017
*
* \param _buf_ The buffer.
*/
#define L2CAP_IS_HID_INPUT_REPORT(_buf_) ((BOOLEAN)_buf_[8] == 0xA1 && _buf_[9] == 0x01)
/**
* \def L2CAP_GET_SIGNALLING_COMMAND_CODE(_buf_) ((L2CAP_SIGNALLING_COMMAND_CODE)_buf_[8])
*
* \brief A macro that validates the signaling command code.
*
* \author Benjamin "Nefarius" Höglinger
* \date 18.09.2017
*
* \param _buf_ The buffer.
*/
#define L2CAP_GET_SIGNALLING_COMMAND_CODE(_buf_) ((L2CAP_SIGNALLING_COMMAND_CODE)_buf_[8])
/**
* \fn BOOLEAN FORCEINLINE L2CAP_IS_SIGNALLING_COMMAND_CODE( PUCHAR Buffer )
*
* \brief Checks if the supplied buffer represents a valid L2CAP signaling command code.
*
* \author Benjamin "Nefarius" Höglinger
* \date 18.09.2017
*
* \param Buffer The buffer.
*
* \return TRUE if valid, FALSE otherwise.
*/
BOOLEAN FORCEINLINE L2CAP_IS_SIGNALLING_COMMAND_CODE(
PUCHAR Buffer
)
{
for (UCHAR i = L2CAP_Command_Reject; i <= L2CAP_Information_Response; i++)
{
if (i == Buffer[8]) return TRUE;
}
return FALSE;
}