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 /** Device Pima Class */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define UX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "ux_api.h"
28 #include "ux_device_class_pima.h"
29 #include "ux_device_stack.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_device_class_pima_object_references_set PORTABLE C */
37 /* 6.1.10 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* Set object references associated with an object handle. */
45 /* The pima class will call the application to set the array of */
46 /* references. */
47 /* */
48 /* */
49 /* */
50 /* INPUT */
51 /* */
52 /* pima Pointer to pima class */
53 /* object_handle Object Handle */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* Completion Status */
58 /* */
59 /* CALLS */
60 /* */
61 /* _ux_device_stack_transfer_request Transfer request */
62 /* _ux_device_stack_endpoint_stall Stall endpoint */
63 /* _ux_device_class_pima_response_send Send PIMA response */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Device Pima Class */
68 /* */
69 /* RELEASE HISTORY */
70 /* */
71 /* DATE NAME DESCRIPTION */
72 /* */
73 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
74 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
75 /* resulting in version 6.1 */
76 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
77 /* updated status handling, */
78 /* resulting in version 6.1.10 */
79 /* */
80 /**************************************************************************/
_ux_device_class_pima_object_references_set(UX_SLAVE_CLASS_PIMA * pima,ULONG object_handle)81 UINT _ux_device_class_pima_object_references_set(UX_SLAVE_CLASS_PIMA *pima,
82 ULONG object_handle)
83 {
84
85 UINT status;
86 UX_SLAVE_TRANSFER *transfer_request;
87 UCHAR *pima_data_buffer;
88 UCHAR *object_references;
89 ULONG object_references_length;
90
91 /* If trace is enabled, insert this event into the trace buffer. */
92 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_PIMA_SET_OBJECT_REFERENCES, pima, object_handle, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
93
94 /* Obtain the pointer to the transfer request. */
95 transfer_request = &pima -> ux_device_class_pima_bulk_out_endpoint -> ux_slave_endpoint_transfer_request;
96
97 /* Obtain memory for this object info. Use the transfer request pre-allocated memory. */
98 pima_data_buffer = transfer_request -> ux_slave_transfer_request_data_pointer;
99
100 /* Get the data payload. */
101 status = _ux_device_stack_transfer_request(transfer_request, UX_DEVICE_CLASS_PIMA_OBJECT_PROP_VALUE_BUFFER_SIZE,
102 UX_DEVICE_CLASS_PIMA_OBJECT_PROP_VALUE_BUFFER_SIZE);
103
104 /* Check if there was an error. If so, stall the endpoint. */
105 if (status != UX_SUCCESS)
106 {
107
108 /* Stall the endpoint. */
109 _ux_device_stack_endpoint_stall(pima -> ux_device_class_pima_bulk_out_endpoint);
110
111 /* Return the status. */
112 return(status);
113
114 }
115
116 /* Allocate the device info pointer to the beginning of the dynamic object info field. */
117 object_references = pima_data_buffer + UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE;
118
119 /* Obtain the length of the data payload. */
120 object_references_length = transfer_request -> ux_slave_transfer_request_actual_length;
121
122 /* Ensure there is some data payload. */
123 if (object_references_length > UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE)
124 {
125
126 /* Take out the header. */
127 object_references_length -= UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE;
128
129 /* Send the object references to the application. */
130 status = pima -> ux_device_class_pima_object_references_set(pima, object_handle, object_references, object_references_length);
131
132 /* Now we return a response with success. */
133 status = (status == UX_SUCCESS) ? UX_DEVICE_CLASS_PIMA_RC_OK : status;
134 _ux_device_class_pima_response_send(pima, status, 0, 0, 0, 0);
135
136 }
137 else
138 {
139 /* We return an error. */
140 _ux_device_class_pima_response_send(pima, UX_DEVICE_CLASS_PIMA_RC_INVALID_PARAMETER, 0, 0, 0, 0);
141
142 /* Status error. */
143 status = UX_ERROR;
144
145 }
146 /* Return completion status. */
147 return(status);
148 }
149
150
151