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_session_close PORTABLE C */
37 /* 6.3.0 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function closes a session with the PIMA device. */
45 /* */
46 /* INPUT */
47 /* */
48 /* pima Pointer to pima class */
49 /* pima_session Pointer to pima session */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* Completion Status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _ux_host_class_pima_command Pima command function */
58 /* */
59 /* CALLED BY */
60 /* */
61 /* USB application */
62 /* */
63 /* RELEASE HISTORY */
64 /* */
65 /* DATE NAME DESCRIPTION */
66 /* */
67 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
68 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
69 /* resulting in version 6.1 */
70 /* 10-31-2023 Yajun xia Modified comment(s), */
71 /* resulting in version 6.3.0 */
72 /* */
73 /**************************************************************************/
_ux_host_class_pima_session_close(UX_HOST_CLASS_PIMA * pima,UX_HOST_CLASS_PIMA_SESSION * pima_session)74 UINT _ux_host_class_pima_session_close(UX_HOST_CLASS_PIMA *pima, UX_HOST_CLASS_PIMA_SESSION *pima_session)
75 {
76
77 UX_HOST_CLASS_PIMA_COMMAND command;
78 UINT status;
79
80 /* If trace is enabled, insert this event into the trace buffer. */
81 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_PIMA_SESSION_CLOSE, pima, pima_session, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
82
83 /* Check if this session is valid or not. */
84 if (pima_session -> ux_host_class_pima_session_magic != UX_HOST_CLASS_PIMA_MAGIC_NUMBER)
85 return (UX_HOST_CLASS_PIMA_RC_SESSION_NOT_OPEN);
86
87 /* Check if this session is opened or not. */
88 if (pima_session -> ux_host_class_pima_session_state != UX_HOST_CLASS_PIMA_SESSION_STATE_OPENED)
89 return (UX_HOST_CLASS_PIMA_RC_SESSION_NOT_OPEN);
90
91 /* The transaction ID in the PIMA instance should be reset. */
92 pima -> ux_host_class_pima_transaction_id = 0;
93
94 /* Issue command to close the session with the PIMA device. No parameter. */
95 command.ux_host_class_pima_command_nb_parameters = 0;
96
97 /* Then set the command to CLOSE_SESSION. */
98 command.ux_host_class_pima_command_operation_code = UX_HOST_CLASS_PIMA_OC_CLOSE_SESSION;
99
100 /* Other parameters unused. */
101 command.ux_host_class_pima_command_parameter_1 = 0;
102 command.ux_host_class_pima_command_parameter_2 = 0;
103 command.ux_host_class_pima_command_parameter_3 = 0;
104 command.ux_host_class_pima_command_parameter_4 = 0;
105 command.ux_host_class_pima_command_parameter_5 = 0;
106
107 /* Issue the command. */
108 status = _ux_host_class_pima_command(pima, &command, 0 , UX_NULL, 0, 0);
109
110 /* Check the result. If OK, the session was closed properly. */
111 if (status == UX_SUCCESS)
112 {
113
114 /* Reset the PIMA session in the pima instance. */
115 pima -> ux_host_class_pima_session = UX_NULL;
116
117 /* Reset the magic field. */
118 pima_session -> ux_host_class_pima_session_magic = 0;
119
120 /* Mark the session as closed. */
121 pima_session -> ux_host_class_pima_session_state = UX_HOST_CLASS_PIMA_SESSION_STATE_CLOSED;
122 }
123
124 /* Return completion status. */
125 return(status);
126 }
127
128 /**************************************************************************/
129 /* */
130 /* FUNCTION RELEASE */
131 /* */
132 /* _uxe_host_class_pima_session_close PORTABLE C */
133 /* 6.3.0 */
134 /* AUTHOR */
135 /* */
136 /* Yajun Xia, Microsoft Corporation */
137 /* */
138 /* DESCRIPTION */
139 /* */
140 /* This function checks errors in pima session close function call. */
141 /* */
142 /* INPUT */
143 /* */
144 /* pima Pointer to pima class */
145 /* pima_session Pointer to pima session */
146 /* */
147 /* OUTPUT */
148 /* */
149 /* Completion Status */
150 /* */
151 /* CALLS */
152 /* */
153 /* _ux_host_class_pima_session_close Close pima session */
154 /* */
155 /* CALLED BY */
156 /* */
157 /* USB application */
158 /* */
159 /* RELEASE HISTORY */
160 /* */
161 /* DATE NAME DESCRIPTION */
162 /* */
163 /* 10-31-2023 Yajun xia Initial Version 6.3.0 */
164 /* */
165 /**************************************************************************/
_uxe_host_class_pima_session_close(UX_HOST_CLASS_PIMA * pima,UX_HOST_CLASS_PIMA_SESSION * pima_session)166 UINT _uxe_host_class_pima_session_close(UX_HOST_CLASS_PIMA *pima, UX_HOST_CLASS_PIMA_SESSION *pima_session)
167 {
168
169 /* Sanity checks. */
170 if ((pima == UX_NULL) || (pima_session == UX_NULL))
171 return (UX_INVALID_PARAMETER);
172
173 /* Call the actual pima session close function. */
174 return(_ux_host_class_pima_session_close(pima, pima_session));
175 }
176