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
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** Device RNDIS Class */
/** */
/**************************************************************************/
/**************************************************************************/
#define UX_SOURCE_CODE
/* Include necessary system files. */
#include "ux_api.h"
#include "ux_device_class_rndis.h"
#include "ux_device_stack.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_rndis_msg_query PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function analyzes and replies to the MSG QUERY */
/* */
/* INPUT */
/* */
/* rndis Pointer to rndis class */
/* transfer_request Pointer to the transfer request */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* _ux_utility_long_get Get 32-bit value */
/* _ux_utility_long_put Put 32-bit value */
/* _ux_utility_string_length_check Check and return C string length */
/* _ux_utility_memory_copy Copy memory */
/* */
/* CALLED BY */
/* */
/* RNDIS Class */
/* */
/**************************************************************************/
UINT _ux_device_class_rndis_msg_query(UX_SLAVE_CLASS_RNDIS *rndis, UX_SLAVE_TRANSFER *transfer_request)
{
UCHAR *rndis_msg;
UCHAR *rndis_response;
ULONG rndis_oid;
ULONG rndis_response_length;
UINT rndis_response_string_length = 0;
ULONG oid_index;
ULONG status;
/* Get the pointer to the RNDIS message. */
rndis_msg = transfer_request -> ux_slave_transfer_request_data_pointer;
/* Get the request ID and keep it for the response. */
rndis -> ux_slave_class_rndis_request_id = _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_QUERY_REQUEST_ID);
/* Get the OID. */
rndis_oid = _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_QUERY_OID);
/* If trace is enabled, insert this event into the trace buffer. */
UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_RNDIS_MSG_QUERY, rndis, rndis_oid, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
/* Now prepare the response. */
rndis_response = rndis -> ux_slave_class_rndis_response;
/* First store the command. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_MESSAGE_TYPE, UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY);
/* Store the request ID. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_REQUEST_ID, rndis -> ux_slave_class_rndis_request_id);
/* By default the function will succeed. */
status = UX_DEVICE_CLASS_RNDIS_STATUS_SUCCESS;
/* What OID are we dealing here ? */
switch (rndis_oid)
{
case UX_DEVICE_CLASS_RNDIS_OID_GEN_SUPPORTED_LIST :
/* Supported List of OIDs. Parse each OID until the end and store it in the response buffer. */
oid_index = 0;
while (ux_device_class_rndis_oid_supported_list[oid_index] != 0)
{
/* We have found a valid OID to return. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER + (oid_index * sizeof(ULONG)),
ux_device_class_rndis_oid_supported_list[oid_index]);
/* Next OID index. */
oid_index++;
}
/* Set the total response length. */
rndis_response_length = oid_index * (ULONG)sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE :
/* Set the maximum frame size. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, UX_DEVICE_CLASS_RNDIS_MAX_FRAME_SIZE);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_MEDIA_SUPPORTED :
/* Set the media supported. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, UX_DEVICE_CLASS_RNDIS_MEDIA_802_3);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_MEDIA_IN_USE :
/* Set the media in use. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, UX_DEVICE_CLASS_RNDIS_MEDIA_802_3);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_HARDWARE_STATUS :
/* Set the hardware status. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, UX_DEVICE_CLASS_RNDIS_OID_HW_STATUS_READY);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_PHYSICAL_MEDIUM :
/* Set the physical medium. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, 0);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE :
/* Set the physical medium. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, UX_DEVICE_CLASS_RNDIS_MAX_PACKET_LENGTH);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_LINK_SPEED :
/* Set the link speed. For now we assume a full speed device. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, UX_DEVICE_CLASS_RNDIS_LINK_SPEED_FS);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_MEDIA_CONNECT_STATUS :
/* Set the media connection status. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, UX_DEVICE_CLASS_RNDIS_MEDIA_CONNECTED);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_MAC_OPTIONS :
/* Set the MAC options. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, UX_DEVICE_CLASS_RNDIS_MAC_OPTIONS);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_VENDOR_ID :
/* Set the vendor ID. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, rndis -> ux_slave_class_rndis_parameter.ux_slave_class_rndis_parameter_vendor_id);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_DRIVER_VERSION :
/* Set the driver version. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, rndis -> ux_slave_class_rndis_parameter.ux_slave_class_rndis_parameter_driver_version);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_VENDOR_DESCRIPTION :
/* Get the string length for the vendor description. */
status = _ux_utility_string_length_check(rndis -> ux_slave_class_rndis_parameter.ux_slave_class_rndis_parameter_vendor_description, &rndis_response_string_length, UX_DEVICE_CLASS_RNDIS_VENDOR_DESCRIPTION_MAX_LENGTH);
if (status)
return(status);
/* Set the total response length. */
rndis_response_length = (ULONG) rndis_response_string_length;
/* Copy the vendor description. */
_ux_utility_memory_copy(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, rndis -> ux_slave_class_rndis_parameter.ux_slave_class_rndis_parameter_vendor_description, rndis_response_length); /* Use case of memcpy is verified. */
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_XMIT_OK :
/* Set the appropriate statistic value. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, rndis -> ux_slave_class_rndis_statistics_xmit_ok);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_RCV_OK :
/* Set the appropriate statistic value. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, rndis -> ux_slave_class_rndis_statistics_rcv_ok);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_XMIT_ERROR :
/* Set the appropriate statistic value. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, rndis -> ux_slave_class_rndis_statistics_xmit_error);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_RCV_ERROR :
/* Set the appropriate statistic value. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, rndis -> ux_slave_class_rndis_statistics_rcv_error);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_GEN_RCV_NO_BUFFER :
/* Set the appropriate statistic value. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, rndis -> ux_slave_class_rndis_statistics_rcv_no_buffer);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
case UX_DEVICE_CLASS_RNDIS_OID_802_3_CURRENT_ADDRESS :
/* Save the Hardware address in the return message. */
_ux_utility_memory_copy(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER,
rndis -> ux_slave_class_rndis_remote_node_id, UX_DEVICE_CLASS_RNDIS_NODE_ID_LENGTH); /* Use case of memcpy is verified. */
/* Set the total response length. */
rndis_response_length = UX_DEVICE_CLASS_RNDIS_NODE_ID_LENGTH;
break;
case UX_DEVICE_CLASS_RNDIS_OID_802_3_PERMANENT_ADDRESS :
/* Save the Hardware address in the return message. */
_ux_utility_memory_copy(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER,
rndis -> ux_slave_class_rndis_remote_node_id,
UX_DEVICE_CLASS_RNDIS_NODE_ID_LENGTH); /* Use case of memcpy is verified. */
/* Set the total response length. */
rndis_response_length = UX_DEVICE_CLASS_RNDIS_NODE_ID_LENGTH;
break;
default :
/* Just return zero ULONG field. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER, 0);
/* Set the total response length. */
rndis_response_length = sizeof(ULONG);
break;
}
/* Set the status field. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_STATUS, status);
/* Set the buffer offset value. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER_OFFSET,
(UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER - UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_REQUEST_ID));
/* Store the length of the buffer. */
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER_LENGTH, rndis_response_length);
/* Update the response length to add the header. */
rndis_response_length += UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_INFO_BUFFER;
/* Set the response length. */
rndis -> ux_slave_class_rndis_response_length = rndis_response_length;
_ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_QUERY_MESSAGE_LENGTH, rndis_response_length);
/* We are done. Return UX_SUCCESS. */
return(status);
}
|