Coverage Report

Created: 2025-07-01 07:09

/work/fu-ebitdo-struct.c
Line
Count
Source (jump to first uncovered line)
1
/* auto-generated, do not modify */
2
#include "config.h"
3
4
#include "fu-ebitdo-struct.h"
5
#include "fu-byte-array.h"
6
#include "fu-mem-private.h"
7
#include "fu-string.h"
8
9
#ifdef G_LOG_DOMAIN
10
  #undef G_LOG_DOMAIN
11
#endif
12
0
#define G_LOG_DOMAIN "FuStruct"
13
14
static const gchar *
15
fu_ebitdo_pkt_type_to_string(FuEbitdoPktType val)
16
0
{
17
0
    if (val == FU_EBITDO_PKT_TYPE_USER_CMD)
18
0
        return "user-cmd";
19
0
    if (val == FU_EBITDO_PKT_TYPE_USER_DATA)
20
0
        return "user-data";
21
0
    if (val == FU_EBITDO_PKT_TYPE_MID_CMD)
22
0
        return "mid-cmd";
23
0
    return NULL;
24
0
}
25
26
const gchar *
27
fu_ebitdo_pkt_cmd_to_string(FuEbitdoPktCmd val)
28
0
{
29
0
    if (val == FU_EBITDO_PKT_CMD_FW_UPDATE_DATA)
30
0
        return "fw-update-data";
31
0
    if (val == FU_EBITDO_PKT_CMD_FW_UPDATE_HEADER)
32
0
        return "fw-update-header";
33
0
    if (val == FU_EBITDO_PKT_CMD_FW_UPDATE_OK)
34
0
        return "fw-update-ok";
35
0
    if (val == FU_EBITDO_PKT_CMD_FW_UPDATE_ERROR)
36
0
        return "fw-update-error";
37
0
    if (val == FU_EBITDO_PKT_CMD_FW_GET_VERSION)
38
0
        return "fw-get-version";
39
0
    if (val == FU_EBITDO_PKT_CMD_FW_SET_VERSION)
40
0
        return "fw-set-version";
41
0
    if (val == FU_EBITDO_PKT_CMD_FW_SET_ENCODE_ID)
42
0
        return "fw-set-encode-id";
43
0
    if (val == FU_EBITDO_PKT_CMD_ACK)
44
0
        return "ack";
45
0
    if (val == FU_EBITDO_PKT_CMD_NAK)
46
0
        return "nak";
47
0
    if (val == FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA)
48
0
        return "update-firmware-data";
49
0
    if (val == FU_EBITDO_PKT_CMD_TRANSFER_ABORT)
50
0
        return "transfer-abort";
51
0
    if (val == FU_EBITDO_PKT_CMD_VERIFICATION_ID)
52
0
        return "verification-id";
53
0
    if (val == FU_EBITDO_PKT_CMD_GET_VERIFICATION_ID)
54
0
        return "get-verification-id";
55
0
    if (val == FU_EBITDO_PKT_CMD_VERIFY_ERROR)
56
0
        return "verify-error";
57
0
    if (val == FU_EBITDO_PKT_CMD_VERIFY_OK)
58
0
        return "verify-ok";
59
0
    if (val == FU_EBITDO_PKT_CMD_TRANSFER_TIMEOUT)
60
0
        return "transfer-timeout";
61
0
    if (val == FU_EBITDO_PKT_CMD_GET_VERSION)
62
0
        return "get-version";
63
0
    if (val == FU_EBITDO_PKT_CMD_GET_VERSION_RESPONSE)
64
0
        return "get-version-response";
65
0
    return NULL;
66
0
}
67
/* getters */
68
/**
69
 * fu_struct_ebitdo_hdr_get_version: (skip):
70
 **/
71
guint32
72
fu_struct_ebitdo_hdr_get_version(const FuStructEbitdoHdr *st)
73
241
{
74
241
    g_return_val_if_fail(st != NULL, 0x0);
75
241
    return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN);
76
241
}
77
/**
78
 * fu_struct_ebitdo_hdr_get_destination_addr: (skip):
79
 **/
80
guint32
81
fu_struct_ebitdo_hdr_get_destination_addr(const FuStructEbitdoHdr *st)
82
241
{
83
241
    g_return_val_if_fail(st != NULL, 0x0);
84
241
    return fu_memread_uint32(st->data + 4, G_LITTLE_ENDIAN);
85
241
}
86
/**
87
 * fu_struct_ebitdo_hdr_get_destination_len: (skip):
88
 **/
89
guint32
90
fu_struct_ebitdo_hdr_get_destination_len(const FuStructEbitdoHdr *st)
91
469
{
92
469
    g_return_val_if_fail(st != NULL, 0x0);
93
469
    return fu_memread_uint32(st->data + 8, G_LITTLE_ENDIAN);
94
469
}
95
96
/* setters */
97
/**
98
 * fu_struct_ebitdo_hdr_set_version: (skip):
99
 **/
100
void
101
fu_struct_ebitdo_hdr_set_version(FuStructEbitdoHdr *st, guint32 value)
102
157
{
103
157
    g_return_if_fail(st != NULL);
104
157
    fu_memwrite_uint32(st->data + 0, value, G_LITTLE_ENDIAN);
105
157
}
106
/**
107
 * fu_struct_ebitdo_hdr_set_destination_addr: (skip):
108
 **/
109
void
110
fu_struct_ebitdo_hdr_set_destination_addr(FuStructEbitdoHdr *st, guint32 value)
111
157
{
112
157
    g_return_if_fail(st != NULL);
113
157
    fu_memwrite_uint32(st->data + 4, value, G_LITTLE_ENDIAN);
114
157
}
115
/**
116
 * fu_struct_ebitdo_hdr_set_destination_len: (skip):
117
 **/
118
void
119
fu_struct_ebitdo_hdr_set_destination_len(FuStructEbitdoHdr *st, guint32 value)
120
157
{
121
157
    g_return_if_fail(st != NULL);
122
157
    fu_memwrite_uint32(st->data + 8, value, G_LITTLE_ENDIAN);
123
157
}
124
/**
125
 * fu_struct_ebitdo_hdr_new: (skip):
126
 **/
127
FuStructEbitdoHdr *
128
fu_struct_ebitdo_hdr_new(void)
129
241
{
130
241
    FuStructEbitdoHdr *st = g_byte_array_sized_new(28);
131
241
    fu_byte_array_set_size(st, 28, 0x0);
132
241
    return st;
133
241
}
134
/**
135
 * fu_struct_ebitdo_hdr_to_string: (skip):
136
 **/
137
static gchar *
138
fu_struct_ebitdo_hdr_to_string(const FuStructEbitdoHdr *st)
139
0
{
140
0
    g_autoptr(GString) str = g_string_new("FuStructEbitdoHdr:\n");
141
0
    g_return_val_if_fail(st != NULL, NULL);
142
0
    g_string_append_printf(str, "  version: 0x%x\n",
143
0
                           (guint) fu_struct_ebitdo_hdr_get_version(st));
144
0
    g_string_append_printf(str, "  destination_addr: 0x%x\n",
145
0
                           (guint) fu_struct_ebitdo_hdr_get_destination_addr(st));
146
0
    g_string_append_printf(str, "  destination_len: 0x%x\n",
147
0
                           (guint) fu_struct_ebitdo_hdr_get_destination_len(st));
148
0
    if (str->len > 0)
149
0
        g_string_set_size(str, str->len - 1);
150
0
    return g_string_free(g_steal_pointer(&str), FALSE);
151
0
}
152
static gboolean
153
fu_struct_ebitdo_hdr_validate_internal(FuStructEbitdoHdr *st, GError **error)
154
355
{
155
355
    g_return_val_if_fail(st != NULL, FALSE);
156
355
    return TRUE;
157
355
}
158
static gboolean
159
fu_struct_ebitdo_hdr_parse_internal(FuStructEbitdoHdr *st, GError **error)
160
355
{
161
355
    if (!fu_struct_ebitdo_hdr_validate_internal(st, error))
162
0
        return FALSE;
163
355
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
164
0
        g_autofree gchar *str = fu_struct_ebitdo_hdr_to_string(st);
165
0
        g_debug("%s", str);
166
0
    }
167
355
    return TRUE;
168
355
}
169
/**
170
 * fu_struct_ebitdo_hdr_parse_stream: (skip):
171
 **/
172
FuStructEbitdoHdr *
173
fu_struct_ebitdo_hdr_parse_stream(GInputStream *stream, gsize offset, GError **error)
174
384
{
175
384
    g_autoptr(GByteArray) st = NULL;
176
384
    st = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error);
177
384
    if (st == NULL) {
178
0
        g_prefix_error(error, "FuStructEbitdoHdr failed read of 0x%x: ", (guint) 28);
179
0
        return NULL;
180
0
    }
181
384
    if (st->len != 28) {
182
29
        g_set_error(error,
183
29
                    FWUPD_ERROR,
184
29
                    FWUPD_ERROR_INVALID_DATA,
185
29
                    "FuStructEbitdoHdr requested 0x%x and got 0x%x",
186
29
                    (guint) 28,
187
29
                    (guint) st->len);
188
29
        return NULL;
189
29
    }
190
355
    if (!fu_struct_ebitdo_hdr_parse_internal(st, error))
191
0
        return NULL;
192
355
    return g_steal_pointer(&st);
193
355
}
194
/* getters */
195
/**
196
 * fu_struct_ebitdo_pkt_get_pkt_len: (skip):
197
 **/
198
guint8
199
fu_struct_ebitdo_pkt_get_pkt_len(const FuStructEbitdoPkt *st)
200
0
{
201
0
    g_return_val_if_fail(st != NULL, 0x0);
202
0
    return st->data[0];
203
0
}
204
/**
205
 * fu_struct_ebitdo_pkt_get_type: (skip):
206
 **/
207
FuEbitdoPktType
208
fu_struct_ebitdo_pkt_get_type(const FuStructEbitdoPkt *st)
209
0
{
210
0
    g_return_val_if_fail(st != NULL, 0x0);
211
0
    return st->data[1];
212
0
}
213
/**
214
 * fu_struct_ebitdo_pkt_get_subtype: (skip):
215
 **/
216
guint8
217
fu_struct_ebitdo_pkt_get_subtype(const FuStructEbitdoPkt *st)
218
0
{
219
0
    g_return_val_if_fail(st != NULL, 0x0);
220
0
    return st->data[2];
221
0
}
222
/**
223
 * fu_struct_ebitdo_pkt_get_cmd_len: (skip):
224
 **/
225
guint16
226
fu_struct_ebitdo_pkt_get_cmd_len(const FuStructEbitdoPkt *st)
227
0
{
228
0
    g_return_val_if_fail(st != NULL, 0x0);
229
0
    return fu_memread_uint16(st->data + 3, G_LITTLE_ENDIAN);
230
0
}
231
/**
232
 * fu_struct_ebitdo_pkt_get_cmd: (skip):
233
 **/
234
FuEbitdoPktCmd
235
fu_struct_ebitdo_pkt_get_cmd(const FuStructEbitdoPkt *st)
236
0
{
237
0
    g_return_val_if_fail(st != NULL, 0x0);
238
0
    return st->data[5];
239
0
}
240
/**
241
 * fu_struct_ebitdo_pkt_get_payload_len: (skip):
242
 **/
243
guint16
244
fu_struct_ebitdo_pkt_get_payload_len(const FuStructEbitdoPkt *st)
245
0
{
246
0
    g_return_val_if_fail(st != NULL, 0x0);
247
0
    return fu_memread_uint16(st->data + 6, G_LITTLE_ENDIAN);
248
0
}
249
250
/* setters */
251
/**
252
 * fu_struct_ebitdo_pkt_set_pkt_len: (skip):
253
 **/
254
void
255
fu_struct_ebitdo_pkt_set_pkt_len(FuStructEbitdoPkt *st, guint8 value)
256
0
{
257
0
    g_return_if_fail(st != NULL);
258
0
    st->data[0] = value;
259
0
}
260
/**
261
 * fu_struct_ebitdo_pkt_set_type: (skip):
262
 **/
263
void
264
fu_struct_ebitdo_pkt_set_type(FuStructEbitdoPkt *st, FuEbitdoPktType value)
265
0
{
266
0
    g_return_if_fail(st != NULL);
267
0
    st->data[1] = value;
268
0
}
269
/**
270
 * fu_struct_ebitdo_pkt_set_subtype: (skip):
271
 **/
272
void
273
fu_struct_ebitdo_pkt_set_subtype(FuStructEbitdoPkt *st, guint8 value)
274
0
{
275
0
    g_return_if_fail(st != NULL);
276
0
    st->data[2] = value;
277
0
}
278
/**
279
 * fu_struct_ebitdo_pkt_set_cmd_len: (skip):
280
 **/
281
void
282
fu_struct_ebitdo_pkt_set_cmd_len(FuStructEbitdoPkt *st, guint16 value)
283
0
{
284
0
    g_return_if_fail(st != NULL);
285
0
    fu_memwrite_uint16(st->data + 3, value, G_LITTLE_ENDIAN);
286
0
}
287
/**
288
 * fu_struct_ebitdo_pkt_set_cmd: (skip):
289
 **/
290
void
291
fu_struct_ebitdo_pkt_set_cmd(FuStructEbitdoPkt *st, FuEbitdoPktCmd value)
292
0
{
293
0
    g_return_if_fail(st != NULL);
294
0
    st->data[5] = value;
295
0
}
296
/**
297
 * fu_struct_ebitdo_pkt_set_payload_len: (skip):
298
 **/
299
void
300
fu_struct_ebitdo_pkt_set_payload_len(FuStructEbitdoPkt *st, guint16 value)
301
0
{
302
0
    g_return_if_fail(st != NULL);
303
0
    fu_memwrite_uint16(st->data + 6, value, G_LITTLE_ENDIAN);
304
0
}
305
/**
306
 * fu_struct_ebitdo_pkt_new: (skip):
307
 **/
308
FuStructEbitdoPkt *
309
fu_struct_ebitdo_pkt_new(void)
310
0
{
311
0
    FuStructEbitdoPkt *st = g_byte_array_sized_new(8);
312
0
    fu_byte_array_set_size(st, 8, 0x0);
313
0
    return st;
314
0
}
315
/**
316
 * fu_struct_ebitdo_pkt_to_string: (skip):
317
 **/
318
static gchar *
319
fu_struct_ebitdo_pkt_to_string(const FuStructEbitdoPkt *st)
320
0
{
321
0
    g_autoptr(GString) str = g_string_new("FuStructEbitdoPkt:\n");
322
0
    g_return_val_if_fail(st != NULL, NULL);
323
0
    g_string_append_printf(str, "  pkt_len: 0x%x\n",
324
0
                           (guint) fu_struct_ebitdo_pkt_get_pkt_len(st));
325
0
    {
326
0
        const gchar *tmp = fu_ebitdo_pkt_type_to_string(fu_struct_ebitdo_pkt_get_type(st));
327
0
        if (tmp != NULL) {
328
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_ebitdo_pkt_get_type(st), tmp);
329
0
        } else {
330
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_ebitdo_pkt_get_type(st));
331
0
        }
332
0
    }
333
0
    g_string_append_printf(str, "  subtype: 0x%x\n",
334
0
                           (guint) fu_struct_ebitdo_pkt_get_subtype(st));
335
0
    g_string_append_printf(str, "  cmd_len: 0x%x\n",
336
0
                           (guint) fu_struct_ebitdo_pkt_get_cmd_len(st));
337
0
    {
338
0
        const gchar *tmp = fu_ebitdo_pkt_cmd_to_string(fu_struct_ebitdo_pkt_get_cmd(st));
339
0
        if (tmp != NULL) {
340
0
            g_string_append_printf(str, "  cmd: 0x%x [%s]\n", (guint) fu_struct_ebitdo_pkt_get_cmd(st), tmp);
341
0
        } else {
342
0
            g_string_append_printf(str, "  cmd: 0x%x\n", (guint) fu_struct_ebitdo_pkt_get_cmd(st));
343
0
        }
344
0
    }
345
0
    g_string_append_printf(str, "  payload_len: 0x%x\n",
346
0
                           (guint) fu_struct_ebitdo_pkt_get_payload_len(st));
347
0
    if (str->len > 0)
348
0
        g_string_set_size(str, str->len - 1);
349
0
    return g_string_free(g_steal_pointer(&str), FALSE);
350
0
}
351
static gboolean
352
fu_struct_ebitdo_pkt_validate_internal(FuStructEbitdoPkt *st, GError **error)
353
0
{
354
0
    g_return_val_if_fail(st != NULL, FALSE);
355
0
    return TRUE;
356
0
}
357
static gboolean
358
fu_struct_ebitdo_pkt_parse_internal(FuStructEbitdoPkt *st, GError **error)
359
0
{
360
0
    if (!fu_struct_ebitdo_pkt_validate_internal(st, error))
361
0
        return FALSE;
362
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
363
0
        g_autofree gchar *str = fu_struct_ebitdo_pkt_to_string(st);
364
0
        g_debug("%s", str);
365
0
    }
366
0
    return TRUE;
367
0
}
368
369
/**
370
 * fu_struct_ebitdo_pkt_parse: (skip):
371
 **/
372
FuStructEbitdoPkt *
373
fu_struct_ebitdo_pkt_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
374
0
{
375
0
    g_autoptr(GByteArray) st = g_byte_array_new();
376
0
    g_return_val_if_fail(buf != NULL, NULL);
377
0
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
378
0
    if (!fu_memchk_read(bufsz, offset, 8, error)) {
379
0
        g_prefix_error(error, "invalid struct FuStructEbitdoPkt: ");
380
0
        return NULL;
381
0
    }
382
0
    g_byte_array_append(st, buf + offset, 8);
383
0
    if (!fu_struct_ebitdo_pkt_parse_internal(st, error))
384
0
        return NULL;
385
0
    return g_steal_pointer(&st);
386
0
}