edid-decode: add --replace-serial-numbers option
[edid-decode.git] / parse-ls-ext-block.cpp
blob9152eb175934e92971fcaf9291d1ad8266ba6400
1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright 2019-2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
5 * Author: Hans Verkuil <hverkuil-cisco@xs4all.nl>
6 */
8 #include "edid-decode.h"
10 static void parse_string(const char *name, const unsigned char *x)
12 if (!*x)
13 return;
14 printf(" %s: ", name);
15 hex_block("", x + 1, *x, true, *x);
18 // Note that support for UTF 16BE and 32BE is missing.
19 // I have never seen LS-EXT support in real EDIDs, so that
20 // shouldn't be a problem.
21 void edid_state::parse_string_table(const unsigned char *x)
23 printf(" UTF Type: ");
24 switch (x[0] & 7) {
25 case 0: printf("UTF 8\n"); break;
26 case 1: printf("UTF 16BE\n"); break;
27 case 2: printf("UTF 32BE\n"); break;
28 default:
29 printf("Unknown (0x%02x)\n", x[0] & 7);
30 fail("Unknown UTF Type (0x%02x).\n", x[0] & 7);
31 break;
33 printf(" Country Code ID (ISO 3166-3): %u\n", ((x[1] & 0x3f) << 8) | x[2]);
35 if (x[3] || x[4]) {
36 char name[4];
38 name[0] = ((x[3] & 0x7c) >> 2) + '@';
39 name[1] = ((x[3] & 0x03) << 3) + ((x[4] & 0xe0) >> 5) + '@';
40 name[2] = (x[4] & 0x1f) + '@';
41 name[3] = 0;
42 if (name[0] == '@') name[0] = ' ';
43 if (name[1] == '@') name[1] = ' ';
44 if (name[2] == '@') name[2] = ' ';
45 printf(" Language ID: '%s'\n", name);
47 x += 5;
48 parse_string("Manufacturer Name", x);
49 x += x[0] + 1;
50 parse_string("Model Name", x);
51 x += x[0] + 1;
52 if (hide_serial_numbers)
53 printf(" Serial Number: ...\n");
54 else
55 parse_string("Serial Number", x);
58 void edid_state::preparse_ls_ext_block(unsigned char *x)
60 unsigned char *orig = x;
62 if (!replace_serial_numbers)
63 return;
65 x += 5;
67 while (x[0] && x + x[0] < orig + 127) {
68 unsigned char *s = x + 6;
70 s += s[0] + 1;
71 s += s[0] + 1;
72 for (unsigned i = 1; i <= s[0]; i++)
73 s[i] = i <= 6 ? '0' + i : ' ';
74 x += x[0];
78 void edid_state::parse_ls_ext_block(const unsigned char *x)
80 const unsigned char *orig = x;
82 printf(" Version: %u.%u\n Unicode Version: %u.%u.%u\n",
83 x[1], x[2], (x[3] >> 4), x[3] & 0x0f, x[4]);
84 x += 5;
86 while (x[0] && x + x[0] < orig + 127) {
87 parse_string_table(x + 1);
88 x += x[0];
90 unused_bytes = orig + 127 - x;
91 if (!memchk(x, unused_bytes)) {
92 data_block.clear();
93 fail("Non-zero values in unused space.\n");