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