1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** USBX Component */
17 /** */
18 /** Asix 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_asix.h"
30 #include "ux_host_stack.h"
31
32
33 #if !defined(UX_HOST_STANDALONE)
34 static inline UINT _ux_host_class_asix_try_all_vid_pids(UX_HOST_CLASS_COMMAND *command);
35 #endif
36
37
38 /**************************************************************************/
39 /* */
40 /* FUNCTION RELEASE */
41 /* */
42 /* _ux_host_class_asix_entry PORTABLE C */
43 /* 6.2.0 */
44 /* AUTHOR */
45 /* */
46 /* Chaoqiong Xiao, Microsoft Corporation */
47 /* */
48 /* DESCRIPTION */
49 /* */
50 /* This function is the entry point of the asix class. It will be */
51 /* called by the USBX stack enumeration module when there is a new */
52 /* asix ethernet device on the bus or when the it is removed. */
53 /* */
54 /* */
55 /* INPUT */
56 /* */
57 /* command Asix class command */
58 /* */
59 /* OUTPUT */
60 /* */
61 /* Completion Status */
62 /* */
63 /* CALLS */
64 /* */
65 /* _ux_host_class_asix_activate Activate asix class */
66 /* _ux_host_class_asix_deactivate Deactivate asix class */
67 /* */
68 /* CALLED BY */
69 /* */
70 /* Asix Class */
71 /* */
72 /* RELEASE HISTORY */
73 /* */
74 /* DATE NAME DESCRIPTION */
75 /* */
76 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
77 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
78 /* resulting in version 6.1 */
79 /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */
80 /* fixed standalone compile, */
81 /* resulting in version 6.1.11 */
82 /* 10-31-2022 Chaoqiong Xiao Modified comment(s), */
83 /* fixed compile warning, */
84 /* refined VID/PID check flow, */
85 /* resulting in version 6.2.0 */
86 /* */
87 /**************************************************************************/
_ux_host_class_asix_entry(UX_HOST_CLASS_COMMAND * command)88 UINT _ux_host_class_asix_entry(UX_HOST_CLASS_COMMAND *command)
89 {
90 #if defined(UX_HOST_STANDALONE)
91 UX_PARAMETER_NOT_USED(command);
92 return(UX_FUNCTION_NOT_SUPPORTED);
93 #else
94
95 UINT status;
96
97
98 /* The command request will tell us we need to do here, either a enumeration
99 query, an activation or a deactivation. */
100 switch (command -> ux_host_class_command_request)
101 {
102
103 case UX_HOST_CLASS_COMMAND_QUERY:
104
105 /* The query command is used to let the stack enumeration process know if we want to own
106 this device or not. */
107 if(command -> ux_host_class_command_usage == UX_HOST_CLASS_COMMAND_USAGE_PIDVID)
108 {
109 if (_ux_host_class_asix_try_all_vid_pids(command) == UX_SUCCESS)
110 return(UX_SUCCESS);
111 }
112
113 /* No match. */
114 return(UX_NO_CLASS_MATCH);
115
116 case UX_HOST_CLASS_COMMAND_ACTIVATE:
117
118 /* The activate command is used when the device inserted has found a parent and
119 is ready to complete the enumeration. */
120 status = _ux_host_class_asix_activate(command);
121 return(status);
122
123 case UX_HOST_CLASS_COMMAND_DEACTIVATE:
124
125 /* The deactivate command is used when the device has been extracted either
126 directly or when its parents has been extracted. */
127 status = _ux_host_class_asix_deactivate(command);
128 return(status);
129
130 default:
131
132 /* Error trap. */
133 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
134
135 /* If trace is enabled, insert this event into the trace buffer. */
136 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
137
138 return(UX_FUNCTION_NOT_SUPPORTED);
139 }
140 #endif
141 }
142 #if !defined(UX_HOST_STANDALONE)
143 static const USHORT _ux_host_class_asix_vid_pid_array[] =
144 {
145 UX_HOST_CLASS_ASIX_VID_PID_ARRAY
146 };
147
_ux_host_class_asix_try_all_vid_pids(UX_HOST_CLASS_COMMAND * command)148 static inline UINT _ux_host_class_asix_try_all_vid_pids(UX_HOST_CLASS_COMMAND *command)
149 {
150 UINT i, pos;
151 UINT n_ids = sizeof(_ux_host_class_asix_vid_pid_array) >> 1;
152 UINT n_id_pairs = n_ids >> 1;
153 for (i = 0, pos = 0; i < n_id_pairs; i ++, pos += 2)
154 {
155 if ((command -> ux_host_class_command_pid == _ux_host_class_asix_vid_pid_array[pos + 1]) &&
156 (command -> ux_host_class_command_vid == _ux_host_class_asix_vid_pid_array[pos ]))
157 return(UX_SUCCESS);
158 }
159 return(UX_NO_CLASS_MATCH);
160 }
161 #endif
162