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 /**   Generic Serial Host module 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_gser.h"
29 #include "ux_host_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_host_class_gser_entry                           PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function is the entry point of the gser class. It will be      */
45 /*    called by the USBX stack enumeration module when there is a new     */
46 /*    gser on the bus or when the USB gser is removed.                    */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    command                                     gser class command      */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    Completion Status                                                   */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _ux_host_class_gser_activate         Activate gser class            */
59 /*    _ux_host_class_gser_deactivate       Deactivate gser class          */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Data pump Class                                                     */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
70 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*                                                                        */
73 /**************************************************************************/
_ux_host_class_gser_entry(UX_HOST_CLASS_COMMAND * command)74 UINT  _ux_host_class_gser_entry(UX_HOST_CLASS_COMMAND *command)
75 {
76 
77 UINT    status;
78 
79 
80     /* The command request will tell us we need to do here, either a enumeration
81        query, an activation or a deactivation.  */
82     switch (command -> ux_host_class_command_request)
83     {
84 
85     case UX_HOST_CLASS_COMMAND_QUERY:
86 
87         /* The query command is used to let the stack enumeration process know if we want to own
88            this device or not.  */
89         if(((command -> ux_host_class_command_usage == UX_HOST_CLASS_COMMAND_USAGE_PIDVID) &&
90                              (command -> ux_host_class_command_pid == UX_HOST_CLASS_GSER_PRODUCT_ID) &&
91                              (command -> ux_host_class_command_vid == UX_HOST_CLASS_GSER_VENDOR_ID )))
92             return(UX_SUCCESS);
93         else
94             return(UX_NO_CLASS_MATCH);
95 
96     case UX_HOST_CLASS_COMMAND_ACTIVATE:
97 
98         /* The activate command is used when the device inserted has found a parent and
99            is ready to complete the enumeration.  */
100         status =  _ux_host_class_gser_activate(command);
101         return(status);
102 
103     case UX_HOST_CLASS_COMMAND_DEACTIVATE:
104 
105         /* The deactivate command is used when the device has been extracted either
106            directly or when its parents has been extracted.  */
107         status =  _ux_host_class_gser_deactivate(command);
108         return(status);
109 
110     default:
111 
112         /* Error trap. */
113         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
114 
115         /* If trace is enabled, insert this event into the trace buffer.  */
116         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
117 
118         return(UX_FUNCTION_NOT_SUPPORTED);
119     }
120 }
121 
122