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 /** */
16 /** USBX Component */
17 /** */
18 /** Generic Serial Host module 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_gser.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_gser_command PORTABLE C */
38 /* 6.1.10 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function will send a command to the ACM device. The command */
46 /* can be one of the following : */
47 /* SET_CONTROL */
48 /* SET_LINE */
49 /* SEND_BREAK */
50 /* */
51 /* */
52 /* INPUT */
53 /* */
54 /* acm Pointer to acm class */
55 /* command command value */
56 /* value value to be sent in the */
57 /* command request */
58 /* data_buffer buffer to be sent */
59 /* data_length length of the buffer to send */
60 /* */
61 /* */
62 /* OUTPUT */
63 /* */
64 /* Completion Status */
65 /* */
66 /* CALLS */
67 /* */
68 /* _ux_host_stack_transfer_request Process transfer request */
69 /* _ux_host_semaphore_get Get semaphore */
70 /* */
71 /* CALLED BY */
72 /* */
73 /* Storage Class */
74 /* */
75 /* RELEASE HISTORY */
76 /* */
77 /* DATE NAME DESCRIPTION */
78 /* */
79 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
80 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
81 /* resulting in version 6.1 */
82 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
83 /* refined macros names, */
84 /* resulting in version 6.1.10 */
85 /* */
86 /**************************************************************************/
_ux_host_class_gser_command(UX_HOST_CLASS_GSER * gser,ULONG interface_index,ULONG command,ULONG value,UCHAR * data_buffer,ULONG data_length)87 UINT _ux_host_class_gser_command(UX_HOST_CLASS_GSER *gser, ULONG interface_index, ULONG command,
88 ULONG value, UCHAR *data_buffer, ULONG data_length)
89 {
90
91 UX_ENDPOINT *control_endpoint;
92 UX_TRANSFER *transfer_request;
93 UINT status;
94 ULONG request_direction;
95
96
97 /* We need to get the default control endpoint transfer request pointer. */
98 control_endpoint = &gser -> ux_host_class_gser_device -> ux_device_control_endpoint;
99 transfer_request = &control_endpoint -> ux_endpoint_transfer_request;
100
101 /* Check the direction of the command. */
102 switch (command)
103 {
104
105 case UX_HOST_CLASS_GSER_REQ_SEND_ENCAPSULATED_COMMAND :
106 case UX_HOST_CLASS_GSER_REQ_SET_COMM_FEATURE :
107 case UX_HOST_CLASS_GSER_REQ_CLEAR_COMM_FEATURE :
108 case UX_HOST_CLASS_GSER_REQ_SET_AUX_LINE_STATE :
109 case UX_HOST_CLASS_GSER_REQ_SET_HOOK_STATE :
110 case UX_HOST_CLASS_GSER_REQ_PULSE_SETUP :
111 case UX_HOST_CLASS_GSER_REQ_SEND_PULSE :
112 case UX_HOST_CLASS_GSER_REQ_SET_PUSLE_TIME :
113 case UX_HOST_CLASS_GSER_REQ_RING_AUX_JACK :
114 case UX_HOST_CLASS_GSER_REQ_SET_LINE_CODING :
115 case UX_HOST_CLASS_GSER_REQ_SET_LINE_STATE :
116 case UX_HOST_CLASS_GSER_REQ_SEND_BREAK :
117 case UX_HOST_CLASS_GSER_REQ_SET_RINGER_PARMS :
118 case UX_HOST_CLASS_GSER_REQ_SET_OPERATION_PARMS :
119 case UX_HOST_CLASS_GSER_REQ_SET_LINE_PARMS :
120
121 /* Direction is out */
122 request_direction = UX_REQUEST_OUT;
123 break;
124
125
126 case UX_HOST_CLASS_GSER_REQ_GET_ENCAPSULATED_COMMAND :
127 case UX_HOST_CLASS_GSER_REQ_GET_COMM_FEATURE :
128 case UX_HOST_CLASS_GSER_REQ_GET_LINE_CODING :
129 case UX_HOST_CLASS_GSER_REQ_GET_RINGER_PARMS :
130 case UX_HOST_CLASS_GSER_REQ_GET_OPERATION_PARMS :
131 case UX_HOST_CLASS_GSER_REQ_GET_LINE_PARMS :
132
133 /* Direction is in */
134 request_direction = UX_REQUEST_IN;
135 break;
136
137
138 default :
139
140 return(UX_ERROR);
141
142 }
143
144 /* Protect the control endpoint semaphore here. It will be unprotected in the
145 transfer request function. */
146 status = _ux_host_semaphore_get(&gser -> ux_host_class_gser_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER);
147
148 /* Check for status. */
149 if (status != UX_SUCCESS)
150
151 /* Something went wrong. */
152 return(status);
153
154 /* Create a transfer_request for the request. */
155 transfer_request -> ux_transfer_request_data_pointer = data_buffer;
156 transfer_request -> ux_transfer_request_requested_length = data_length;
157 transfer_request -> ux_transfer_request_function = command;
158 transfer_request -> ux_transfer_request_type = request_direction | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
159 transfer_request -> ux_transfer_request_value = value;
160 transfer_request -> ux_transfer_request_index = gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_interface->ux_interface_descriptor.bInterfaceNumber;
161
162 /* Send request to HCD layer. */
163 status = _ux_host_stack_transfer_request(transfer_request);
164
165 /* Return completion status. */
166 return(status);
167 }
168
169