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