1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
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 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_device_class_cdc_ecm_control_request            PORTABLE C      */
36 /*                                                           6.1.12       */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function manages the based sent by the host on the control     */
44 /*    endpoints with a CLASS or VENDOR SPECIFIC type.                     */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    cdc_ecm                           Pointer to cdc_ecm class          */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    None                                                                */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    _ux_utility_short_get                 Get 16-bit value              */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    CDC_ECM Class                                                       */
61 /*                                                                        */
62 /*  RELEASE HISTORY                                                       */
63 /*                                                                        */
64 /*    DATE              NAME                      DESCRIPTION             */
65 /*                                                                        */
66 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
67 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
68 /*                                            resulting in version 6.1    */
69 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
70 /*                                            fixed parameter/variable    */
71 /*                                            names conflict C++ keyword, */
72 /*                                            resulting in version 6.1.12 */
73 /*                                                                        */
74 /**************************************************************************/
_ux_device_class_cdc_ecm_control_request(UX_SLAVE_CLASS_COMMAND * command)75 UINT  _ux_device_class_cdc_ecm_control_request(UX_SLAVE_CLASS_COMMAND *command)
76 {
77 
78 UX_SLAVE_TRANSFER       *transfer_request;
79 UX_SLAVE_DEVICE         *device;
80 ULONG                   request;
81 ULONG                   request_value;
82 UX_SLAVE_CLASS          *class_ptr;
83 UX_SLAVE_CLASS_CDC_ECM  *cdc_ecm;
84 
85     /* Get the pointer to the device.  */
86     device =  &_ux_system_slave -> ux_system_slave_device;
87 
88     /* Get the pointer to the transfer request associated with the control endpoint.  */
89     transfer_request =  &device -> ux_slave_device_control_endpoint.ux_slave_endpoint_transfer_request;
90 
91     /* Extract all necessary fields of the request.  */
92     request =  *(transfer_request -> ux_slave_transfer_request_setup + UX_SETUP_REQUEST);
93     request_value  =   _ux_utility_short_get(transfer_request -> ux_slave_transfer_request_setup + UX_SETUP_VALUE);
94 
95     /* Get the class container.  */
96     class_ptr =  command -> ux_slave_class_command_class_ptr;
97 
98     /* Get the cdc_ecm instance from this class container.  */
99     cdc_ecm =  (UX_SLAVE_CLASS_CDC_ECM *) class_ptr -> ux_slave_class_instance;
100 
101     /* Here we proceed only the standard request we know of at the device level.  */
102     switch (request)
103     {
104 
105         case UX_DEVICE_CLASS_CDC_ECM_SET_ETHERNET_MULTICAST_FILTER                :
106 
107             /* Save the multicast filter.  */
108             cdc_ecm -> ux_slave_class_cdc_ecm_ethernet_multicast_filter =  request_value;
109             break ;
110 
111         case UX_DEVICE_CLASS_CDC_ECM_SET_ETHERNET_POWER_MANAGEMENT_FILTER        :
112 
113             /* Save the power management filter.  */
114             cdc_ecm -> ux_slave_class_cdc_ecm_ethernet_power_management_filter =  request_value;
115             break ;
116 
117         case UX_DEVICE_CLASS_CDC_ECM_SET_ETHERNET_PACKET_FILTER                    :
118 
119             /* Save the packet filter.  */
120             cdc_ecm -> ux_slave_class_cdc_ecm_ethernet_packet_filter =  request_value;
121             break ;
122 
123         case UX_DEVICE_CLASS_CDC_ECM_GET_ETHERNET_POWER_MANAGEMENT_FILTER        :
124         default:
125 
126             /* Unknown function. It's not handled.  */
127             return(UX_ERROR);
128     }
129 
130     /* It's handled.  */
131     return(UX_SUCCESS);
132 }
133 
134