1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11 /**************************************************************************/
12 /**************************************************************************/
13 /** */
14 /** USBX Component */
15 /** */
16 /** Device RNDIS Class */
17 /** */
18 /**************************************************************************/
19 /**************************************************************************/
20
21 #define UX_SOURCE_CODE
22
23
24 /* Include necessary system files. */
25
26 #include "ux_api.h"
27 #include "ux_device_class_rndis.h"
28 #include "ux_device_stack.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_device_class_rndis_msg_initialize PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function analyzes and replies to the MSG INITIALIZE */
44 /* endpoints with a CLASS or VENDOR SPECIFIC type. */
45 /* */
46 /* INPUT */
47 /* */
48 /* rndis Pointer to rndis class */
49 /* transfer_request Pointer to the transfer request */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* None */
54 /* */
55 /* CALLS */
56 /* */
57 /* _ux_utility_long_get Get 32-bit value */
58 /* _ux_utility_long_put Put 32-bit value */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* RNDIS Class */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
69 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
70 /* resulting in version 6.1 */
71 /* */
72 /**************************************************************************/
_ux_device_class_rndis_msg_initialize(UX_SLAVE_CLASS_RNDIS * rndis,UX_SLAVE_TRANSFER * transfer_request)73 UINT _ux_device_class_rndis_msg_initialize(UX_SLAVE_CLASS_RNDIS *rndis, UX_SLAVE_TRANSFER *transfer_request)
74 {
75
76 UCHAR *rndis_msg;
77 UCHAR *rndis_response;
78
79 /* Get the pointer to the RNDIS message. */
80 rndis_msg = transfer_request -> ux_slave_transfer_request_data_pointer;
81
82 /* Get the request ID and keep it for the response. */
83 rndis -> ux_slave_class_rndis_request_id = _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_INITIALIZE_REQUEST_ID);
84
85 /* Get the major version and store it into the RNDIS instance. */
86 rndis -> ux_slave_class_rndis_major_version = _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_INITIALIZE_MAJOR_VERSION);
87
88 /* Get the minor version and store it into the RNDIS instance. */
89 rndis -> ux_slave_class_rndis_minor_version = _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_INITIALIZE_MINOR_VERSION);
90
91 /* Get the max transfer size and store it into the RNDIS instance. */
92 rndis -> ux_slave_class_rndis_max_transfer_size = _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_INITIALIZE_MAX_TRANSFER_SIZE);
93
94 /* Store the state machine to initialized. */
95 rndis -> ux_slave_class_rndis_state = UX_DEVICE_CLASS_RNDIS_STATE_INITIALIZED;
96
97 /* Now prepare the response. */
98 rndis_response = rndis -> ux_slave_class_rndis_response;
99
100 /* First store the command. */
101 _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MESSAGE_TYPE, UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE);
102
103 /* Then the length of the response. */
104 _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MESSAGE_LENGTH, UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_RESPONSE_LENGTH);
105
106 /* Store the request ID. */
107 _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_REQUEST_ID, rndis -> ux_slave_class_rndis_request_id);
108
109 /* Force the status to SUCCESS. */
110 _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_STATUS, UX_DEVICE_CLASS_RNDIS_STATUS_SUCCESS);
111
112 /* Set the major version of the device */
113 _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MAJOR_VERSION, UX_DEVICE_CLASS_RNDIS_VERSION_MAJOR);
114
115 /* Set the minor version of the device */
116 _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MINOR_VERSION, UX_DEVICE_CLASS_RNDIS_VERSION_MINOR);
117
118 /* Set the type of connection supported. */
119 _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_DEVICE_FLAGS, UX_DEVICE_CLASS_RNDIS_DF_CONNECTION_SUPPORTED);
120
121 /* Set the type of media supported. */
122 _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MEDIUM, UX_DEVICE_CLASS_RNDIS_MEDIUM_SUPPORTED);
123
124 /* Set the max packet per transfer. */
125 _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MAX_PACKETS_PER_TRANSFER, UX_DEVICE_CLASS_RNDIS_MAX_PACKET_PER_TRANSFER);
126
127 /* Set the max transfer size. */
128 _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MAX_TRANSFER_SIZE, UX_DEVICE_CLASS_RNDIS_MAX_PACKET_TRANSFER_SIZE);
129
130 /* Set the packet alignment factor. */
131 _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_PACKET_ALIGNMENT, UX_DEVICE_CLASS_RNDIS_PACKET_ALIGNEMENT_FACTOR);
132
133 /* Set AFListOffset and AFListSize fields to 0. */
134 _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_AFL_LIST_OFFSET, 0);
135 _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_AFL_LIST_SIZE, 0);
136
137 /* Set the response length. */
138 rndis -> ux_slave_class_rndis_response_length = UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_RESPONSE_LENGTH;
139
140 /* We are done. Return UX_SUCCESS. */
141 return(UX_SUCCESS);
142 }
143
144