1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** USBX Component                                                        */
17 /**                                                                       */
18 /**   Device Pima Class                                                   */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define UX_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "ux_api.h"
29 #include "ux_device_class_pima.h"
30 #include "ux_device_stack.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _ux_device_class_pima_object_handles_send           PORTABLE C      */
38 /*                                                           6.1.10       */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function returns the object handle array to the host.          */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    pima                                  Pointer to pima class         */
50 /*    storage_id                            StorageID                     */
51 /*    object_format_code                    Format code filter            */
52 /*    object_association                    Object Handle Association     */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    Completion Status                                                   */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _ux_device_stack_transfer_request     Transfer request              */
61 /*    _ux_utility_long_put                  Put 32-bit value              */
62 /*    _ux_utility_short_put                 Put 32-bit value              */
63 /*    _ux_utility_memory_set                Set memory                    */
64 /*    _ux_device_class_pima_response_send   Send PIMA response            */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    Device Pima Class                                                   */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
75 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
76 /*                                            resulting in version 6.1    */
77 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
78 /*                                            updated status handling,    */
79 /*                                            resulting in version 6.1.10 */
80 /*                                                                        */
81 /**************************************************************************/
_ux_device_class_pima_object_handles_send(UX_SLAVE_CLASS_PIMA * pima,ULONG storage_id,ULONG object_format_code,ULONG object_association)82 UINT  _ux_device_class_pima_object_handles_send(UX_SLAVE_CLASS_PIMA *pima,
83                                                     ULONG storage_id,
84                                                     ULONG object_format_code,
85                                                     ULONG object_association)
86 {
87 
88 UINT                    status;
89 UX_SLAVE_TRANSFER       *transfer_request;
90 ULONG                   object_handles_array_length;
91 UCHAR                   *object_handles_array;
92 
93     UX_PARAMETER_NOT_USED(storage_id);
94 
95     /* If trace is enabled, insert this event into the trace buffer.  */
96     UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_PIMA_OBJECT_HANDLES_SEND, pima, storage_id, object_format_code, object_association, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
97 
98     /* Obtain the pointer to the transfer request.  */
99     transfer_request =  &pima -> ux_device_class_pima_bulk_in_endpoint -> ux_slave_endpoint_transfer_request;
100 
101     /* Obtain memory for this object info. Use the transfer request pre-allocated memory.  */
102     object_handles_array =  transfer_request -> ux_slave_transfer_request_data_pointer;
103 
104     /* Fill in the data container type.  */
105     _ux_utility_short_put(object_handles_array + UX_DEVICE_CLASS_PIMA_DATA_HEADER_TYPE,
106                             UX_DEVICE_CLASS_PIMA_CT_DATA_BLOCK);
107 
108     /* Fill in the data code.  */
109     _ux_utility_short_put(object_handles_array + UX_DEVICE_CLASS_PIMA_DATA_HEADER_CODE,
110                             UX_DEVICE_CLASS_PIMA_OC_GET_OBJECT_HANDLES);
111 
112     /* Fill in the Transaction ID.  */
113     _ux_utility_long_put(object_handles_array + UX_DEVICE_CLASS_PIMA_DATA_HEADER_TRANSACTION_ID,
114                             pima -> ux_device_class_pima_transaction_id);
115 
116     /* Get the array from the application.  */
117     status = pima -> ux_device_class_pima_object_handles_get(pima, object_format_code,
118                                                             object_association, (ULONG *) (object_handles_array + UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE),
119                                                             (UX_DEVICE_CLASS_PIMA_ARRAY_BUFFER_SIZE / sizeof(ULONG)) -1);
120 
121     /* Result should always be OK, but to be sure .... */
122     if (status != UX_SUCCESS)
123 
124         /* We return an error.  */
125         _ux_device_class_pima_response_send(pima, status, 0, 0, 0, 0);
126 
127     else
128     {
129 
130         /* Compute the overall length of the handle arrays.  */
131         object_handles_array_length = (_ux_utility_long_get(object_handles_array + UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE) +1) * (ULONG)sizeof(ULONG);
132 
133         /* Add the header size.  */
134         object_handles_array_length += UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE;
135 
136         /* Fill in the size of the response header.  */
137         _ux_utility_long_put(object_handles_array + UX_DEVICE_CLASS_PIMA_DATA_HEADER_LENGTH,
138                                 object_handles_array_length);
139 
140         /* Send a data payload with the object handles array.  */
141         status =  _ux_device_stack_transfer_request(transfer_request, object_handles_array_length, 0);
142 
143         /* Now we return a response with success.  */
144         _ux_device_class_pima_response_send(pima, UX_DEVICE_CLASS_PIMA_RC_OK, 0, 0, 0, 0);
145 
146     }
147 
148     /* Return completion status.  */
149     return(status);
150 }
151 
152 
153