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_entry PORTABLE C */ |
38 |
|
|
/* 6.1.11 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function is the entry point of the cdc_ecm class. It will be */ |
46 |
|
|
/* called by the USBX stack enumeration module when there is a new */ |
47 |
|
|
/* cdc_ecm ethernet device on the bus or when the it is removed. */ |
48 |
|
|
/* */ |
49 |
|
|
/* */ |
50 |
|
|
/* INPUT */ |
51 |
|
|
/* */ |
52 |
|
|
/* command CDC ECM class command */ |
53 |
|
|
/* */ |
54 |
|
|
/* OUTPUT */ |
55 |
|
|
/* */ |
56 |
|
|
/* Completion Status */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLS */ |
59 |
|
|
/* */ |
60 |
|
|
/* _ux_host_class_cdc_ecm_activate Activate cdc_ecm class */ |
61 |
|
|
/* _ux_host_class_cdc_ecm_deactivate Deactivate cdc_ecm class */ |
62 |
|
|
/* */ |
63 |
|
|
/* CALLED BY */ |
64 |
|
|
/* */ |
65 |
|
|
/* CDC ECM Class */ |
66 |
|
|
/* */ |
67 |
|
|
/**************************************************************************/ |
68 |
|
811 |
UINT _ux_host_class_cdc_ecm_entry(UX_HOST_CLASS_COMMAND *command) |
69 |
|
|
{ |
70 |
|
|
#if defined(UX_HOST_STANDALONE) |
71 |
|
|
UX_PARAMETER_NOT_USED(command); |
72 |
|
|
return(UX_FUNCTION_NOT_SUPPORTED); |
73 |
|
|
#else |
74 |
|
|
|
75 |
|
|
UINT status; |
76 |
|
|
|
77 |
|
|
|
78 |
|
|
/* The command request will tell us we need to do here, either a enumeration |
79 |
|
|
query, an activation or a deactivation. */ |
80 |
✓✓✓✓
|
811 |
switch (command -> ux_host_class_command_request) |
81 |
|
|
{ |
82 |
|
|
|
83 |
|
510 |
case UX_HOST_CLASS_COMMAND_QUERY: |
84 |
|
|
|
85 |
|
|
/* The query command is used to let the stack enumeration process know if we want to own |
86 |
|
|
this device or not. */ |
87 |
✓✓ |
510 |
if(command -> ux_host_class_command_usage == UX_HOST_CLASS_COMMAND_USAGE_CSP) |
88 |
|
|
{ |
89 |
|
|
|
90 |
|
|
/* We are in CSP mode. Check if CDC-ECM Control or Data. */ |
91 |
✓✓✓✓
|
258 |
if (((command -> ux_host_class_command_class == UX_HOST_CLASS_CDC_DATA_CLASS) && (command -> ux_host_class_command_subclass == 0)) || |
92 |
✓✓ |
132 |
((command -> ux_host_class_command_class == UX_HOST_CLASS_CDC_CONTROL_CLASS) && |
93 |
✓✓ |
127 |
(command -> ux_host_class_command_subclass == UX_HOST_CLASS_CDC_ECM_CONTROL_SUBCLASS))) |
94 |
|
|
{ |
95 |
|
|
/* Check for IAD presence. */ |
96 |
✓✓✓✓
|
252 |
if ((command -> ux_host_class_command_iad_class == 0) && (command -> ux_host_class_command_iad_subclass == 0)) |
97 |
|
|
|
98 |
|
|
/* No IAD, we accept this class. */ |
99 |
|
3 |
return(UX_SUCCESS); |
100 |
|
|
|
101 |
|
|
else |
102 |
|
|
{ |
103 |
|
|
|
104 |
✓✓ |
249 |
if ((command -> ux_host_class_command_iad_class == UX_HOST_CLASS_CDC_CONTROL_CLASS) && |
105 |
✓✓ |
247 |
(command -> ux_host_class_command_iad_subclass == UX_HOST_CLASS_CDC_ECM_CONTROL_SUBCLASS)) |
106 |
|
|
|
107 |
|
|
/* There is an IAD and this is for CDC-ACM. */ |
108 |
|
246 |
return(UX_SUCCESS); |
109 |
|
|
|
110 |
|
|
else |
111 |
|
|
|
112 |
|
|
/* The IAD does not match with CDC-ACM. */ |
113 |
|
3 |
return(UX_NO_CLASS_MATCH); |
114 |
|
|
} |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
/* Not CDC-ECM control or data class. */ |
118 |
|
6 |
return(UX_NO_CLASS_MATCH); |
119 |
|
|
|
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
else |
123 |
|
|
|
124 |
|
|
/* No match. */ |
125 |
|
252 |
return(UX_NO_CLASS_MATCH); |
126 |
|
|
|
127 |
|
247 |
case UX_HOST_CLASS_COMMAND_ACTIVATE: |
128 |
|
|
|
129 |
|
|
/* The activate command is used when the device inserted has found a parent and |
130 |
|
|
is ready to complete the enumeration. */ |
131 |
|
247 |
status = _ux_host_class_cdc_ecm_activate(command); |
132 |
|
247 |
return(status); |
133 |
|
|
|
134 |
|
53 |
case UX_HOST_CLASS_COMMAND_DEACTIVATE: |
135 |
|
|
|
136 |
|
|
/* The deactivate command is used when the device has been extracted either |
137 |
|
|
directly or when its parents has been extracted. */ |
138 |
|
53 |
status = _ux_host_class_cdc_ecm_deactivate(command); |
139 |
|
53 |
return(status); |
140 |
|
|
|
141 |
|
1 |
default: |
142 |
|
|
|
143 |
|
|
/* Error trap. */ |
144 |
|
1 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED); |
145 |
|
|
|
146 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
147 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0) |
148 |
|
|
|
149 |
|
1 |
return(UX_FUNCTION_NOT_SUPPORTED); |
150 |
|
|
} |
151 |
|
|
#endif |
152 |
|
|
} |
153 |
|
|
|