Coverage Report

Created: 2026-01-09 07:21

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