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