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_open PORTABLE C */
37 /* 6.3.0 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function opens a session with the PIMA device. The session */
45 /* is maintained in this state until the session is closed or the */
46 /* device is unmounted. */
47 /* */
48 /* INPUT */
49 /* */
50 /* pima Pointer to pima class */
51 /* pima_session Pointer to pima session */
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_session_open(UX_HOST_CLASS_PIMA * pima,UX_HOST_CLASS_PIMA_SESSION * pima_session)76 UINT _ux_host_class_pima_session_open(UX_HOST_CLASS_PIMA *pima, UX_HOST_CLASS_PIMA_SESSION *pima_session)
77 {
78
79 UX_HOST_CLASS_PIMA_COMMAND command;
80 ULONG status;
81
82 /* If trace is enabled, insert this event into the trace buffer. */
83 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_PIMA_SESSION_OPEN, pima, pima_session, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
84
85 /* Check if there is already a session opened. */
86 if (pima -> ux_host_class_pima_session != UX_NULL)
87 return (UX_HOST_CLASS_PIMA_RC_SESSION_ALREADY_OPENED);
88
89 /* The transaction ID in the PIMA instance should be reset. */
90 pima -> ux_host_class_pima_transaction_id = 0;
91
92 /* Issue command to open the session with the PIMA device. First set the number of parameters. */
93 command.ux_host_class_pima_command_nb_parameters = 1;
94
95 /* Then set the command to OPEN_SESSION. */
96 command.ux_host_class_pima_command_operation_code = UX_HOST_CLASS_PIMA_OC_OPEN_SESSION;
97
98 /* The session ID is the handle to the session. */
99 command.ux_host_class_pima_command_parameter_1 = (ULONG) (ALIGN_TYPE) pima_session;
100
101 /* Other parameters unused. */
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 opened properly. */
111 if (status == UX_SUCCESS)
112 {
113
114 /* Store the session pointer in the PIMA instance. The PIMA class instance
115 only supports one opened session at a time at this stage. */
116 pima -> ux_host_class_pima_session = pima_session;
117
118 /* Save the session ID in the session container. This is not too useful since
119 the session ID is the session structure address. */
120 pima_session -> ux_host_class_pima_session_id = (ALIGN_TYPE) pima_session;
121
122 /* Put the magic number in the session instance. */
123 pima_session -> ux_host_class_pima_session_magic = UX_HOST_CLASS_PIMA_MAGIC_NUMBER;
124
125 /* Mark the session as opened. */
126 pima_session -> ux_host_class_pima_session_state = UX_HOST_CLASS_PIMA_SESSION_STATE_OPENED;
127 }
128
129 /* Return completion status. */
130 return(status);
131 }
132
133 /**************************************************************************/
134 /* */
135 /* FUNCTION RELEASE */
136 /* */
137 /* _uxe_host_class_pima_session_open PORTABLE C */
138 /* 6.3.0 */
139 /* AUTHOR */
140 /* */
141 /* Yajun Xia, Microsoft Corporation */
142 /* */
143 /* DESCRIPTION */
144 /* */
145 /* This function checks errors in pima session open function call. */
146 /* */
147 /* INPUT */
148 /* */
149 /* pima Pointer to pima class */
150 /* pima_session Pointer to pima session */
151 /* */
152 /* OUTPUT */
153 /* */
154 /* Completion Status */
155 /* */
156 /* CALLS */
157 /* */
158 /* _ux_host_class_pima_session_open Open pima session */
159 /* */
160 /* CALLED BY */
161 /* */
162 /* USB application */
163 /* */
164 /* RELEASE HISTORY */
165 /* */
166 /* DATE NAME DESCRIPTION */
167 /* */
168 /* 10-31-2023 Yajun xia Initial Version 6.3.0 */
169 /* */
170 /**************************************************************************/
_uxe_host_class_pima_session_open(UX_HOST_CLASS_PIMA * pima,UX_HOST_CLASS_PIMA_SESSION * pima_session)171 UINT _uxe_host_class_pima_session_open(UX_HOST_CLASS_PIMA *pima, UX_HOST_CLASS_PIMA_SESSION *pima_session)
172 {
173
174 /* Sanity checks. */
175 if ((pima == UX_NULL) || (pima_session == UX_NULL))
176 return(UX_INVALID_PARAMETER);
177
178 /* Call the actual pima session open function. */
179 return(_ux_host_class_pima_session_open(pima, pima_session));
180 }