summaryrefslogtreecommitdiff
path: root/common/usbx_device_classes/src/ux_device_class_ccid_response.c
blob: ece56604727c6de82f1b4656ab60251c60554aaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2026-present Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/

/**************************************************************************/
/**                                                                       */
/** USBX Component                                                        */
/**                                                                       */
/**   Device CCID Class                                                   */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

#define UX_SOURCE_CODE


/* Include necessary system files.  */

#include "ux_api.h"
#include "ux_device_class_ccid.h"
#include "ux_device_stack.h"


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _ux_device_class_ccid_response                      PORTABLE C      */
/*                                                           6.2.1        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Chaoqiong Xiao, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function sends bulk IN response of the USB CCID device.        */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    ccid                                  Pointer to ccid instance      */
/*    buffer                                Pointer to data buffer        */
/*    length                                Data length                   */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    Completion Status                                                   */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    USBX Source Code                                                    */
/*                                                                        */
/**************************************************************************/
UINT _ux_device_class_ccid_response(UX_DEVICE_CLASS_CCID *ccid, UCHAR *buffer, ULONG length)
{

UX_SLAVE_ENDPOINT               *endpoint;
UX_SLAVE_TRANSFER               *transfer;
UINT                            status;

    /* Get bulk IN endpoint.  */
    endpoint = ccid -> ux_device_class_ccid_endpoint_in;

    /* Get transfer request.  */
    transfer = &endpoint -> ux_slave_endpoint_transfer_request;

    /* Lock bulk IN.  */
    _ux_device_mutex_on(&ccid -> ux_device_class_ccid_response_mutex);

    /* Prepare data to transfer.  */
    if (length > 0 && buffer != UX_NULL &&
        transfer -> ux_slave_transfer_request_data_pointer != buffer)
    {
        _ux_utility_memory_copy(transfer -> ux_slave_transfer_request_data_pointer,
                                buffer, length); /* Use case of memcpy is verified. */
    }

#if defined(UX_DEVICE_STANDALONE)

    /* Setup transfer struct for running.  */
    UX_SLAVE_TRANSFER_STATE_RESET(transfer);
    transfer -> ux_slave_transfer_request_requested_length = length;
    status = UX_SUCCESS;

    ccid -> ux_device_class_ccid_rsp_state = UX_DEVICE_CLASS_CCID_RSP_START;
#else

    /* Transfer data.  */
    status = _ux_device_stack_transfer_request(transfer, length, length);
#endif

    /* Unlock bulk IN.  */
    _ux_device_mutex_off(&ccid -> ux_device_class_ccid_response_mutex);

    /* Return transfer status.  */
    return(status);
}