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 /** USBX Component */
15 /** */
16 /** Device CCID Class */
17 /** */
18 /**************************************************************************/
19 /**************************************************************************/
20
21 #define UX_SOURCE_CODE
22
23
24 /* Include necessary system files. */
25
26 #include "ux_api.h"
27 #include "ux_device_class_ccid.h"
28 #include "ux_device_stack.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_device_class_ccid_response PORTABLE C */
36 /* 6.2.1 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function sends bulk IN response of the USB CCID device. */
44 /* */
45 /* INPUT */
46 /* */
47 /* ccid Pointer to ccid instance */
48 /* buffer Pointer to data buffer */
49 /* length Data length */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* Completion Status */
54 /* */
55 /* CALLS */
56 /* */
57 /* */
58 /* CALLED BY */
59 /* */
60 /* USBX Source Code */
61 /* */
62 /* RELEASE HISTORY */
63 /* */
64 /* DATE NAME DESCRIPTION */
65 /* */
66 /* 04-25-2022 Chaoqiong Xiao Initial Version 6.1.11 */
67 /* 03-08-2023 Chaoqiong Xiao Modified comment(s), */
68 /* added standalone support, */
69 /* resulting in version 6.2.1 */
70 /* */
71 /**************************************************************************/
_ux_device_class_ccid_response(UX_DEVICE_CLASS_CCID * ccid,UCHAR * buffer,ULONG length)72 UINT _ux_device_class_ccid_response(UX_DEVICE_CLASS_CCID *ccid, UCHAR *buffer, ULONG length)
73 {
74
75 UX_SLAVE_ENDPOINT *endpoint;
76 UX_SLAVE_TRANSFER *transfer;
77 UINT status;
78
79 /* Get bulk IN endpoint. */
80 endpoint = ccid -> ux_device_class_ccid_endpoint_in;
81
82 /* Get transfer request. */
83 transfer = &endpoint -> ux_slave_endpoint_transfer_request;
84
85 /* Lock bulk IN. */
86 _ux_device_mutex_on(&ccid -> ux_device_class_ccid_response_mutex);
87
88 /* Prepare data to transfer. */
89 if (length > 0 && buffer != UX_NULL &&
90 transfer -> ux_slave_transfer_request_data_pointer != buffer)
91 {
92 _ux_utility_memory_copy(transfer -> ux_slave_transfer_request_data_pointer,
93 buffer, length); /* Use case of memcpy is verified. */
94 }
95
96 #if defined(UX_DEVICE_STANDALONE)
97
98 /* Setup transfer struct for running. */
99 UX_SLAVE_TRANSFER_STATE_RESET(transfer);
100 transfer -> ux_slave_transfer_request_requested_length = length;
101 status = UX_SUCCESS;
102
103 ccid -> ux_device_class_ccid_rsp_state = UX_DEVICE_CLASS_CCID_RSP_START;
104 #else
105
106 /* Transfer data. */
107 status = _ux_device_stack_transfer_request(transfer, length, length);
108 #endif
109
110 /* Unlock bulk IN. */
111 _ux_device_mutex_off(&ccid -> ux_device_class_ccid_response_mutex);
112
113 /* Return transfer status. */
114 return(status);
115 }
116