1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** USBX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** CDC ECM Class */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
/**************************************************************************/ |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#define UX_SOURCE_CODE |
27 |
|
|
|
28 |
|
|
#include "ux_api.h" |
29 |
|
|
#include "ux_host_class_cdc_ecm.h" |
30 |
|
|
#include "ux_host_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_host_class_cdc_ecm_interrupt_notification PORTABLE C */ |
38 |
|
|
/* 6.1.11 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function is called by the stack when an interrupt packet as */ |
46 |
|
|
/* been received. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* transfer_request Pointer to transfer request */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* None */ |
55 |
|
|
/* */ |
56 |
|
|
/* CALLS */ |
57 |
|
|
/* */ |
58 |
|
|
/* None */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLED BY */ |
61 |
|
|
/* */ |
62 |
|
|
/* USBX stack */ |
63 |
|
|
/* */ |
64 |
|
|
/**************************************************************************/ |
65 |
|
114 |
VOID _ux_host_class_cdc_ecm_interrupt_notification(UX_TRANSFER *transfer_request) |
66 |
|
|
{ |
67 |
|
|
|
68 |
|
|
UX_HOST_CLASS_CDC_ECM *cdc_ecm; |
69 |
|
|
ULONG notification_type; |
70 |
|
|
ULONG notification_value; |
71 |
|
|
|
72 |
|
|
|
73 |
|
|
/* Get the control class instance for this transfer request. */ |
74 |
|
114 |
cdc_ecm = (UX_HOST_CLASS_CDC_ECM *) transfer_request -> ux_transfer_request_class_instance; |
75 |
|
|
|
76 |
|
|
/* Check the state of the transfer. If there is an error, we do not proceed with this notification. */ |
77 |
✓✓ |
114 |
if (transfer_request -> ux_transfer_request_completion_code != UX_SUCCESS) |
78 |
|
|
|
79 |
|
|
/* We do not proceed. */ |
80 |
|
50 |
return; |
81 |
|
|
|
82 |
|
|
/* Check if the class is in shutdown. */ |
83 |
✓✓ |
64 |
if (cdc_ecm -> ux_host_class_cdc_ecm_state == UX_HOST_CLASS_INSTANCE_SHUTDOWN) |
84 |
|
|
|
85 |
|
|
/* We do not proceed. */ |
86 |
|
1 |
return; |
87 |
|
|
|
88 |
|
|
/* Increment the notification count. */ |
89 |
|
63 |
cdc_ecm -> ux_host_class_cdc_ecm_notification_count++; |
90 |
|
|
|
91 |
|
|
/* Get the notification. */ |
92 |
|
63 |
notification_type = (ULONG) *(transfer_request -> ux_transfer_request_data_pointer + UX_HOST_CLASS_CDC_ECM_NPF_NOTIFICATION_TYPE); |
93 |
|
|
|
94 |
|
|
/* And the value. */ |
95 |
|
63 |
notification_value = (ULONG) *(transfer_request -> ux_transfer_request_data_pointer + UX_HOST_CLASS_CDC_ECM_NPF_VALUE); |
96 |
|
|
|
97 |
|
|
/* Check if the notification is a Network notification. */ |
98 |
✓✓ |
63 |
if (notification_type == UX_HOST_CLASS_CDC_ECM_NOTIFICATION_NETWORK_CONNECTION) |
99 |
|
|
{ |
100 |
|
|
|
101 |
|
|
/* Check the state of the link. */ |
102 |
✓✓ |
62 |
if (notification_value == UX_HOST_CLASS_CDC_ECM_NOTIFICATION_NETWORK_LINK_UP) |
103 |
|
|
{ |
104 |
|
|
|
105 |
|
|
/* Link is up. See if we know about that. */ |
106 |
✓✓ |
51 |
if (cdc_ecm -> ux_host_class_cdc_ecm_link_state != UX_HOST_CLASS_CDC_ECM_LINK_STATE_UP && |
107 |
✓✓ |
50 |
cdc_ecm -> ux_host_class_cdc_ecm_link_state != UX_HOST_CLASS_CDC_ECM_LINK_STATE_PENDING_UP) |
108 |
|
|
{ |
109 |
|
|
|
110 |
|
|
/* Memorize the new link state. */ |
111 |
|
49 |
cdc_ecm -> ux_host_class_cdc_ecm_link_state = UX_HOST_CLASS_CDC_ECM_LINK_STATE_PENDING_UP; |
112 |
|
|
|
113 |
|
|
/* We need to inform the cdc_ecm thread of this change. */ |
114 |
|
49 |
_ux_host_semaphore_put(&cdc_ecm -> ux_host_class_cdc_ecm_interrupt_notification_semaphore); |
115 |
|
|
} |
116 |
|
|
} |
117 |
|
|
else |
118 |
|
|
{ |
119 |
|
|
|
120 |
|
|
/* Link is down. See if we know about that. */ |
121 |
✓✓ |
11 |
if (cdc_ecm -> ux_host_class_cdc_ecm_link_state != UX_HOST_CLASS_CDC_ECM_LINK_STATE_DOWN && |
122 |
✓✓ |
9 |
cdc_ecm -> ux_host_class_cdc_ecm_link_state != UX_HOST_CLASS_CDC_ECM_LINK_STATE_PENDING_DOWN) |
123 |
|
|
{ |
124 |
|
|
|
125 |
|
|
/* We need to abort any transfers on the bulk in endpoint. */ |
126 |
|
|
|
127 |
|
|
/* Make sure no one does any more transfers. */ |
128 |
|
8 |
cdc_ecm -> ux_host_class_cdc_ecm_link_state = UX_HOST_CLASS_CDC_ECM_LINK_STATE_PENDING_DOWN; |
129 |
|
|
|
130 |
|
|
/* Now abort all transfers. It's possible we're executing right before the transfer |
131 |
|
|
is armed. If this is the case, then the transfer will not be aborted if we do the abort right now; instead, |
132 |
|
|
we should wait until after the transfer is armed. We must look at the CDC-ECM thread's state. */ |
133 |
|
|
|
134 |
|
|
/* Is it in the process of checking the link state and arming the transfer? */ |
135 |
✓✓ |
8 |
if (cdc_ecm -> ux_host_class_cdc_ecm_bulk_in_transfer_check_and_arm_in_process == UX_TRUE) |
136 |
|
|
{ |
137 |
|
|
|
138 |
|
|
/* Yes. We must wait for it to finish arming the transfer. */ |
139 |
|
|
|
140 |
|
|
/* Let the CDC-ECM thread know we're waiting so it can wake us up. */ |
141 |
|
1 |
cdc_ecm -> ux_host_class_cdc_ecm_bulk_in_transfer_waiting_for_check_and_arm_to_finish = UX_TRUE; |
142 |
|
|
|
143 |
|
|
/* Wait for the transfer to be armed, or possibly an error. The CDC-ECM thread will wake us up. */ |
144 |
|
1 |
_ux_host_semaphore_get_norc(&cdc_ecm -> ux_host_class_cdc_ecm_bulk_in_transfer_waiting_for_check_and_arm_to_finish_semaphore, UX_WAIT_FOREVER); |
145 |
|
|
|
146 |
|
|
/* We're no longer waiting. */ |
147 |
|
1 |
cdc_ecm -> ux_host_class_cdc_ecm_bulk_in_transfer_waiting_for_check_and_arm_to_finish = UX_FALSE; |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
/* Now we can abort the transfer. */ |
151 |
|
8 |
_ux_host_stack_transfer_request_abort(&cdc_ecm -> ux_host_class_cdc_ecm_bulk_in_endpoint -> ux_endpoint_transfer_request); |
152 |
|
|
|
153 |
|
|
/* We need to inform the CDC-ECM thread of this change. */ |
154 |
|
8 |
_ux_host_semaphore_put(&cdc_ecm -> ux_host_class_cdc_ecm_interrupt_notification_semaphore); |
155 |
|
|
} |
156 |
|
|
} |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
/* Reactivate the CDC_ECM interrupt pipe. */ |
160 |
|
63 |
_ux_host_stack_transfer_request(transfer_request); |
161 |
|
|
|
162 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
163 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_CDC_ECM_INTERRUPT_NOTIFICATION, cdc_ecm, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) |
164 |
|
|
|
165 |
|
|
/* Return to caller. */ |
166 |
|
63 |
return; |
167 |
|
|
} |
168 |
|
|
|