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_deactivate PORTABLE C */
36 /* 6.1.12 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function deactivate an instance of the rndis class. */
44 /* */
45 /* INPUT */
46 /* */
47 /* command Pointer to a class command */
48 /* */
49 /* OUTPUT */
50 /* */
51 /* Completion Status */
52 /* */
53 /* CALLS */
54 /* */
55 /* _ux_device_stack_transfer_all_request_abort */
56 /* Abort all transfers */
57 /* _ux_device_event_flags_set Set event flags */
58 /* _ux_network_driver_deactivate Deactivate NetX USB interface */
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 /* used UX prefix to refer to */
71 /* TX symbols instead of using */
72 /* them directly, */
73 /* resulting in version 6.1 */
74 /* 08-02-2021 Wen Wang Modified comment(s), */
75 /* fixed spelling error, */
76 /* resulting in version 6.1.8 */
77 /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */
78 /* fixed standalone compile, */
79 /* resulting in version 6.1.11 */
80 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
81 /* fixed parameter/variable */
82 /* names conflict C++ keyword, */
83 /* resulting in version 6.1.12 */
84 /* */
85 /**************************************************************************/
_ux_device_class_rndis_deactivate(UX_SLAVE_CLASS_COMMAND * command)86 UINT _ux_device_class_rndis_deactivate(UX_SLAVE_CLASS_COMMAND *command)
87 {
88
89 UX_SLAVE_CLASS_RNDIS *rndis;
90 UX_SLAVE_INTERFACE *interface_ptr;
91 UX_SLAVE_CLASS *class_ptr;
92
93 /* Get the class container. */
94 class_ptr = command -> ux_slave_class_command_class_ptr;
95
96 /* Get the class instance in the container. */
97 rndis = (UX_SLAVE_CLASS_RNDIS *) class_ptr -> ux_slave_class_instance;
98
99 /* Get the interface that owns this instance. Normally the interface can be derived
100 from the class instance but since RNDIS has 2 interfaces and we only store the Control
101 interface in the class container, we used the class_command pointer to retrieve the
102 correct interface which issued the deactivation. */
103 interface_ptr = (UX_SLAVE_INTERFACE *) command -> ux_slave_class_command_interface;
104
105 /* Check if this is the Control or Data interface. We only need to dismount the link and abort the
106 transfer once for the 2 classes. */
107 if (interface_ptr -> ux_slave_interface_descriptor.bInterfaceClass == UX_DEVICE_CLASS_RNDIS_CLASS_COMMUNICATION_CONTROL)
108 {
109
110 /* Declare the link to be down. That may need to change later to make it dependant on the
111 WAN/Wireless modem. */
112 rndis -> ux_slave_class_rndis_link_state = UX_DEVICE_CLASS_RNDIS_LINK_STATE_DOWN;
113
114 /* Terminate the transactions pending on the endpoints (interrupt, bulk in, bulk out). */
115 _ux_device_stack_transfer_all_request_abort(rndis -> ux_slave_class_rndis_interrupt_endpoint, UX_TRANSFER_BUS_RESET);
116 _ux_device_stack_transfer_all_request_abort(rndis -> ux_slave_class_rndis_bulkin_endpoint, UX_TRANSFER_BUS_RESET);
117 _ux_device_stack_transfer_all_request_abort(rndis -> ux_slave_class_rndis_bulkout_endpoint, UX_TRANSFER_BUS_RESET);
118
119 /* We have 2 threads waiting for an event, interrupt and bulk in. We wake them up with
120 a DEVICE_STATE_CHANGE event. In turn they will release the NetX resources used and suspend. */
121 _ux_device_event_flags_set(&rndis -> ux_slave_class_rndis_event_flags_group, UX_DEVICE_CLASS_RNDIS_NEW_DEVICE_STATE_CHANGE_EVENT, UX_OR);
122
123 /* If there is a deactivate function call it. */
124 if (rndis -> ux_slave_class_rndis_parameter.ux_slave_class_rndis_instance_deactivate != UX_NULL)
125
126 /* Invoke the application. */
127 rndis -> ux_slave_class_rndis_parameter.ux_slave_class_rndis_instance_deactivate(rndis);
128
129 /* Deregister this interface to the NetX USB interface broker. */
130 _ux_network_driver_deactivate((VOID *) rndis, rndis -> ux_slave_class_rndis_network_handle);
131
132 }
133
134 /* If trace is enabled, insert this event into the trace buffer. */
135 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_RNDIS_DEACTIVATE, rndis, 0, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
136
137 /* If trace is enabled, register this object. */
138 UX_TRACE_OBJECT_UNREGISTER(rndis);
139
140 /* Return completion status. */
141 return(UX_SUCCESS);
142 }
143
144