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 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _ux_device_class_rndis_msg_set                      PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Chaoqiong Xiao, Microsoft Corporation                               */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This function analyzes and replies to the MSG SET                   */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    rndis                           Pointer to rndis class              */
47 /*    transfer_request                Pointer to the transfer request     */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    None                                                                */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    _ux_utility_long_get            Get 32-bit value                    */
56 /*    _ux_utility_long_put            Put 32-bit value                    */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    RNDIS Class                                                         */
61 /*                                                                        */
62 /*  RELEASE HISTORY                                                       */
63 /*                                                                        */
64 /*    DATE              NAME                      DESCRIPTION             */
65 /*                                                                        */
66 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
67 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
68 /*                                            resulting in version 6.1    */
69 /*                                                                        */
70 /**************************************************************************/
_ux_device_class_rndis_msg_set(UX_SLAVE_CLASS_RNDIS * rndis,UX_SLAVE_TRANSFER * transfer_request)71 UINT _ux_device_class_rndis_msg_set(UX_SLAVE_CLASS_RNDIS *rndis, UX_SLAVE_TRANSFER *transfer_request)
72 {
73 
74 UCHAR            *rndis_msg;
75 UCHAR            *rndis_response;
76 ULONG            rndis_oid;
77 ULONG            status;
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_SET_REQUEST_ID);
84 
85     /* Get the OID.  */
86     rndis_oid = _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_SET_OID);
87 
88     /* If trace is enabled, insert this event into the trace buffer.  */
89     UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_RNDIS_MSG_SET, rndis, rndis_oid, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
90 
91     /* Now prepare the response.  */
92     rndis_response = rndis -> ux_slave_class_rndis_response;
93 
94     /* First store the command. */
95     _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_SET_MESSAGE_TYPE, UX_DEVICE_CLASS_RNDIS_CMPLT_SET);
96 
97     /* Store the request ID.  */
98     _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_SET_REQUEST_ID, rndis -> ux_slave_class_rndis_request_id);
99 
100     /* By default the function will succeed. */
101     status = UX_DEVICE_CLASS_RNDIS_STATUS_SUCCESS;
102 
103     /* What OID are we dealing here ? No need to treat OIDs but not sure so leave the code as is for now. */
104     switch (rndis_oid)
105     {
106 
107          case UX_DEVICE_CLASS_RNDIS_OID_GEN_SUPPORTED_LIST        :
108         case UX_DEVICE_CLASS_RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE    :
109         case UX_DEVICE_CLASS_RNDIS_OID_GEN_MEDIA_SUPPORTED         :
110         case UX_DEVICE_CLASS_RNDIS_OID_GEN_MEDIA_IN_USE            :
111         case UX_DEVICE_CLASS_RNDIS_OID_GEN_HARDWARE_STATUS        :
112         case UX_DEVICE_CLASS_RNDIS_OID_GEN_PHYSICAL_MEDIUM        :
113         case UX_DEVICE_CLASS_RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE    :
114         case UX_DEVICE_CLASS_RNDIS_OID_GEN_LINK_SPEED            :
115         case UX_DEVICE_CLASS_RNDIS_OID_GEN_MEDIA_CONNECT_STATUS    :
116         case UX_DEVICE_CLASS_RNDIS_OID_GEN_XMIT_OK                :
117         case UX_DEVICE_CLASS_RNDIS_OID_GEN_RCV_OK                :
118         case UX_DEVICE_CLASS_RNDIS_OID_GEN_XMIT_ERROR            :
119         case UX_DEVICE_CLASS_RNDIS_OID_GEN_RCV_ERROR            :
120         case UX_DEVICE_CLASS_RNDIS_OID_GEN_RCV_NO_BUFFER        :
121         default                                                    :
122         break;
123 
124     }
125 
126     /* Set the status field.  */
127     _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_SET_STATUS, status);
128 
129     /* Set the response length.  */
130     rndis -> ux_slave_class_rndis_response_length =   UX_DEVICE_CLASS_RNDIS_CMPLT_SET_RESPONSE_LENGTH;
131     _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_SET_MESSAGE_LENGTH, UX_DEVICE_CLASS_RNDIS_CMPLT_SET_RESPONSE_LENGTH);
132 
133     /* We are done. Return UX_SUCCESS.  */
134     return(status);
135 }
136 
137