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_prop_value_set PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* Return an Object Property Value. */
45 /* */
46 /* */
47 /* INPUT */
48 /* */
49 /* pima Pointer to pima class */
50 /* object_handle Object Handle */
51 /* object_property_code Object Property code for */
52 /* which the value is obtained. */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* Completion Status */
57 /* */
58 /* CALLS */
59 /* */
60 /* _ux_device_stack_transfer_request Transfer request */
61 /* _ux_device_stack_endpoint_stall Stall endpoint */
62 /* _ux_device_class_pima_response_send Send PIMA response */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* Device Pima Class */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
73 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
74 /* resulting in version 6.1 */
75 /* */
76 /**************************************************************************/
_ux_device_class_pima_object_prop_value_set(UX_SLAVE_CLASS_PIMA * pima,ULONG object_handle,ULONG object_property_code)77 UINT _ux_device_class_pima_object_prop_value_set(UX_SLAVE_CLASS_PIMA *pima,
78 ULONG object_handle,
79 ULONG object_property_code)
80 {
81
82 UINT status;
83 UX_SLAVE_TRANSFER *transfer_request;
84 UCHAR *pima_data_buffer;
85 UCHAR *object_property_value;
86 ULONG object_property_value_length;
87
88 /* If trace is enabled, insert this event into the trace buffer. */
89 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_PIMA_SET_OBJECT_PROP_VALUE, pima, object_handle, object_property_code, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
90
91 /* Obtain the pointer to the transfer request. */
92 transfer_request = &pima -> ux_device_class_pima_bulk_out_endpoint -> ux_slave_endpoint_transfer_request;
93
94 /* Obtain memory for this object info. Use the transfer request pre-allocated memory. */
95 pima_data_buffer = transfer_request -> ux_slave_transfer_request_data_pointer;
96
97 /* Get the data payload. */
98 status = _ux_device_stack_transfer_request(transfer_request, UX_DEVICE_CLASS_PIMA_OBJECT_PROP_VALUE_BUFFER_SIZE,
99 UX_DEVICE_CLASS_PIMA_OBJECT_PROP_VALUE_BUFFER_SIZE);
100
101 /* Check if there was an error. If so, stall the endpoint. */
102 if (status != UX_SUCCESS)
103 {
104
105 /* Stall the endpoint. */
106 _ux_device_stack_endpoint_stall(pima -> ux_device_class_pima_bulk_out_endpoint);
107
108 /* Return the status. */
109 return(status);
110
111 }
112
113 /* Allocate the device info pointer to the beginning of the dynamic object info field. */
114 object_property_value = pima_data_buffer + UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE;
115
116 /* Obtain the length of the data payload. */
117 object_property_value_length = transfer_request -> ux_slave_transfer_request_actual_length;
118
119 /* Ensure there is some data payload. */
120 if (object_property_value_length > UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE)
121 {
122
123 /* Take out the header. */
124 object_property_value_length -= UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE;
125
126 /* Send the object to the application. */
127 status = pima -> ux_device_class_pima_object_prop_value_set(pima, object_handle, object_property_code, object_property_value, object_property_value_length);
128
129 /* Check error code from application. */
130 if (status == UX_SUCCESS)
131
132 /* Now we return a response with success. */
133 _ux_device_class_pima_response_send(pima, UX_DEVICE_CLASS_PIMA_RC_OK, 0, 0, 0, 0);
134 else
135
136 /* We return an error. The code is passed by the application. */
137 _ux_device_class_pima_response_send(pima, status, 0, 0, 0, 0);
138
139 }
140 else
141 {
142 /* We return an error. */
143 _ux_device_class_pima_response_send(pima, UX_DEVICE_CLASS_PIMA_RC_INVALID_PARAMETER, 0, 0, 0, 0);
144
145 /* Status error. */
146 status = UX_ERROR;
147
148 }
149 /* Return completion status. */
150 return(status);
151 }
152
153
154