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 /** Printer 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_printer.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_printer_device_id_get PORTABLE C */
38 /* 6.1.12 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function obtains the printer IEEE 1284 device ID string */
46 /* (including length in the first two bytes in big endian format). */
47 /* */
48 /* INPUT */
49 /* */
50 /* printer Pointer to printer class */
51 /* descriptor_buffer Pointer to a buffer to fill */
52 /* IEEE 1284 device ID string */
53 /* (including length in the */
54 /* first two bytes in BE format) */
55 /* length Length of buffer in bytes */
56 /* */
57 /* OUTPUT */
58 /* */
59 /* Completion Status */
60 /* */
61 /* CALLS */
62 /* */
63 /* _ux_host_stack_transfer_request Process transfer request */
64 /* _ux_utility_memory_allocate Allocate memory block */
65 /* _ux_utility_memory_compare Compare memory block */
66 /* _ux_utility_memory_copy Copy memory block */
67 /* _ux_utility_memory_free Free memory block */
68 /* _ux_utility_short_get_big_endian Get 16-bit value */
69 /* */
70 /* CALLED BY */
71 /* */
72 /* Application */
73 /* */
74 /* RELEASE HISTORY */
75 /* */
76 /* DATE NAME DESCRIPTION */
77 /* */
78 /* 02-02-2021 Chaoqiong Xiao Initial Version 6.1.4 */
79 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
80 /* added standalone support, */
81 /* resulting in version 6.1.10 */
82 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
83 /* fixed parameter/variable */
84 /* names conflict C++ keyword, */
85 /* resulting in version 6.1.12 */
86 /* */
87 /**************************************************************************/
_ux_host_class_printer_device_id_get(UX_HOST_CLASS_PRINTER * printer,UCHAR * descriptor_buffer,ULONG length)88 UINT _ux_host_class_printer_device_id_get(UX_HOST_CLASS_PRINTER *printer, UCHAR *descriptor_buffer, ULONG length)
89 {
90 #if defined(UX_HOST_STANDALONE)
91 UX_INTERRUPT_SAVE_AREA
92 #endif
93 UX_INTERFACE *interface_ptr;
94 UX_ENDPOINT *control_endpoint;
95 UX_TRANSFER *transfer_request;
96 UINT status;
97
98
99 /* If trace is enabled, insert this event into the trace buffer. */
100 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_PRINTER_DEVICE_ID_GET, printer, descriptor_buffer, length, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
101
102 /* Protect thread reentry to this instance. */
103 #if defined(UX_HOST_STANDALONE)
104 UX_DISABLE
105 if ((printer -> ux_host_class_printer_flags & UX_HOST_CLASS_PRINTER_FLAG_LOCK) ||
106 (printer -> ux_host_class_printer_device -> ux_device_flags & UX_DEVICE_FLAG_LOCK))
107 {
108 UX_RESTORE
109 return(UX_BUSY);
110 }
111 printer -> ux_host_class_printer_flags |= UX_HOST_CLASS_PRINTER_FLAG_LOCK;
112 printer -> ux_host_class_printer_device -> ux_device_flags |= UX_DEVICE_FLAG_LOCK;
113 UX_RESTORE
114 #else
115
116 status = _ux_host_semaphore_get(&printer -> ux_host_class_printer_semaphore, UX_WAIT_FOREVER);
117 if (status != UX_SUCCESS)
118 return(status);
119
120 /* Protect the control endpoint semaphore here. It will be unprotected in the
121 transfer request function. */
122 status = _ux_host_semaphore_get(&printer -> ux_host_class_printer_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER);
123
124 /* Check for status. */
125 if (status != UX_SUCCESS)
126 {
127 _ux_host_semaphore_put(&printer -> ux_host_class_printer_semaphore);
128 return(status);
129 }
130 #endif
131
132 /* We need to get the default control endpoint transfer request pointer. */
133 control_endpoint = &printer -> ux_host_class_printer_device -> ux_device_control_endpoint;
134 transfer_request = &control_endpoint -> ux_endpoint_transfer_request;
135
136 /* Need interface for wIndex. */
137 interface_ptr = printer -> ux_host_class_printer_interface;
138
139 /* Create a transfer request for the GET_DEVICE_ID request. */
140 transfer_request -> ux_transfer_request_data_pointer = descriptor_buffer;
141 transfer_request -> ux_transfer_request_requested_length = length;
142 transfer_request -> ux_transfer_request_function = UX_HOST_CLASS_PRINTER_GET_DEVICE_ID;
143 transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
144 transfer_request -> ux_transfer_request_value = 0; /* Do not support multiple configuration for now. */
145 transfer_request -> ux_transfer_request_index = (interface_ptr -> ux_interface_descriptor.bInterfaceNumber << 8) |
146 (interface_ptr -> ux_interface_descriptor.bAlternateSetting );
147
148 #if defined(UX_HOST_STANDALONE)
149
150 /* Enable auto unlock device. */
151 transfer_request -> ux_transfer_request_flags |= UX_TRANSFER_FLAG_AUTO_DEVICE_UNLOCK;
152 #endif
153
154 /* Send request to HCD layer. */
155 status = _ux_host_stack_transfer_request(transfer_request);
156
157 /* Unprotect thread reentry to this instance. */
158 _ux_host_class_printer_unlock(printer);
159
160 /* Return completion status. */
161 return(status);
162 }
163