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 /** */ 15 /** USBX Component */ 16 /** */ 17 /** HID Class */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 23 /* Include necessary system files. */ 24 25 #define UX_SOURCE_CODE 26 27 #include "ux_api.h" 28 #include "ux_host_class_hid.h" 29 #include "ux_host_stack.h" 30 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _ux_host_class_hid_instance_clean PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* Chaoqiong Xiao, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function cleans all the components of a HID instance. */ 45 /* */ 46 /* INPUT */ 47 /* */ 48 /* hid Pointer to HID class */ 49 /* */ 50 /* OUTPUT */ 51 /* */ 52 /* Completion Status */ 53 /* */ 54 /* CALLS */ 55 /* */ 56 /* _ux_utility_memory_free Release memory block */ 57 /* */ 58 /* CALLED BY */ 59 /* */ 60 /* HID 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 /* */ 70 /**************************************************************************/ _ux_host_class_hid_instance_clean(UX_HOST_CLASS_HID * hid)71UINT _ux_host_class_hid_instance_clean(UX_HOST_CLASS_HID *hid) 72 { 73 74 UX_HOST_CLASS_HID_PARSER *hid_parser; 75 UX_HOST_CLASS_HID_REPORT *hid_report; 76 UX_HOST_CLASS_HID_REPORT *hid_next_report; 77 UX_HOST_CLASS_HID_FIELD *hid_field; 78 UX_HOST_CLASS_HID_FIELD *hid_next_field; 79 80 81 /* Get the parser structure pointer. */ 82 hid_parser = &hid -> ux_host_class_hid_parser; 83 84 /* Each report list of the parser should be cleaned: Input report. */ 85 hid_report = hid_parser -> ux_host_class_hid_parser_input_report; 86 while (hid_report != UX_NULL) 87 { 88 89 /* Get the next report before we clean the current report. */ 90 hid_next_report = hid_report -> ux_host_class_hid_report_next_report; 91 92 /* Get the first field in the report. */ 93 hid_field = hid_report -> ux_host_class_hid_report_field; 94 95 /* Clean all the fields attached. */ 96 while (hid_field != UX_NULL) 97 { 98 99 /* Get the next field before we clean the current field. */ 100 hid_next_field = hid_field -> ux_host_class_hid_field_next_field; 101 102 /* Free the usage table. */ 103 if (hid_field -> ux_host_class_hid_field_usages != UX_NULL) 104 _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_usages); 105 106 /* Free the value table. */ 107 if (hid_field -> ux_host_class_hid_field_values != UX_NULL) 108 _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_values); 109 110 /* Now free the field memory. */ 111 _ux_utility_memory_free(hid_field); 112 113 /* Next field. */ 114 hid_field = hid_next_field; 115 } 116 117 /* Free the report. */ 118 _ux_utility_memory_free(hid_report); 119 120 /* Next report. */ 121 hid_report = hid_next_report; 122 } 123 124 /* Each report list of the parser should be cleaned: Output report. */ 125 hid_report = hid_parser -> ux_host_class_hid_parser_output_report; 126 while (hid_report != UX_NULL) 127 { 128 129 /* Get the next report before we clean the current report. */ 130 hid_next_report = hid_report -> ux_host_class_hid_report_next_report; 131 132 /* Get the first field in the report. */ 133 hid_field = hid_report -> ux_host_class_hid_report_field; 134 135 /* Clean all the fields attached. */ 136 while (hid_field != UX_NULL) 137 { 138 139 /* Get the next field before we clean the current field. */ 140 hid_next_field = hid_field -> ux_host_class_hid_field_next_field; 141 142 /* Free the usage table. */ 143 if (hid_field -> ux_host_class_hid_field_usages != UX_NULL) 144 _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_usages); 145 146 /* Free the value table. */ 147 if (hid_field -> ux_host_class_hid_field_values != UX_NULL) 148 _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_values); 149 150 /* Now free the field memory. */ 151 _ux_utility_memory_free(hid_field); 152 153 /* Next field. */ 154 hid_field = hid_next_field; 155 } 156 157 /* Free the report. */ 158 _ux_utility_memory_free(hid_report); 159 160 /* Next report. */ 161 hid_report = hid_next_report; 162 } 163 164 /* Each report list of the parser should be cleaned: Feature report. */ 165 hid_report = hid_parser -> ux_host_class_hid_parser_feature_report; 166 while (hid_report != UX_NULL) 167 { 168 169 /* Get the next report before we clean the current report. */ 170 hid_next_report = hid_report -> ux_host_class_hid_report_next_report; 171 172 /* Get the first field in the report. */ 173 hid_field = hid_report -> ux_host_class_hid_report_field; 174 175 /* Clean all the fields attached. */ 176 while (hid_field != UX_NULL) 177 { 178 179 /* Get the next field before we clean the current field. */ 180 hid_next_field = hid_field -> ux_host_class_hid_field_next_field; 181 182 /* Free the usage table. */ 183 if (hid_field -> ux_host_class_hid_field_usages != UX_NULL) 184 _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_usages); 185 186 /* Free the value table. */ 187 if (hid_field -> ux_host_class_hid_field_values != UX_NULL) 188 _ux_utility_memory_free(hid_field -> ux_host_class_hid_field_values); 189 190 /* Now free the field memory. */ 191 _ux_utility_memory_free(hid_field); 192 193 /* Next field. */ 194 hid_field = hid_next_field; 195 } 196 197 /* Free the report. */ 198 _ux_utility_memory_free(hid_report); 199 200 /* Next report. */ 201 hid_report = hid_next_report; 202 } 203 204 /* Return successful completion. */ 205 return(UX_SUCCESS); 206 } 207 208