1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include <mos/types.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7
8static const struct
9{
10 u8 base_class;
11 u8 sub_class;
12 u8 prog_if;
13 const char *name;
14} known_classes[] = {
15#define _X(x, y, z, name) { x, y, z, name },
16#include "builtin.h"
17#undef _X
18};
19
20const char *get_known_class_name(u8 base_class, u8 sub_class, u8 prog_if)
21{
22 for (size_t i = 0; i < MOS_ARRAY_SIZE(known_classes); i++)
23 {
24 const u8 k_baseclass = known_classes[i].base_class;
25 const u8 k_subclass = known_classes[i].sub_class;
26 const u8 k_progif = known_classes[i].prog_if;
27
28 if (k_baseclass == base_class && k_subclass == sub_class && k_progif == prog_if)
29 return strdup(string: known_classes[i].name);
30 }
31
32 char *name = malloc(size: 64);
33 sprintf(buffer: name, format: "Unknown class: %02x:%02x:%02x", base_class, sub_class, prog_if);
34 return name;
35}
36