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 /**   Pima 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_pima.h"
29 #include "ux_host_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_host_class_pima_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 pima class. It will be      */
45 /*    called by the USBX stack enumeration module when there is a new     */
46 /*    pima on the bus or when the USB pima is removed.                    */
47 /*                                                                        */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    command                                  Pima class command         */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    Completion Status                                                   */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _ux_host_class_pima_activate             Activate pima class        */
60 /*    _ux_host_class_pima_deactivate           Deactivate pima class      */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    USBX stack                                                          */
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 /*                                                                        */
74 /**************************************************************************/
_ux_host_class_pima_entry(UX_HOST_CLASS_COMMAND * command)75 UINT  _ux_host_class_pima_entry(UX_HOST_CLASS_COMMAND *command)
76 {
77 
78 UINT    status;
79 
80 
81     /* The command request will tell us we need to do here, either a enumeration
82        query, an activation or a deactivation.  */
83     switch (command -> ux_host_class_command_request)
84     {
85 
86     case UX_HOST_CLASS_COMMAND_QUERY:
87 
88         /* The query command is used to let the stack enumeration process know if we want to own
89            this device or not.  */
90         if((command -> ux_host_class_command_usage == UX_HOST_CLASS_COMMAND_USAGE_CSP) &&
91                              ((command -> ux_host_class_command_class == UX_HOST_CLASS_PIMA_CLASS) &&
92                              (command -> ux_host_class_command_subclass == UX_HOST_CLASS_PIMA_SUBCLASS) &&
93                              (command -> ux_host_class_command_protocol == UX_HOST_CLASS_PIMA_PROTOCOL)))
94             return(UX_SUCCESS);
95         else
96             return(UX_NO_CLASS_MATCH);
97 
98     case UX_HOST_CLASS_COMMAND_ACTIVATE:
99 
100         /* The activate command is used when the device inserted has found a parent and
101            is ready to complete the enumeration.  */
102         status =  _ux_host_class_pima_activate(command);
103         return(status);
104 
105     case UX_HOST_CLASS_COMMAND_DEACTIVATE:
106 
107         /* The deactivate command is used when the device has been extracted either
108            directly or when its parents has been extracted.  */
109         status =  _ux_host_class_pima_deactivate(command);
110         return(status);
111 
112     default:
113 
114         /* Error trap. */
115         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
116 
117         /* If trace is enabled, insert this event into the trace buffer.  */
118         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
119 
120         return(UX_FUNCTION_NOT_SUPPORTED);
121     }
122 }
123 
124