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_num_objects_get                 PORTABLE C      */
37 /*                                                           6.3.0        */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function returns the number of objects for a specific storage. */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    pima                                       Pointer to pima class    */
49 /*    pima_session                               Pointer to pima session  */
50 /*    storage_id                                 The storage ID           */
51 /*    object_format_code                         The object format code   */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    Completion Status                                                   */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*  _ux_host_class_pima_command                 Pima command function     */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    USB application                                                     */
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 /*  10-31-2023     Yajun xia                Modified comment(s),          */
73 /*                                            resulting in version 6.3.0  */
74 /*                                                                        */
75 /**************************************************************************/
_ux_host_class_pima_num_objects_get(UX_HOST_CLASS_PIMA * pima,UX_HOST_CLASS_PIMA_SESSION * pima_session,ULONG storage_id,ULONG object_format_code)76 UINT  _ux_host_class_pima_num_objects_get(UX_HOST_CLASS_PIMA *pima,
77                                         UX_HOST_CLASS_PIMA_SESSION *pima_session,
78                                         ULONG storage_id,
79                                         ULONG object_format_code)
80 {
81 
82 UX_HOST_CLASS_PIMA_COMMAND             command;
83 UINT                                status;
84 
85     /* If trace is enabled, insert this event into the trace buffer.  */
86     UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_PIMA_NUM_OBJECTS_GET, pima, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
87 
88     /* Check if this session is valid or not.  */
89     if (pima_session -> ux_host_class_pima_session_magic != UX_HOST_CLASS_PIMA_MAGIC_NUMBER)
90         return (UX_HOST_CLASS_PIMA_RC_SESSION_NOT_OPEN);
91 
92     /* Check if this session is opened or not.  */
93     if (pima_session -> ux_host_class_pima_session_state != UX_HOST_CLASS_PIMA_SESSION_STATE_OPENED)
94         return (UX_HOST_CLASS_PIMA_RC_SESSION_NOT_OPEN);
95 
96     /* Issue command to get the storage IDs.  2 parameter.  */
97     command.ux_host_class_pima_command_nb_parameters =  2;
98 
99     /* Parameter 1 is the Storage ID.  */
100     command.ux_host_class_pima_command_parameter_1 =  storage_id;
101 
102     /* Parameter 2 is the Object Format Code.  */
103     command.ux_host_class_pima_command_parameter_2 =  object_format_code;
104 
105     /* Other parameters unused.  */
106     command.ux_host_class_pima_command_parameter_3 =  0;
107     command.ux_host_class_pima_command_parameter_4 =  0;
108     command.ux_host_class_pima_command_parameter_5 =  0;
109 
110     /* Then set the command to GET_NUM_OBJETCS.  */
111     command.ux_host_class_pima_command_operation_code =  UX_HOST_CLASS_PIMA_OC_GET_NUM_OBJECTS;
112 
113     /* Issue the command.  */
114     status = _ux_host_class_pima_command(pima, &command, 0 , UX_NULL, 0, 0);
115 
116     /* Check the result. If the result is OK, the parameter1 has the number of objects. */
117     if (status == UX_SUCCESS)
118 
119         /* Store the number of objects into the current pima session.  */
120         pima_session -> ux_host_class_pima_session_nb_objects =  command.ux_host_class_pima_command_parameter_1;
121 
122     /* Return completion status.  */
123     return(status);
124 }
125 
126 /**************************************************************************/
127 /*                                                                        */
128 /*  FUNCTION                                               RELEASE        */
129 /*                                                                        */
130 /*    _uxe_host_class_pima_num_objects_get                PORTABLE C      */
131 /*                                                           6.3.0        */
132 /*  AUTHOR                                                                */
133 /*                                                                        */
134 /*    Yajun Xia, Microsoft Corporation                                    */
135 /*                                                                        */
136 /*  DESCRIPTION                                                           */
137 /*                                                                        */
138 /*    This function checks errors in pima object number get function      */
139 /*    call.                                                               */
140 /*                                                                        */
141 /*  INPUT                                                                 */
142 /*                                                                        */
143 /*    pima                                       Pointer to pima class    */
144 /*    pima_session                               Pointer to pima session  */
145 /*    storage_id                                 The storage ID           */
146 /*    object_format_code                         The object format code   */
147 /*                                                                        */
148 /*  OUTPUT                                                                */
149 /*                                                                        */
150 /*    Completion Status                                                   */
151 /*                                                                        */
152 /*  CALLS                                                                 */
153 /*                                                                        */
154 /*    _ux_host_class_pima_num_objects_get   Get pima object number        */
155 /*                                                                        */
156 /*  CALLED BY                                                             */
157 /*                                                                        */
158 /*    USB application                                                     */
159 /*                                                                        */
160 /*  RELEASE HISTORY                                                       */
161 /*                                                                        */
162 /*    DATE              NAME                      DESCRIPTION             */
163 /*                                                                        */
164 /*  10-31-2023        Yajun xia             Initial Version 6.3.0         */
165 /*                                                                        */
166 /**************************************************************************/
_uxe_host_class_pima_num_objects_get(UX_HOST_CLASS_PIMA * pima,UX_HOST_CLASS_PIMA_SESSION * pima_session,ULONG storage_id,ULONG object_format_code)167 UINT  _uxe_host_class_pima_num_objects_get(UX_HOST_CLASS_PIMA *pima,
168                                         UX_HOST_CLASS_PIMA_SESSION *pima_session,
169                                         ULONG storage_id,
170                                         ULONG object_format_code)
171 {
172 
173     /* Sanity checks.  */
174     if ((pima == UX_NULL) || (pima_session == UX_NULL))
175         return(UX_INVALID_PARAMETER);
176 
177     /* Call the actual pima num objects get function.  */
178     return(_ux_host_class_pima_num_objects_get(pima, pima_session, storage_id, object_format_code));
179 }