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: 2024-12-12 17:16:36 Branches: 12 12 100.0 %

Line Branch Exec Source
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
/**                                                                       */
14
/** USBX Component                                                        */
15
/**                                                                       */
16
/**   Device CDC_ECM 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_cdc_ecm.h"
28
#include "ux_device_stack.h"
29
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _ux_device_class_cdc_ecm_entry                      PORTABLE C      */
36
/*                                                           6.x          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Chaoqiong Xiao, Microsoft Corporation                               */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function is the entry point of the cdc_ecm class. It           */
44
/*    will be called by the device stack enumeration module when the      */
45
/*    host has sent a SET_CONFIGURATION command and the cdc_ecm interface */
46
/*    needs to be mounted.                                                */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    command                               Pointer to class command      */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    Completion Status                                                   */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _ux_device_class_cdc_ecm_initialize       Initialize cdc_ecm class  */
59
/*    _ux_device_class_cdc_ecm_uninitialize     Uninitialize cdc_ecm class*/
60
/*    _ux_device_class_cdc_ecm_activate         Activate cdc_ecm class    */
61
/*    _ux_device_class_cdc_ecm_deactivate       Deactivate cdc_ecm class  */
62
/*    _ux_device_class_cdc_ecm_change           Alternate setting change  */
63
/*    _ux_device_class_cdc_ecm_control_request  Request control           */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    CDC_ECM Class                                                       */
68
/*                                                                        */
69
/*  RELEASE HISTORY                                                       */
70
/*                                                                        */
71
/*    DATE              NAME                      DESCRIPTION             */
72
/*                                                                        */
73
/*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
74
/*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
75
/*                                            resulting in version 6.1    */
76
/*  xx-xx-xxxx     Mohamed ayed             Modified comment(s),          */
77
/*                                            fix typo,                   */
78
/*                                            remove extra spaces,        */
79
/*                                            resulting in version 6.x    */
80
/*                                                                        */
81
/**************************************************************************/
82
906
UINT  _ux_device_class_cdc_ecm_entry(UX_SLAVE_CLASS_COMMAND *command)
83
{
84
85
UINT        status;
86
87
    /* The command request will tell us we need to do here, either a enumeration
88
       query, an activation or a deactivation.  */
89


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