Line | Count | Source |
1 | | /* |
2 | | * This file is auto-generated, do not modify! |
3 | | * |
4 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | | */ |
6 | | |
7 | | #include "config.h" |
8 | | |
9 | | #include <glib.h> |
10 | | |
11 | | #include "fu-dpaux-struct.h" |
12 | | #include "fu-byte-array.h" |
13 | | #include "fu-mem-private.h" |
14 | | #include "fu-string.h" |
15 | | |
16 | | #ifdef G_LOG_DOMAIN |
17 | | #undef G_LOG_DOMAIN |
18 | | #endif |
19 | 0 | #define G_LOG_DOMAIN "FuStruct" |
20 | | /** |
21 | | * fu_struct_dpaux_dpcd_ref: (skip): |
22 | | **/ |
23 | | FuStructDpauxDpcd * |
24 | | fu_struct_dpaux_dpcd_ref(FuStructDpauxDpcd *st) |
25 | 0 | { |
26 | 0 | g_return_val_if_fail(st != NULL, NULL); |
27 | 0 | st->refcount++; |
28 | 0 | return st; |
29 | 0 | } |
30 | | /** |
31 | | * fu_struct_dpaux_dpcd_unref: (skip): |
32 | | **/ |
33 | | void |
34 | | fu_struct_dpaux_dpcd_unref(FuStructDpauxDpcd *st) |
35 | 0 | { |
36 | 0 | g_return_if_fail(st != NULL); |
37 | 0 | if (st->refcount == 0) { |
38 | 0 | g_critical("FuStructDpauxDpcd refcount already zero"); |
39 | 0 | return; |
40 | 0 | } |
41 | 0 | if (--st->refcount > 0) |
42 | 0 | return; |
43 | 0 | if (st->buf != NULL) |
44 | 0 | g_byte_array_unref(st->buf); |
45 | 0 | g_free(st); |
46 | 0 | } |
47 | | /** |
48 | | * fu_struct_dpaux_dpcd_new_internal: (skip): |
49 | | **/ |
50 | | static FuStructDpauxDpcd * |
51 | | fu_struct_dpaux_dpcd_new_internal(void) |
52 | 0 | { |
53 | 0 | FuStructDpauxDpcd *st = g_new0(FuStructDpauxDpcd, 1); |
54 | 0 | st->refcount = 1; |
55 | 0 | return st; |
56 | 0 | } |
57 | | |
58 | | /* getters */ |
59 | | /** |
60 | | * fu_struct_dpaux_dpcd_get_ieee_oui: (skip): |
61 | | **/ |
62 | | guint32 |
63 | | fu_struct_dpaux_dpcd_get_ieee_oui(const FuStructDpauxDpcd *st) |
64 | 0 | { |
65 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
66 | 0 | return fu_memread_uint24(st->buf->data + 0, G_BIG_ENDIAN); |
67 | 0 | } |
68 | | /** |
69 | | * fu_struct_dpaux_dpcd_get_dev_id: (skip): |
70 | | **/ |
71 | | gchar * |
72 | | fu_struct_dpaux_dpcd_get_dev_id(const FuStructDpauxDpcd *st) |
73 | 0 | { |
74 | 0 | g_return_val_if_fail(st != NULL, NULL); |
75 | 0 | return fu_memstrsafe(st->buf->data, st->buf->len, 3, 6, NULL); |
76 | 0 | } |
77 | | /** |
78 | | * fu_struct_dpaux_dpcd_get_hw_rev: (skip): |
79 | | **/ |
80 | | guint8 |
81 | | fu_struct_dpaux_dpcd_get_hw_rev(const FuStructDpauxDpcd *st) |
82 | 0 | { |
83 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
84 | 0 | return st->buf->data[9]; |
85 | 0 | } |
86 | | /** |
87 | | * fu_struct_dpaux_dpcd_get_fw_ver: (skip): |
88 | | **/ |
89 | | guint32 |
90 | | fu_struct_dpaux_dpcd_get_fw_ver(const FuStructDpauxDpcd *st) |
91 | 0 | { |
92 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
93 | 0 | return fu_memread_uint24(st->buf->data + 10, G_BIG_ENDIAN); |
94 | 0 | } |
95 | | |
96 | | /* setters */ |
97 | | /** |
98 | | * fu_struct_dpaux_dpcd_to_string: (skip): |
99 | | **/ |
100 | | static gchar * |
101 | | fu_struct_dpaux_dpcd_to_string(const FuStructDpauxDpcd *st) |
102 | 0 | { |
103 | 0 | g_autoptr(GString) str = g_string_new("FuStructDpauxDpcd:\n"); |
104 | 0 | g_return_val_if_fail(st != NULL, NULL); |
105 | 0 | g_string_append_printf(str, " ieee_oui: 0x%x\n", |
106 | 0 | (guint) fu_struct_dpaux_dpcd_get_ieee_oui(st)); |
107 | 0 | { |
108 | 0 | g_autofree gchar *tmp = fu_struct_dpaux_dpcd_get_dev_id(st); |
109 | 0 | if (tmp != NULL) |
110 | 0 | g_string_append_printf(str, " dev_id: %s\n", tmp); |
111 | 0 | } |
112 | 0 | g_string_append_printf(str, " hw_rev: 0x%x\n", |
113 | 0 | (guint) fu_struct_dpaux_dpcd_get_hw_rev(st)); |
114 | 0 | g_string_append_printf(str, " fw_ver: 0x%x\n", |
115 | 0 | (guint) fu_struct_dpaux_dpcd_get_fw_ver(st)); |
116 | 0 | if (str->len > 0) |
117 | 0 | g_string_set_size(str, str->len - 1); |
118 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
119 | 0 | } |
120 | | static gboolean |
121 | | fu_struct_dpaux_dpcd_validate_internal(FuStructDpauxDpcd *st, GError **error) |
122 | 0 | { |
123 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
124 | 0 | return TRUE; |
125 | 0 | } |
126 | | static gboolean |
127 | | fu_struct_dpaux_dpcd_parse_internal(FuStructDpauxDpcd *st, GError **error) |
128 | 0 | { |
129 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
130 | 0 | g_autofree gchar *str = fu_struct_dpaux_dpcd_to_string(st); |
131 | 0 | g_debug("%s", str); |
132 | 0 | } |
133 | 0 | if (!fu_struct_dpaux_dpcd_validate_internal(st, error)) |
134 | 0 | return FALSE; |
135 | 0 | return TRUE; |
136 | 0 | } |
137 | | |
138 | | /** |
139 | | * fu_struct_dpaux_dpcd_parse: (skip): |
140 | | **/ |
141 | | FuStructDpauxDpcd * |
142 | | fu_struct_dpaux_dpcd_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error) |
143 | 0 | { |
144 | 0 | g_autoptr(FuStructDpauxDpcd) st = fu_struct_dpaux_dpcd_new_internal(); |
145 | 0 | g_return_val_if_fail(buf != NULL, NULL); |
146 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, NULL); |
147 | 0 | if (!fu_memchk_read(bufsz, offset, 13, error)) { |
148 | 0 | g_prefix_error_literal(error, "invalid struct FuStructDpauxDpcd: "); |
149 | 0 | return NULL; |
150 | 0 | } |
151 | 0 | st->buf = g_byte_array_new(); |
152 | 0 | g_byte_array_append(st->buf, buf + offset, 13); |
153 | 0 | if (!fu_struct_dpaux_dpcd_parse_internal(st, error)) |
154 | 0 | return NULL; |
155 | 0 | return g_steal_pointer(&st); |
156 | 0 | } |