GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_storage_device_support_check.c Lines: 14 14 100.0 %
Date: 2026-03-06 18:57:10 Branches: 4 4 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** USBX Component                                                        */
17
/**                                                                       */
18
/**   Storage Class                                                       */
19
/**                                                                       */
20
/**************************************************************************/
21
/**************************************************************************/
22
23
24
/* Include necessary system files.  */
25
26
#define UX_SOURCE_CODE
27
28
#include "ux_api.h"
29
#include "ux_host_class_storage.h"
30
#include "ux_host_stack.h"
31
32
33
#if defined(UX_HOST_STANDALONE) && defined(UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT)
34
#error Only Mass Storage BulkOnly (BO) is supported in standalone mode right now.
35
#endif
36
/**************************************************************************/
37
/*                                                                        */
38
/*  FUNCTION                                               RELEASE        */
39
/*                                                                        */
40
/*    _ux_host_class_storage_device_support_check         PORTABLE C      */
41
/*                                                           6.1.10       */
42
/*  AUTHOR                                                                */
43
/*                                                                        */
44
/*    Chaoqiong Xiao, Microsoft Corporation                               */
45
/*                                                                        */
46
/*  DESCRIPTION                                                           */
47
/*                                                                        */
48
/*    This function verifies the support for the subclass and protocol    */
49
/*    of the USB device. If the device is supported it will update the    */
50
/*    storage class instances with the transport layer functions.         */
51
/*                                                                        */
52
/*  INPUT                                                                 */
53
/*                                                                        */
54
/*    storage                               Pointer to storage class      */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    Completion Status                                                   */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    None                                                                */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    Storage Class                                                       */
67
/*                                                                        */
68
/**************************************************************************/
69
141
UINT  _ux_host_class_storage_device_support_check(UX_HOST_CLASS_STORAGE *storage)
70
{
71
72
    /* Check for the protocol type (BO/CB/CBI) and update the transport functions.  */
73
141
    switch(storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceProtocol)
74
    {
75
76
140
    case UX_HOST_CLASS_STORAGE_PROTOCOL_BO:
77
78
#if !defined(UX_HOST_STANDALONE)
79
140
        storage -> ux_host_class_storage_transport =  _ux_host_class_storage_transport_bo;
80
#endif
81
140
        break;
82
83
#ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT
84
    case UX_HOST_CLASS_STORAGE_PROTOCOL_CB:
85
86
#if !defined(UX_HOST_STANDALONE)
87
        storage -> ux_host_class_storage_transport =  _ux_host_class_storage_transport_cb;
88
#endif
89
        break;
90
91
92
    case UX_HOST_CLASS_STORAGE_PROTOCOL_CBI:
93
94
#if !defined(UX_HOST_STANDALONE)
95
96
        /* In case of CBI, the subclass must be UFI, if not, default back to CB transport.  */
97
        if (storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceSubClass == UX_HOST_CLASS_STORAGE_SUBCLASS_UFI)
98
            storage -> ux_host_class_storage_transport =  _ux_host_class_storage_transport_cbi;
99
        else
100
            storage -> ux_host_class_storage_transport =  _ux_host_class_storage_transport_cb;
101
#endif
102
        break;
103
104
#endif
105
106
1
    default:
107
108
        /* Error trap. */
109
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_PROTOCOL_ERROR);
110
111
        /* If trace is enabled, insert this event into the trace buffer.  */
112
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_PROTOCOL_ERROR, storage, 0, 0, UX_TRACE_ERRORS, 0, 0)
113
114
1
        return(UX_HOST_CLASS_PROTOCOL_ERROR);
115
    }
116
117
    /* Check for the sub class and make sure we support it.  */
118
140
    switch (storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceSubClass)
119
    {
120
121
#ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT
122
    case UX_HOST_CLASS_STORAGE_SUBCLASS_UFI:
123
#endif
124
139
    case UX_HOST_CLASS_STORAGE_SUBCLASS_RBC:
125
    case UX_HOST_CLASS_STORAGE_SUBCLASS_SCSI:
126
    case UX_HOST_CLASS_STORAGE_SUBCLASS_SFF8020:
127
    case UX_HOST_CLASS_STORAGE_SUBCLASS_SFF8070:
128
129
139
        return(UX_SUCCESS);
130
131
1
    default:
132
133
        /* Error trap. */
134
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_PROTOCOL_ERROR);
135
136
        /* If trace is enabled, insert this event into the trace buffer.  */
137
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_PROTOCOL_ERROR, storage, 0, 0, UX_TRACE_ERRORS, 0, 0)
138
139
1
        return(UX_HOST_CLASS_PROTOCOL_ERROR);
140
    }
141
}