GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_device_classes/src/ux_device_class_cdc_ecm_entry.c Lines: 28 28 100.0 %
Date: 2026-03-06 18:57:10 Branches: 12 12 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
/** USBX Component                                                        */
16
/**                                                                       */
17
/**   Device CDC_ECM Class                                                */
18
/**                                                                       */
19
/**************************************************************************/
20
/**************************************************************************/
21
22
#define UX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "ux_api.h"
28
#include "ux_device_class_cdc_ecm.h"
29
#include "ux_device_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_device_class_cdc_ecm_entry                      PORTABLE C      */
37
/*                                                           6.x          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function is the entry point of the cdc_ecm class. It           */
45
/*    will be called by the device stack enumeration module when the      */
46
/*    host has sent a SET_CONFIGURATION command and the cdc_ecm interface */
47
/*    needs to be mounted.                                                */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    command                               Pointer to class command      */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    Completion Status                                                   */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    _ux_device_class_cdc_ecm_initialize       Initialize cdc_ecm class  */
60
/*    _ux_device_class_cdc_ecm_uninitialize     Uninitialize cdc_ecm class*/
61
/*    _ux_device_class_cdc_ecm_activate         Activate cdc_ecm class    */
62
/*    _ux_device_class_cdc_ecm_deactivate       Deactivate cdc_ecm class  */
63
/*    _ux_device_class_cdc_ecm_change           Alternate setting change  */
64
/*    _ux_device_class_cdc_ecm_control_request  Request control           */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    CDC_ECM Class                                                       */
69
/*                                                                        */
70
/**************************************************************************/
71
906
UINT  _ux_device_class_cdc_ecm_entry(UX_SLAVE_CLASS_COMMAND *command)
72
{
73
74
UINT        status;
75
76
    /* The command request will tell us we need to do here, either a enumeration
77
       query, an activation or a deactivation.  */
78


906
    switch (command -> ux_slave_class_command_request)
79
    {
80
81
65
    case UX_SLAVE_CLASS_COMMAND_INITIALIZE:
82
83
        /* Call the init function of the CDC_ECM class.  */
84
65
        status =  _ux_device_class_cdc_ecm_initialize(command);
85
86
        /* Return the completion status.  */
87
65
        return(status);
88
89
7
    case UX_SLAVE_CLASS_COMMAND_UNINITIALIZE:
90
91
        /* Call the uninit function of the CDC_ECM class.  */
92
7
        status =  _ux_device_class_cdc_ecm_uninitialize(command);
93
94
        /* Return the completion status.  */
95
7
        return(status);
96
97
246
    case UX_SLAVE_CLASS_COMMAND_QUERY:
98
99
        /* Check the CLASS definition in the interface descriptor. */
100
246
        if (command -> ux_slave_class_command_class == UX_DEVICE_CLASS_CDC_ECM_CLASS_COMMUNICATION_CONTROL ||
101
125
                command -> ux_slave_class_command_class == UX_DEVICE_CLASS_CDC_ECM_CLASS_COMMUNICATION_DATA)
102
242
            return(UX_SUCCESS);
103
        else
104
4
            return(UX_NO_CLASS_MATCH);
105
106
242
    case UX_SLAVE_CLASS_COMMAND_ACTIVATE:
107
108
        /* The activate command is used when the host has sent a SET_CONFIGURATION command
109
           and this interface has to be mounted. In CDC ECM, the alternate setting 0 has no endpoints.
110
           Only the Alternate Setting 1 has the Bulk IN and OUT endpoints active.  */
111
242
        status =  _ux_device_class_cdc_ecm_activate(command);
112
113
        /* Return the completion status.  */
114
242
        return(status);
115
116
101
    case UX_SLAVE_CLASS_COMMAND_CHANGE:
117
118
        /* The change command is used when the host has sent a SET_INTERFACE command
119
           to go from Alternate Setting 0 to 1 or revert to the default mode.  */
120
101
        status =  _ux_device_class_cdc_ecm_change(command);
121
122
        /* Return the completion status.  */
123
101
        return(status);
124
125
126
236
    case UX_SLAVE_CLASS_COMMAND_DEACTIVATE:
127
128
        /* The deactivate command is used when the device has been extracted.
129
           The device endpoints have to be dismounted and the cdc_ecm thread canceled.  */
130
236
        status =  _ux_device_class_cdc_ecm_deactivate(command);
131
132
        /* Return the completion status.  */
133
236
        return(status);
134
135
8
    case UX_SLAVE_CLASS_COMMAND_REQUEST:
136
137
        /* The request command is used when the host sends a command on the control endpoint.  */
138
8
        status = _ux_device_class_cdc_ecm_control_request(command);
139
140
        /* Return the completion status.  */
141
8
        return(status);
142
143
1
    default:
144
145
        /* Error trap. */
146
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
147
148
        /* If trace is enabled, insert this event into the trace buffer.  */
149
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
150
151
        /* Return an error.  */
152
1
        return(UX_FUNCTION_NOT_SUPPORTED);
153
    }
154
}
155