Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_host_stack.h"
...
...
_ux_host_stack_device_descriptor_read(UX_DEVICE *)
Files
loading...
CodeScopeSTM32 Libraries and Samplesusbxcommon/core/src/ux_host_stack_device_descriptor_read.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** USBX Component */ /** */ /** Host Stack */ /** */... /**************************************************************************/ /**************************************************************************/ /* Include necessary system files. */ #define UX_SOURCE_CODE #include "ux_api.h" #include "ux_host_stack.h" ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _ux_host_stack_device_descriptor_read PORTABLE C */ /* 6.1.10 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function reads the device descriptor. */ /* */ /* INPUT */ /* */ /* device Pointer to device */ /* */ /* OUTPUT */ /* */ /* Completion Status */ /* */ /* CALLS */ /* */ /* _ux_host_stack_transfer_request Process transfer request */ /* _ux_utility_descriptor_parse Parse descriptor */ /* _ux_utility_memory_allocate Allocate memory block */ /* _ux_utility_memory_free Free memory block */ /* */ /* CALLED BY */ /* */ /* USBX Components */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ /* 10-15-2021 Chaoqiong Xiao Modified comment(s), */ /* added bMaxPacketSize0 check,*/ /* resulting in version 6.1.9 */ /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ /* added standalone support, */ /* added class code checking, */ /* resulting in version 6.1.10 */ /* */... /**************************************************************************/ UINT _ux_host_stack_device_descriptor_read(UX_DEVICE *device) { UX_TRANSFER *transfer_request; UINT status; UCHAR * descriptor; UX_ENDPOINT *control_endpoint; /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_DEVICE_DESCRIPTOR_READ, device, 0, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0) /* Retrieve the pointer to the control endpoint. */ control_endpoint = &device -> ux_device_control_endpoint; transfer_request = &control_endpoint -> ux_endpoint_transfer_request; /* Need to allocate memory for the descriptor. */ descriptor = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, UX_DEVICE_DESCRIPTOR_LENGTH); if (descriptor == UX_NULL) return(UX_MEMORY_INSUFFICIENT); /* Create a transfer_request for the GET_DESCRIPTOR request. The first transfer_request asks for the first 8 bytes only. This way we will know the real MaxPacketSize value for the control endpoint. *//* ... */ transfer_request -> ux_transfer_request_data_pointer = descriptor; transfer_request -> ux_transfer_request_requested_length = 8; transfer_request -> ux_transfer_request_function = UX_GET_DESCRIPTOR; transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_DEVICE; transfer_request -> ux_transfer_request_value = UX_DEVICE_DESCRIPTOR_ITEM << 8; transfer_request -> ux_transfer_request_index = 0; #if defined(UX_HOST_STANDALONE) device -> ux_device_enum_trans = transfer_request; status = UX_SUCCESS; return(status);/* ... */ #else /* Send request to HCD layer. */ status = _ux_host_stack_transfer_request(transfer_request); /* Check for correct transfer and entire descriptor returned. */ if ((status == UX_SUCCESS) && (transfer_request -> ux_transfer_request_actual_length == 8)) { /* Parse the device descriptor and create the local descriptor. */ _ux_utility_descriptor_parse(descriptor, _ux_system_device_descriptor_structure, UX_DEVICE_DESCRIPTOR_ENTRIES, (UCHAR *) &device -> ux_device_descriptor); }if ((status == UX_SUCCESS) && (transfer_request -> ux_transfer_request_actual_length == 8)) { ... } else { /* Free all used resources. */ _ux_utility_memory_free(descriptor); /* Return completion status. */ return(status); }else { ... } /* Validate the bMaxPacketSize0. */ if (device -> ux_device_descriptor.bMaxPacketSize0 != 8 && device -> ux_device_descriptor.bMaxPacketSize0 != 16 && device -> ux_device_descriptor.bMaxPacketSize0 != 32 && device -> ux_device_descriptor.bMaxPacketSize0 != 64) { _ux_utility_memory_free(descriptor); return(UX_DESCRIPTOR_CORRUPTED); }if (device -> ux_device_descriptor.bMaxPacketSize0 != 8 && device -> ux_device_descriptor.bMaxPacketSize0 != 16 && device -> ux_device_descriptor.bMaxPacketSize0 != 32 && device -> ux_device_descriptor.bMaxPacketSize0 != 64) { ... } #if defined(UX_HOST_DEVICE_CLASS_CODE_VALIDATION_ENABLE) /* Validate the USB-IF bDeviceClass class code. */ switch(device -> ux_device_descriptor.bDeviceClass) { case 0x00: /* Fall through. */ case 0x02: /* Fall through. */ case 0x09: /* Fall through. */ case 0x11: /* Fall through. */ case 0xDC: /* Fall through. */ case 0xEF: /* Fall through. */ case 0xFF: break;case 0xFF: default: /* Invalid device class code. */ _ux_utility_memory_free(descriptor); return(UX_DESCRIPTOR_CORRUPTED);default }switch (device -> ux_device_descriptor.bDeviceClass) { ... } /* ... */#endif /* Update the max packet size value for the endpoint. */ control_endpoint -> ux_endpoint_descriptor.wMaxPacketSize = device -> ux_device_descriptor.bMaxPacketSize0; /* Create a transfer_request for the GET_DESCRIPTOR request. This time, we have the complete length */ transfer_request -> ux_transfer_request_data_pointer = descriptor; transfer_request -> ux_transfer_request_requested_length = UX_DEVICE_DESCRIPTOR_LENGTH; transfer_request -> ux_transfer_request_function = UX_GET_DESCRIPTOR; transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_DEVICE; transfer_request -> ux_transfer_request_value = UX_DEVICE_DESCRIPTOR_ITEM << 8; transfer_request -> ux_transfer_request_index = 0; transfer_request -> ux_transfer_request_packet_length = device -> ux_device_descriptor.bMaxPacketSize0; /* Send request to HCD layer. */ status = _ux_host_stack_transfer_request(transfer_request); /* Check for correct transfer and entire descriptor returned. */ if ((status == UX_SUCCESS) && (transfer_request -> ux_transfer_request_actual_length == UX_DEVICE_DESCRIPTOR_LENGTH)) { /* Parse the device descriptor and create the local descriptor. */ _ux_utility_descriptor_parse(descriptor, _ux_system_device_descriptor_structure, UX_DEVICE_DESCRIPTOR_ENTRIES, (UCHAR *) &device -> ux_device_descriptor); }if ((status == UX_SUCCESS) && (transfer_request -> ux_transfer_request_actual_length == UX_DEVICE_DESCRIPTOR_LENGTH)) { ... } else { /* Error trap. */ _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_DESCRIPTOR_CORRUPTED); /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor, 0, 0, UX_TRACE_ERRORS, 0, 0) /* The device descriptor does not contain the right amount of data. Maybe corruption. */ status = UX_DESCRIPTOR_CORRUPTED; }else { ... } /* Free all used resources. */ _ux_utility_memory_free(descriptor); /* Return completion status. */ return(status); /* ... */ #endif }{ ... }