1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** Device Pima Class */
/** */
/**************************************************************************/
/**************************************************************************/
#define UX_SOURCE_CODE
/* Include necessary system files. */
#include "ux_api.h"
#include "ux_device_class_pima.h"
#include "ux_device_stack.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_pima_object_data_send PORTABLE C */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function accepts an object data from the host. */
/* */
/* INPUT */
/* */
/* pima Pointer to pima class */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* _ux_device_stack_transfer_request Transfer request */
/* _ux_device_stack_endpoint_stall Stall endpoint */
/* */
/* CALLED BY */
/* */
/* Device Storage Class */
/* */
/**************************************************************************/
UINT _ux_device_class_pima_object_data_send(UX_SLAVE_CLASS_PIMA *pima)
{
UINT status;
UX_SLAVE_TRANSFER *transfer_request;
ULONG transfer_length;
UX_SLAVE_CLASS_PIMA_OBJECT *object;
ULONG object_handle;
UCHAR *object_data;
ULONG object_offset;
ULONG object_length;
ULONG total_length;
/* Get the last object handle. The handle used is the last handle used when he host performed a OBJECT_INFO_SEND. */
object_handle = pima -> ux_device_class_pima_current_object_handle;
/* If trace is enabled, insert this event into the trace buffer. */
UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_PIMA_OBJECT_DATA_SEND, pima, object_handle, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
/* Obtain the object info from the application. */
status = pima -> ux_device_class_pima_object_info_get(pima, object_handle, &object);
/* Check for error. */
if (status == UX_SUCCESS)
{
/* Data phase (Bulk OUT). */
pima -> ux_device_class_pima_state = UX_DEVICE_CLASS_PIMA_PHASE_DATA_OUT;
/* Set the object length. */
object_length = object -> ux_device_class_pima_object_compressed_size;
/* Set the total length to be received. */
total_length = object_length + UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE;
/* Reset the offset. */
object_offset = 0;
/* Obtain the pointer to the transfer request of the bulk out endpoint. */
transfer_request = &pima -> ux_device_class_pima_bulk_out_endpoint -> ux_slave_endpoint_transfer_request;
/* Obtain memory for this object info. Use the transfer request pre-allocated memory. */
object_data = transfer_request -> ux_slave_transfer_request_data_pointer;
/* Assume the host will send all the data. */
while (total_length != 0)
{
/* Get a data payload. */
status = _ux_device_stack_transfer_request(transfer_request, UX_DEVICE_CLASS_PIMA_TRANSFER_BUFFER_LENGTH, UX_DEVICE_CLASS_PIMA_TRANSFER_BUFFER_LENGTH);
/* It's canceled, do not proceed. */
if (pima -> ux_device_class_pima_state == UX_DEVICE_CLASS_PIMA_PHASE_IDLE)
{
pima -> ux_device_class_pima_device_status = UX_DEVICE_CLASS_PIMA_RC_OK;
return(UX_ERROR);
}
/* Check for the status. We may have had a request to cancel the transaction from the host. */
if (status != UX_SUCCESS)
{
/* Check the completion code for transfer abort from the host. */
if (transfer_request -> ux_slave_transfer_request_status == UX_TRANSFER_STATUS_ABORT)
{
/* Do not proceed. */
return(UX_ERROR);
}
else
{
/* We have a transmission error. Do not proceed. */
status = UX_ERROR;
break;
}
}
/* Obtain the length of the transaction. */
transfer_length = transfer_request -> ux_slave_transfer_request_actual_length;
/* If this is the first packet, we have to take into account the
header. */
if (object_offset == 0)
{
/* Do some sanity check. */
if (object_length < (transfer_length - UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE))
{
/* We have an overflow. Do not proceed. */
status = UX_ERROR;
break;
}
/* Send the object data to the application. */
status = pima -> ux_device_class_pima_object_data_send(pima, object_handle, UX_DEVICE_CLASS_PIMA_OBJECT_TRANSFER_PHASE_ACTIVE,
object_data + UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE,
object_offset,
(transfer_length - UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE));
/* Check status, if we have a problem, we abort. */
if (status != UX_SUCCESS)
{
/* We need to inform the host of an error. */
status = UX_ERROR;
break;
}
else
{
/* Adjust the remaining length of the object. */
total_length -= transfer_length;
/* Adjust the length to be sent. */
object_offset += (transfer_length - UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE);
}
}
else
{
/* Do some sanity check. */
if (object_length < transfer_length)
{
/* We have an overflow. Do not proceed. */
status = UX_ERROR;
break;
}
/* This is not the first packet, send the object data to the application. */
status = pima -> ux_device_class_pima_object_data_send(pima, object_handle, UX_DEVICE_CLASS_PIMA_OBJECT_TRANSFER_PHASE_ACTIVE,
object_data,
object_offset,
transfer_length);
/* Check status, if we have a problem, we abort. */
if (status != UX_SUCCESS)
{
/* We need to inform the host of an error. */
status = UX_ERROR;
break;
}
else
{
/* Adjust the remaining length of the total object. */
total_length -= transfer_length;
/* Adjust the length to be sent. */
object_offset += transfer_length;
}
}
/* It's canceled, do not proceed. */
if (pima -> ux_device_class_pima_state == UX_DEVICE_CLASS_PIMA_PHASE_IDLE)
{
pima -> ux_device_class_pima_device_status = UX_DEVICE_CLASS_PIMA_RC_OK;
return(UX_ERROR);
}
}
}
/* Check for status. */
if (status == UX_SUCCESS)
{
/* Now we return a response with success. */
_ux_device_class_pima_response_send(pima, UX_DEVICE_CLASS_PIMA_RC_OK, 0, 0, 0, 0);
/* Make the object transfer completed. */
status = pima -> ux_device_class_pima_object_data_send(pima, object_handle, UX_DEVICE_CLASS_PIMA_OBJECT_TRANSFER_PHASE_COMPLETED,
UX_NULL, 0, 0);
}
else
{
/* We need to stall the bulk out pipe. This is the method used by Pima devices to
cancel a transaction. */
_ux_device_stack_endpoint_stall(pima -> ux_device_class_pima_bulk_in_endpoint);
/* Make the object transfer non completed. */
status = pima -> ux_device_class_pima_object_data_send(pima, object_handle, UX_DEVICE_CLASS_PIMA_OBJECT_TRANSFER_PHASE_COMPLETED_ERROR,
UX_NULL, 0, 0);
}
/* Return completion status. */
return(status);
}
|