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_keep_alive               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 KEEP_ALIVE            */
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_keep_alive(UX_SLAVE_CLASS_RNDIS * rndis,UX_SLAVE_TRANSFER * transfer_request)72 UINT  _ux_device_class_rndis_msg_keep_alive(UX_SLAVE_CLASS_RNDIS *rndis, UX_SLAVE_TRANSFER *transfer_request)
73 {
74 
75 UCHAR            *rndis_msg;
76 UCHAR            *rndis_response;
77 
78     /* If trace is enabled, insert this event into the trace buffer.  */
79     UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_RNDIS_MSG_KEEP_ALIVE, rndis, 0, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
80 
81     /* Get the pointer to the RNDIS message.  */
82     rndis_msg = transfer_request -> ux_slave_transfer_request_data_pointer;
83 
84     /* Get the request ID and keep it for the response.  */
85     rndis -> ux_slave_class_rndis_request_id =  _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_KEEP_ALIVE_REQUEST_ID);
86 
87     /* Now prepare the response.  */
88     rndis_response = rndis -> ux_slave_class_rndis_response;
89 
90     /* First store the command. */
91     _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_KEEP_ALIVE_MESSAGE_TYPE, UX_DEVICE_CLASS_RNDIS_CMPLT_KEEP_ALIVE);
92 
93     /* Then the length of the response. */
94     _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_KEEP_ALIVE_MESSAGE_LENGTH, UX_DEVICE_CLASS_RNDIS_CMPLT_KEEP_ALIVE_RESPONSE_LENGTH);
95 
96     /* Store the request ID.  */
97     _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_KEEP_ALIVE_REQUEST_ID, rndis -> ux_slave_class_rndis_request_id);
98 
99     /* Force the status to SUCCESS.  */
100     _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_KEEP_ALIVE_STATUS, UX_DEVICE_CLASS_RNDIS_STATUS_SUCCESS);
101 
102     /* Set the response length.  */
103     rndis -> ux_slave_class_rndis_response_length =   UX_DEVICE_CLASS_RNDIS_CMPLT_KEEP_ALIVE_RESPONSE_LENGTH;
104 
105     /* We are done. Return UX_SUCCESS.  */
106     return(UX_SUCCESS);
107 }
108 
109