1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Device RNDIS Class                                                  */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define UX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "ux_api.h"
28 #include "ux_device_class_rndis.h"
29 #include "ux_device_stack.h"
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_device_class_rndis_msg_set                      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 SET                   */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    rndis                           Pointer to rndis class              */
48 /*    transfer_request                Pointer to the transfer request     */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    None                                                                */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    _ux_utility_long_get            Get 32-bit value                    */
57 /*    _ux_utility_long_put            Put 32-bit value                    */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    RNDIS Class                                                         */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
68 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
69 /*                                            resulting in version 6.1    */
70 /*                                                                        */
71 /**************************************************************************/
_ux_device_class_rndis_msg_set(UX_SLAVE_CLASS_RNDIS * rndis,UX_SLAVE_TRANSFER * transfer_request)72 UINT _ux_device_class_rndis_msg_set(UX_SLAVE_CLASS_RNDIS *rndis, UX_SLAVE_TRANSFER *transfer_request)
73 {
74 
75 UCHAR            *rndis_msg;
76 UCHAR            *rndis_response;
77 ULONG            rndis_oid;
78 ULONG            status;
79 
80     /* Get the pointer to the RNDIS message.  */
81     rndis_msg = transfer_request -> ux_slave_transfer_request_data_pointer;
82 
83     /* Get the request ID and keep it for the response.  */
84     rndis -> ux_slave_class_rndis_request_id =  _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_SET_REQUEST_ID);
85 
86     /* Get the OID.  */
87     rndis_oid = _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_SET_OID);
88 
89     /* If trace is enabled, insert this event into the trace buffer.  */
90     UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_RNDIS_MSG_SET, rndis, rndis_oid, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
91 
92     /* Now prepare the response.  */
93     rndis_response = rndis -> ux_slave_class_rndis_response;
94 
95     /* First store the command. */
96     _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_SET_MESSAGE_TYPE, UX_DEVICE_CLASS_RNDIS_CMPLT_SET);
97 
98     /* Store the request ID.  */
99     _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_SET_REQUEST_ID, rndis -> ux_slave_class_rndis_request_id);
100 
101     /* By default the function will succeed. */
102     status = UX_DEVICE_CLASS_RNDIS_STATUS_SUCCESS;
103 
104     /* What OID are we dealing here ? No need to treat OIDs but not sure so leave the code as is for now. */
105     switch (rndis_oid)
106     {
107 
108          case UX_DEVICE_CLASS_RNDIS_OID_GEN_SUPPORTED_LIST        :
109         case UX_DEVICE_CLASS_RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE    :
110         case UX_DEVICE_CLASS_RNDIS_OID_GEN_MEDIA_SUPPORTED         :
111         case UX_DEVICE_CLASS_RNDIS_OID_GEN_MEDIA_IN_USE            :
112         case UX_DEVICE_CLASS_RNDIS_OID_GEN_HARDWARE_STATUS        :
113         case UX_DEVICE_CLASS_RNDIS_OID_GEN_PHYSICAL_MEDIUM        :
114         case UX_DEVICE_CLASS_RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE    :
115         case UX_DEVICE_CLASS_RNDIS_OID_GEN_LINK_SPEED            :
116         case UX_DEVICE_CLASS_RNDIS_OID_GEN_MEDIA_CONNECT_STATUS    :
117         case UX_DEVICE_CLASS_RNDIS_OID_GEN_XMIT_OK                :
118         case UX_DEVICE_CLASS_RNDIS_OID_GEN_RCV_OK                :
119         case UX_DEVICE_CLASS_RNDIS_OID_GEN_XMIT_ERROR            :
120         case UX_DEVICE_CLASS_RNDIS_OID_GEN_RCV_ERROR            :
121         case UX_DEVICE_CLASS_RNDIS_OID_GEN_RCV_NO_BUFFER        :
122         default                                                    :
123         break;
124 
125     }
126 
127     /* Set the status field.  */
128     _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_SET_STATUS, status);
129 
130     /* Set the response length.  */
131     rndis -> ux_slave_class_rndis_response_length =   UX_DEVICE_CLASS_RNDIS_CMPLT_SET_RESPONSE_LENGTH;
132     _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_SET_MESSAGE_LENGTH, UX_DEVICE_CLASS_RNDIS_CMPLT_SET_RESPONSE_LENGTH);
133 
134     /* We are done. Return UX_SUCCESS.  */
135     return(status);
136 }
137 
138