Coverage Report

Created: 2026-02-26 06:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/fu-ebitdo-struct.c
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-ebitdo-struct.h"
12
#include "fu-byte-array.h"
13
#include "fu-bytes.h"
14
#include "fu-mem-private.h"
15
#include "fu-string.h"
16
17
#ifdef G_LOG_DOMAIN
18
  #undef G_LOG_DOMAIN
19
#endif
20
0
#define G_LOG_DOMAIN "FuStruct"
21
22
/**
23
 * fu_ebitdo_pkt_type_to_string:
24
 * @val: value, e.g. %FU_EBITDO_PKT_TYPE_USER_DATA
25
 *
26
 * Converts an enumerated value to a string.
27
 *
28
 * Returns: identifier string
29
 **/
30
static const gchar *
31
fu_ebitdo_pkt_type_to_string(FuEbitdoPktType val)
32
0
{
33
0
    if (val == FU_EBITDO_PKT_TYPE_USER_CMD)
34
0
        return "user-cmd";
35
0
    if (val == FU_EBITDO_PKT_TYPE_USER_DATA)
36
0
        return "user-data";
37
0
    if (val == FU_EBITDO_PKT_TYPE_MID_CMD)
38
0
        return "mid-cmd";
39
0
    return NULL;
40
0
}
41
42
/**
43
 * fu_ebitdo_pkt_cmd_to_string:
44
 * @val: value, e.g. %FU_EBITDO_PKT_CMD_FW_UPDATE_HEADER
45
 *
46
 * Converts an enumerated value to a string.
47
 *
48
 * Returns: identifier string
49
 **/
50
const gchar *
51
fu_ebitdo_pkt_cmd_to_string(FuEbitdoPktCmd val)
52
0
{
53
0
    if (val == FU_EBITDO_PKT_CMD_FW_UPDATE_DATA)
54
0
        return "fw-update-data";
55
0
    if (val == FU_EBITDO_PKT_CMD_FW_UPDATE_HEADER)
56
0
        return "fw-update-header";
57
0
    if (val == FU_EBITDO_PKT_CMD_FW_UPDATE_OK)
58
0
        return "fw-update-ok";
59
0
    if (val == FU_EBITDO_PKT_CMD_FW_UPDATE_ERROR)
60
0
        return "fw-update-error";
61
0
    if (val == FU_EBITDO_PKT_CMD_FW_GET_VERSION)
62
0
        return "fw-get-version";
63
0
    if (val == FU_EBITDO_PKT_CMD_FW_SET_VERSION)
64
0
        return "fw-set-version";
65
0
    if (val == FU_EBITDO_PKT_CMD_FW_SET_ENCODE_ID)
66
0
        return "fw-set-encode-id";
67
0
    if (val == FU_EBITDO_PKT_CMD_ACK)
68
0
        return "ack";
69
0
    if (val == FU_EBITDO_PKT_CMD_NAK)
70
0
        return "nak";
71
0
    if (val == FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA)
72
0
        return "update-firmware-data";
73
0
    if (val == FU_EBITDO_PKT_CMD_TRANSFER_ABORT)
74
0
        return "transfer-abort";
75
0
    if (val == FU_EBITDO_PKT_CMD_VERIFICATION_ID)
76
0
        return "verification-id";
77
0
    if (val == FU_EBITDO_PKT_CMD_GET_VERIFICATION_ID)
78
0
        return "get-verification-id";
79
0
    if (val == FU_EBITDO_PKT_CMD_VERIFY_ERROR)
80
0
        return "verify-error";
81
0
    if (val == FU_EBITDO_PKT_CMD_VERIFY_OK)
82
0
        return "verify-ok";
83
0
    if (val == FU_EBITDO_PKT_CMD_TRANSFER_TIMEOUT)
84
0
        return "transfer-timeout";
85
0
    if (val == FU_EBITDO_PKT_CMD_GET_VERSION)
86
0
        return "get-version";
87
0
    if (val == FU_EBITDO_PKT_CMD_GET_VERSION_RESPONSE)
88
0
        return "get-version-response";
89
0
    return NULL;
90
0
}
91
/**
92
 * fu_struct_ebitdo_hdr_ref: (skip):
93
 **/
94
FuStructEbitdoHdr *
95
fu_struct_ebitdo_hdr_ref(FuStructEbitdoHdr *st)
96
0
{
97
0
    g_return_val_if_fail(st != NULL, NULL);
98
0
    st->refcount++;
99
0
    return st;
100
0
}
101
/**
102
 * fu_struct_ebitdo_hdr_unref: (skip):
103
 **/
104
void
105
fu_struct_ebitdo_hdr_unref(FuStructEbitdoHdr *st)
106
469
{
107
469
    g_return_if_fail(st != NULL);
108
469
    if (st->refcount == 0) {
109
0
        g_critical("FuStructEbitdoHdr refcount already zero");
110
0
        return;
111
0
    }
112
469
    if (--st->refcount > 0)
113
0
        return;
114
469
    if (st->buf != NULL)
115
304
        g_byte_array_unref(st->buf);
116
469
    g_free(st);
117
469
}
118
/**
119
 * fu_struct_ebitdo_hdr_new_internal: (skip):
120
 **/
121
static FuStructEbitdoHdr *
122
fu_struct_ebitdo_hdr_new_internal(void)
123
469
{
124
469
    FuStructEbitdoHdr *st = g_new0(FuStructEbitdoHdr, 1);
125
469
    st->refcount = 1;
126
469
    return st;
127
469
}
128
129
/* getters */
130
/**
131
 * fu_struct_ebitdo_hdr_get_version: (skip):
132
 **/
133
guint32
134
fu_struct_ebitdo_hdr_get_version(const FuStructEbitdoHdr *st)
135
279
{
136
279
    g_return_val_if_fail(st != NULL, 0x0);
137
279
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
138
279
}
139
/**
140
 * fu_struct_ebitdo_hdr_get_destination_addr: (skip):
141
 **/
142
guint32
143
fu_struct_ebitdo_hdr_get_destination_addr(const FuStructEbitdoHdr *st)
144
170
{
145
170
    g_return_val_if_fail(st != NULL, 0x0);
146
170
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
147
170
}
148
/**
149
 * fu_struct_ebitdo_hdr_get_destination_len: (skip):
150
 **/
151
guint32
152
fu_struct_ebitdo_hdr_get_destination_len(const FuStructEbitdoHdr *st)
153
449
{
154
449
    g_return_val_if_fail(st != NULL, 0x0);
155
449
    return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN);
156
449
}
157
158
/* setters */
159
/**
160
 * fu_struct_ebitdo_hdr_set_version: (skip):
161
 **/
162
void
163
fu_struct_ebitdo_hdr_set_version(FuStructEbitdoHdr *st, guint32 value)
164
165
{
165
165
    g_return_if_fail(st != NULL);
166
165
    fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN);
167
165
}
168
/**
169
 * fu_struct_ebitdo_hdr_set_destination_addr: (skip):
170
 **/
171
void
172
fu_struct_ebitdo_hdr_set_destination_addr(FuStructEbitdoHdr *st, guint32 value)
173
165
{
174
165
    g_return_if_fail(st != NULL);
175
165
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
176
165
}
177
/**
178
 * fu_struct_ebitdo_hdr_set_destination_len: (skip):
179
 **/
180
void
181
fu_struct_ebitdo_hdr_set_destination_len(FuStructEbitdoHdr *st, guint32 value)
182
165
{
183
165
    g_return_if_fail(st != NULL);
184
165
    fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN);
185
165
}
186
/**
187
 * fu_struct_ebitdo_hdr_new: (skip):
188
 **/
189
FuStructEbitdoHdr *
190
fu_struct_ebitdo_hdr_new(void)
191
170
{
192
170
    FuStructEbitdoHdr *st = fu_struct_ebitdo_hdr_new_internal();
193
170
    st->buf = g_byte_array_sized_new(28);
194
170
    fu_byte_array_set_size(st->buf, 28, 0x0);
195
170
    return st;
196
170
}
197
/**
198
 * fu_struct_ebitdo_hdr_to_string: (skip):
199
 **/
200
static gchar *
201
fu_struct_ebitdo_hdr_to_string(const FuStructEbitdoHdr *st)
202
0
{
203
0
    g_autoptr(GString) str = g_string_new("FuStructEbitdoHdr:\n");
204
0
    g_return_val_if_fail(st != NULL, NULL);
205
0
    g_string_append_printf(str, "  version: 0x%x\n",
206
0
                           (guint) fu_struct_ebitdo_hdr_get_version(st));
207
0
    g_string_append_printf(str, "  destination_addr: 0x%x\n",
208
0
                           (guint) fu_struct_ebitdo_hdr_get_destination_addr(st));
209
0
    g_string_append_printf(str, "  destination_len: 0x%x\n",
210
0
                           (guint) fu_struct_ebitdo_hdr_get_destination_len(st));
211
0
    if (str->len > 0)
212
0
        g_string_set_size(str, str->len - 1);
213
0
    return g_string_free(g_steal_pointer(&str), FALSE);
214
0
}
215
static gboolean
216
fu_struct_ebitdo_hdr_validate_internal(FuStructEbitdoHdr *st, GError **error)
217
279
{
218
279
    g_return_val_if_fail(st != NULL, FALSE);
219
279
    return TRUE;
220
279
}
221
static gboolean
222
fu_struct_ebitdo_hdr_parse_internal(FuStructEbitdoHdr *st, GError **error)
223
279
{
224
279
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
225
0
        g_autofree gchar *str = fu_struct_ebitdo_hdr_to_string(st);
226
0
        g_debug("%s", str);
227
0
    }
228
279
    if (!fu_struct_ebitdo_hdr_validate_internal(st, error))
229
0
        return FALSE;
230
279
    return TRUE;
231
279
}
232
/**
233
 * fu_struct_ebitdo_hdr_parse_stream: (skip):
234
 **/
235
FuStructEbitdoHdr *
236
fu_struct_ebitdo_hdr_parse_stream(GInputStream *stream, gsize offset, GError **error)
237
299
{
238
299
    g_autoptr(FuStructEbitdoHdr) st = fu_struct_ebitdo_hdr_new_internal();
239
299
    st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error);
240
299
    if (st->buf == NULL) {
241
0
        g_prefix_error(error, "FuStructEbitdoHdr failed read of 0x%x: ", (guint) 28);
242
0
        return NULL;
243
0
    }
244
299
    if (st->buf->len != 28) {
245
20
        g_set_error(error,
246
20
                    FWUPD_ERROR,
247
20
                    FWUPD_ERROR_INVALID_DATA,
248
20
                    "FuStructEbitdoHdr requested 0x%x and got 0x%x",
249
20
                    (guint) 28,
250
20
                    (guint) st->buf->len);
251
20
        return NULL;
252
20
    }
253
279
    if (!fu_struct_ebitdo_hdr_parse_internal(st, error))
254
0
        return NULL;
255
279
    return g_steal_pointer(&st);
256
279
}
257
/**
258
 * fu_struct_ebitdo_pkt_ref: (skip):
259
 **/
260
FuStructEbitdoPkt *
261
fu_struct_ebitdo_pkt_ref(FuStructEbitdoPkt *st)
262
0
{
263
0
    g_return_val_if_fail(st != NULL, NULL);
264
0
    st->refcount++;
265
0
    return st;
266
0
}
267
/**
268
 * fu_struct_ebitdo_pkt_unref: (skip):
269
 **/
270
void
271
fu_struct_ebitdo_pkt_unref(FuStructEbitdoPkt *st)
272
0
{
273
0
    g_return_if_fail(st != NULL);
274
0
    if (st->refcount == 0) {
275
0
        g_critical("FuStructEbitdoPkt refcount already zero");
276
0
        return;
277
0
    }
278
0
    if (--st->refcount > 0)
279
0
        return;
280
0
    if (st->buf != NULL)
281
0
        g_byte_array_unref(st->buf);
282
0
    g_free(st);
283
0
}
284
/**
285
 * fu_struct_ebitdo_pkt_new_internal: (skip):
286
 **/
287
static FuStructEbitdoPkt *
288
fu_struct_ebitdo_pkt_new_internal(void)
289
0
{
290
0
    FuStructEbitdoPkt *st = g_new0(FuStructEbitdoPkt, 1);
291
0
    st->refcount = 1;
292
0
    return st;
293
0
}
294
295
/* getters */
296
/**
297
 * fu_struct_ebitdo_pkt_get_pkt_len: (skip):
298
 **/
299
guint8
300
fu_struct_ebitdo_pkt_get_pkt_len(const FuStructEbitdoPkt *st)
301
0
{
302
0
    g_return_val_if_fail(st != NULL, 0x0);
303
0
    return st->buf->data[0];
304
0
}
305
/**
306
 * fu_struct_ebitdo_pkt_get_type: (skip):
307
 **/
308
FuEbitdoPktType
309
fu_struct_ebitdo_pkt_get_type(const FuStructEbitdoPkt *st)
310
0
{
311
0
    g_return_val_if_fail(st != NULL, 0x0);
312
0
    return st->buf->data[1];
313
0
}
314
/**
315
 * fu_struct_ebitdo_pkt_get_subtype: (skip):
316
 **/
317
guint8
318
fu_struct_ebitdo_pkt_get_subtype(const FuStructEbitdoPkt *st)
319
0
{
320
0
    g_return_val_if_fail(st != NULL, 0x0);
321
0
    return st->buf->data[2];
322
0
}
323
/**
324
 * fu_struct_ebitdo_pkt_get_cmd_len: (skip):
325
 **/
326
guint16
327
fu_struct_ebitdo_pkt_get_cmd_len(const FuStructEbitdoPkt *st)
328
0
{
329
0
    g_return_val_if_fail(st != NULL, 0x0);
330
0
    return fu_memread_uint16(st->buf->data + 3, G_LITTLE_ENDIAN);
331
0
}
332
/**
333
 * fu_struct_ebitdo_pkt_get_cmd: (skip):
334
 **/
335
FuEbitdoPktCmd
336
fu_struct_ebitdo_pkt_get_cmd(const FuStructEbitdoPkt *st)
337
0
{
338
0
    g_return_val_if_fail(st != NULL, 0x0);
339
0
    return st->buf->data[5];
340
0
}
341
/**
342
 * fu_struct_ebitdo_pkt_get_payload_len: (skip):
343
 **/
344
guint16
345
fu_struct_ebitdo_pkt_get_payload_len(const FuStructEbitdoPkt *st)
346
0
{
347
0
    g_return_val_if_fail(st != NULL, 0x0);
348
0
    return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN);
349
0
}
350
351
/* setters */
352
/**
353
 * fu_struct_ebitdo_pkt_set_pkt_len: (skip):
354
 **/
355
void
356
fu_struct_ebitdo_pkt_set_pkt_len(FuStructEbitdoPkt *st, guint8 value)
357
0
{
358
0
    g_return_if_fail(st != NULL);
359
0
    st->buf->data[0] = value;
360
0
}
361
/**
362
 * fu_struct_ebitdo_pkt_set_type: (skip):
363
 **/
364
void
365
fu_struct_ebitdo_pkt_set_type(FuStructEbitdoPkt *st, FuEbitdoPktType value)
366
0
{
367
0
    g_return_if_fail(st != NULL);
368
0
    st->buf->data[1] = value;
369
0
}
370
/**
371
 * fu_struct_ebitdo_pkt_set_subtype: (skip):
372
 **/
373
void
374
fu_struct_ebitdo_pkt_set_subtype(FuStructEbitdoPkt *st, guint8 value)
375
0
{
376
0
    g_return_if_fail(st != NULL);
377
0
    st->buf->data[2] = value;
378
0
}
379
/**
380
 * fu_struct_ebitdo_pkt_set_cmd_len: (skip):
381
 **/
382
void
383
fu_struct_ebitdo_pkt_set_cmd_len(FuStructEbitdoPkt *st, guint16 value)
384
0
{
385
0
    g_return_if_fail(st != NULL);
386
0
    fu_memwrite_uint16(st->buf->data + 3, value, G_LITTLE_ENDIAN);
387
0
}
388
/**
389
 * fu_struct_ebitdo_pkt_set_cmd: (skip):
390
 **/
391
void
392
fu_struct_ebitdo_pkt_set_cmd(FuStructEbitdoPkt *st, FuEbitdoPktCmd value)
393
0
{
394
0
    g_return_if_fail(st != NULL);
395
0
    st->buf->data[5] = value;
396
0
}
397
/**
398
 * fu_struct_ebitdo_pkt_set_payload_len: (skip):
399
 **/
400
void
401
fu_struct_ebitdo_pkt_set_payload_len(FuStructEbitdoPkt *st, guint16 value)
402
0
{
403
0
    g_return_if_fail(st != NULL);
404
0
    fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN);
405
0
}
406
/**
407
 * fu_struct_ebitdo_pkt_new: (skip):
408
 **/
409
FuStructEbitdoPkt *
410
fu_struct_ebitdo_pkt_new(void)
411
0
{
412
0
    FuStructEbitdoPkt *st = fu_struct_ebitdo_pkt_new_internal();
413
0
    st->buf = g_byte_array_sized_new(8);
414
0
    fu_byte_array_set_size(st->buf, 8, 0x0);
415
0
    return st;
416
0
}
417
/**
418
 * fu_struct_ebitdo_pkt_to_string: (skip):
419
 **/
420
static gchar *
421
fu_struct_ebitdo_pkt_to_string(const FuStructEbitdoPkt *st)
422
0
{
423
0
    g_autoptr(GString) str = g_string_new("FuStructEbitdoPkt:\n");
424
0
    g_return_val_if_fail(st != NULL, NULL);
425
0
    g_string_append_printf(str, "  pkt_len: 0x%x\n",
426
0
                           (guint) fu_struct_ebitdo_pkt_get_pkt_len(st));
427
0
    {
428
0
        const gchar *tmp = fu_ebitdo_pkt_type_to_string(fu_struct_ebitdo_pkt_get_type(st));
429
0
        if (tmp != NULL) {
430
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_ebitdo_pkt_get_type(st), tmp);
431
0
        } else {
432
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_ebitdo_pkt_get_type(st));
433
0
        }
434
0
    }
435
0
    g_string_append_printf(str, "  subtype: 0x%x\n",
436
0
                           (guint) fu_struct_ebitdo_pkt_get_subtype(st));
437
0
    g_string_append_printf(str, "  cmd_len: 0x%x\n",
438
0
                           (guint) fu_struct_ebitdo_pkt_get_cmd_len(st));
439
0
    {
440
0
        const gchar *tmp = fu_ebitdo_pkt_cmd_to_string(fu_struct_ebitdo_pkt_get_cmd(st));
441
0
        if (tmp != NULL) {
442
0
            g_string_append_printf(str, "  cmd: 0x%x [%s]\n", (guint) fu_struct_ebitdo_pkt_get_cmd(st), tmp);
443
0
        } else {
444
0
            g_string_append_printf(str, "  cmd: 0x%x\n", (guint) fu_struct_ebitdo_pkt_get_cmd(st));
445
0
        }
446
0
    }
447
0
    g_string_append_printf(str, "  payload_len: 0x%x\n",
448
0
                           (guint) fu_struct_ebitdo_pkt_get_payload_len(st));
449
0
    if (str->len > 0)
450
0
        g_string_set_size(str, str->len - 1);
451
0
    return g_string_free(g_steal_pointer(&str), FALSE);
452
0
}
453
static gboolean
454
fu_struct_ebitdo_pkt_validate_internal(FuStructEbitdoPkt *st, GError **error)
455
0
{
456
0
    g_return_val_if_fail(st != NULL, FALSE);
457
0
    return TRUE;
458
0
}
459
static gboolean
460
fu_struct_ebitdo_pkt_parse_internal(FuStructEbitdoPkt *st, GError **error)
461
0
{
462
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
463
0
        g_autofree gchar *str = fu_struct_ebitdo_pkt_to_string(st);
464
0
        g_debug("%s", str);
465
0
    }
466
0
    if (!fu_struct_ebitdo_pkt_validate_internal(st, error))
467
0
        return FALSE;
468
0
    return TRUE;
469
0
}
470
471
/**
472
 * fu_struct_ebitdo_pkt_parse: (skip):
473
 **/
474
FuStructEbitdoPkt *
475
fu_struct_ebitdo_pkt_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
476
0
{
477
0
    g_autoptr(FuStructEbitdoPkt) st = fu_struct_ebitdo_pkt_new_internal();
478
0
    g_return_val_if_fail(buf != NULL, NULL);
479
0
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
480
0
    if (!fu_memchk_read(bufsz, offset, 8, error)) {
481
0
        g_prefix_error_literal(error, "invalid struct FuStructEbitdoPkt: ");
482
0
        return NULL;
483
0
    }
484
0
    st->buf = g_byte_array_new();
485
0
    g_byte_array_append(st->buf, buf + offset, 8);
486
0
    if (!fu_struct_ebitdo_pkt_parse_internal(st, error))
487
0
        return NULL;
488
0
    return g_steal_pointer(&st);
489
0
}