Changeset 6dd929c in mainline
- Timestamp:
- 2011-02-23T18:12:42Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- dde2c90
- Parents:
- 071b5f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/info.c
r071b5f8 r6dd929c 129 129 config_descriptor.total_length); 130 130 131 /* 132 * Dump STRING languages. 133 */ 134 uint8_t *string_descriptor = NULL; 135 size_t string_descriptor_size = 0; 136 rc = usb_request_get_descriptor_alloc(&ctrl_pipe, 137 USB_REQUEST_TYPE_STANDARD, USB_DESCTYPE_STRING, 0, 0, 138 (void **) &string_descriptor, &string_descriptor_size); 139 if (rc != EOK) { 140 fprintf(stderr, 141 NAME ": failed to fetch language table: %s.\n", 142 str_error(rc)); 143 goto leave; 144 } 145 if ((string_descriptor_size <= 2) 146 || ((string_descriptor_size % 2) != 0)) { 147 fprintf(stderr, NAME ": No supported languages.\n"); 148 goto leave; 149 } 150 151 size_t lang_count = (string_descriptor_size - 2) / 2; 152 int *lang_codes = malloc(sizeof(int) * lang_count); 153 size_t i; 154 for (i = 0; i < lang_count; i++) { 155 lang_codes[i] = (string_descriptor[2 + 2 * i + 1] << 8) 156 + string_descriptor[2 + 2 * i]; 157 } 158 159 printf("String languages:"); 160 for (i = 0; i < lang_count; i++) { 161 printf(" 0x%04x", lang_codes[i]); 162 } 163 printf(".\n"); 164 165 free(string_descriptor); 166 free(lang_codes); 167 168 /* 169 * Dump all strings in English (0x0409). 170 */ 171 uint16_t lang = 0x0409; 172 /* 173 * Up to 3 string in device descriptor, 1 for configuration and 174 * one for each interface. 175 */ 176 size_t max_idx = 3 + 1 + config_descriptor.interface_count; 177 size_t idx; 178 for (idx = 1; idx <= max_idx; idx++) { 179 uint8_t *string; 180 size_t string_size; 181 rc = usb_request_get_descriptor_alloc(&ctrl_pipe, 182 USB_REQUEST_TYPE_STANDARD, USB_DESCTYPE_STRING, 183 idx, uint16_host2usb(lang), 184 (void **) &string, &string_size); 185 if (rc == EINTR) { 186 /* Invalid index, skip silently. */ 187 continue; 188 } 189 if (rc != EOK) { 190 fprintf(stderr, 191 NAME ": failed to fetch string #%zu " \ 192 "(lang 0x%04x): %s.\n", 193 idx, (int) lang, str_error(rc)); 194 continue; 195 } 196 /* 197 printf("String #%zu (language 0x%04x):\n", idx, (int) lang); 198 dump_buffer(NULL, 0, 199 string, string_size); 200 */ 201 if (string_size <= 2) { 202 fprintf(stderr, 203 NAME ": no string for index #%zu.\n", idx); 204 free(string); 205 continue; 206 } 207 string_size -= 2; 208 209 size_t string_char_count = string_size / 2; 210 wchar_t *string_chars = malloc(sizeof(wchar_t) * (string_char_count + 1)); 211 assert(string_chars != NULL); 212 for (i = 0; i < string_char_count; i++) { 213 uint16_t uni_char = (string[2 + 2 * i + 1] << 8) 214 + string[2 + 2 * i]; 215 string_chars[i] = uni_char; 216 } 217 string_chars[string_char_count] = 0; 218 free(string); 219 220 char *str = wstr_to_astr(string_chars); 221 assert(str != NULL); 222 free(string_chars); 223 224 printf("String #%zu (language 0x%04x): \"%s\"\n", 225 idx, (int) lang, str); 226 free(str); 227 } 228 131 229 rc = EOK; 230 132 231 leave: 133 232 /* Ignoring errors here. */
Note:
See TracChangeset
for help on using the changeset viewer.