Coverage Report

Created: 2026-06-15 06:54

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
468
{
107
468
    g_return_if_fail(st != NULL);
108
468
    if (st->refcount == 0) {
109
0
        g_critical("FuStructEbitdoHdr refcount already zero");
110
0
        return;
111
0
    }
112
468
    if (--st->refcount > 0)
113
0
        return;
114
468
    if (st->buf != NULL)
115
297
        g_byte_array_unref(st->buf);
116
468
    g_free(st);
117
468
}
118
/**
119
 * fu_struct_ebitdo_hdr_new_internal: (skip):
120
 **/
121
static FuStructEbitdoHdr *
122
fu_struct_ebitdo_hdr_new_internal(void)
123
468
{
124
468
    FuStructEbitdoHdr *st = g_new0(FuStructEbitdoHdr, 1);
125
468
    st->refcount = 1;
126
468
    return st;
127
468
}
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
270
{
136
270
    g_return_val_if_fail(st != NULL, 0x0);
137
270
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
138
270
}
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
181
{
145
181
    g_return_val_if_fail(st != NULL, 0x0);
146
181
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
147
181
}
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
451
{
154
451
    g_return_val_if_fail(st != NULL, 0x0);
155
451
    return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN);
156
451
}
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
171
{
165
171
    g_return_if_fail(st != NULL);
166
171
    fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN);
167
171
}
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
171
{
174
171
    g_return_if_fail(st != NULL);
175
171
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
176
171
}
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
171
{
183
171
    g_return_if_fail(st != NULL);
184
171
    fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN);
185
171
}
186
/**
187
 * fu_struct_ebitdo_hdr_new: (skip):
188
 **/
189
FuStructEbitdoHdr *
190
fu_struct_ebitdo_hdr_new(void)
191
181
{
192
181
    FuStructEbitdoHdr *st = fu_struct_ebitdo_hdr_new_internal();
193
181
    st->buf = g_byte_array_sized_new(28);
194
181
    fu_byte_array_set_size(st->buf, 28, 0x0);
195
181
    return st;
196
181
}
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_parse_internal(FuStructEbitdoHdr *st, GError **error)
217
270
{
218
270
    if (g_log_get_debug_enabled()) {
219
0
        g_autofree gchar *str = fu_struct_ebitdo_hdr_to_string(st);
220
0
        g_debug("%s", str);
221
0
    }
222
270
    return TRUE;
223
270
}
224
/**
225
 * fu_struct_ebitdo_hdr_parse_stream: (skip):
226
 **/
227
FuStructEbitdoHdr *
228
fu_struct_ebitdo_hdr_parse_stream(GInputStream *stream, gsize offset, GError **error)
229
287
{
230
287
    g_autoptr(FuStructEbitdoHdr) st = fu_struct_ebitdo_hdr_new_internal();
231
287
    st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error);
232
287
    if (st->buf == NULL) {
233
0
        g_prefix_error(error, "FuStructEbitdoHdr failed read of 0x%x: ", (guint) 28);
234
0
        return NULL;
235
0
    }
236
287
    if (st->buf->len != 28) {
237
17
        g_set_error(error,
238
17
                    FWUPD_ERROR,
239
17
                    FWUPD_ERROR_INVALID_DATA,
240
17
                    "FuStructEbitdoHdr requested 0x%x and got 0x%x",
241
17
                    (guint) 28,
242
17
                    (guint) st->buf->len);
243
17
        return NULL;
244
17
    }
245
270
    if (!fu_struct_ebitdo_hdr_parse_internal(st, error))
246
0
        return NULL;
247
270
    return g_steal_pointer(&st);
248
270
}
249
/**
250
 * fu_struct_ebitdo_pkt_ref: (skip):
251
 **/
252
FuStructEbitdoPkt *
253
fu_struct_ebitdo_pkt_ref(FuStructEbitdoPkt *st)
254
0
{
255
0
    g_return_val_if_fail(st != NULL, NULL);
256
0
    st->refcount++;
257
0
    return st;
258
0
}
259
/**
260
 * fu_struct_ebitdo_pkt_unref: (skip):
261
 **/
262
void
263
fu_struct_ebitdo_pkt_unref(FuStructEbitdoPkt *st)
264
0
{
265
0
    g_return_if_fail(st != NULL);
266
0
    if (st->refcount == 0) {
267
0
        g_critical("FuStructEbitdoPkt refcount already zero");
268
0
        return;
269
0
    }
270
0
    if (--st->refcount > 0)
271
0
        return;
272
0
    if (st->buf != NULL)
273
0
        g_byte_array_unref(st->buf);
274
0
    g_free(st);
275
0
}
276
/**
277
 * fu_struct_ebitdo_pkt_new_internal: (skip):
278
 **/
279
static FuStructEbitdoPkt *
280
fu_struct_ebitdo_pkt_new_internal(void)
281
0
{
282
0
    FuStructEbitdoPkt *st = g_new0(FuStructEbitdoPkt, 1);
283
0
    st->refcount = 1;
284
0
    return st;
285
0
}
286
287
/* getters */
288
/**
289
 * fu_struct_ebitdo_pkt_get_pkt_len: (skip):
290
 **/
291
guint8
292
fu_struct_ebitdo_pkt_get_pkt_len(const FuStructEbitdoPkt *st)
293
0
{
294
0
    g_return_val_if_fail(st != NULL, 0x0);
295
0
    return st->buf->data[0];
296
0
}
297
/**
298
 * fu_struct_ebitdo_pkt_get_type: (skip):
299
 **/
300
FuEbitdoPktType
301
fu_struct_ebitdo_pkt_get_type(const FuStructEbitdoPkt *st)
302
0
{
303
0
    g_return_val_if_fail(st != NULL, 0x0);
304
0
    return st->buf->data[1];
305
0
}
306
/**
307
 * fu_struct_ebitdo_pkt_get_subtype: (skip):
308
 **/
309
guint8
310
fu_struct_ebitdo_pkt_get_subtype(const FuStructEbitdoPkt *st)
311
0
{
312
0
    g_return_val_if_fail(st != NULL, 0x0);
313
0
    return st->buf->data[2];
314
0
}
315
/**
316
 * fu_struct_ebitdo_pkt_get_cmd_len: (skip):
317
 **/
318
guint16
319
fu_struct_ebitdo_pkt_get_cmd_len(const FuStructEbitdoPkt *st)
320
0
{
321
0
    g_return_val_if_fail(st != NULL, 0x0);
322
0
    return fu_memread_uint16(st->buf->data + 3, G_LITTLE_ENDIAN);
323
0
}
324
/**
325
 * fu_struct_ebitdo_pkt_get_cmd: (skip):
326
 **/
327
FuEbitdoPktCmd
328
fu_struct_ebitdo_pkt_get_cmd(const FuStructEbitdoPkt *st)
329
0
{
330
0
    g_return_val_if_fail(st != NULL, 0x0);
331
0
    return st->buf->data[5];
332
0
}
333
/**
334
 * fu_struct_ebitdo_pkt_get_payload_len: (skip):
335
 **/
336
guint16
337
fu_struct_ebitdo_pkt_get_payload_len(const FuStructEbitdoPkt *st)
338
0
{
339
0
    g_return_val_if_fail(st != NULL, 0x0);
340
0
    return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN);
341
0
}
342
343
/* setters */
344
/**
345
 * fu_struct_ebitdo_pkt_set_pkt_len: (skip):
346
 **/
347
void
348
fu_struct_ebitdo_pkt_set_pkt_len(FuStructEbitdoPkt *st, guint8 value)
349
0
{
350
0
    g_return_if_fail(st != NULL);
351
0
    st->buf->data[0] = value;
352
0
}
353
/**
354
 * fu_struct_ebitdo_pkt_set_type: (skip):
355
 **/
356
void
357
fu_struct_ebitdo_pkt_set_type(FuStructEbitdoPkt *st, FuEbitdoPktType value)
358
0
{
359
0
    g_return_if_fail(st != NULL);
360
0
    st->buf->data[1] = value;
361
0
}
362
/**
363
 * fu_struct_ebitdo_pkt_set_subtype: (skip):
364
 **/
365
void
366
fu_struct_ebitdo_pkt_set_subtype(FuStructEbitdoPkt *st, guint8 value)
367
0
{
368
0
    g_return_if_fail(st != NULL);
369
0
    st->buf->data[2] = value;
370
0
}
371
/**
372
 * fu_struct_ebitdo_pkt_set_cmd_len: (skip):
373
 **/
374
void
375
fu_struct_ebitdo_pkt_set_cmd_len(FuStructEbitdoPkt *st, guint16 value)
376
0
{
377
0
    g_return_if_fail(st != NULL);
378
0
    fu_memwrite_uint16(st->buf->data + 3, value, G_LITTLE_ENDIAN);
379
0
}
380
/**
381
 * fu_struct_ebitdo_pkt_set_cmd: (skip):
382
 **/
383
void
384
fu_struct_ebitdo_pkt_set_cmd(FuStructEbitdoPkt *st, FuEbitdoPktCmd value)
385
0
{
386
0
    g_return_if_fail(st != NULL);
387
0
    st->buf->data[5] = value;
388
0
}
389
/**
390
 * fu_struct_ebitdo_pkt_set_payload_len: (skip):
391
 **/
392
void
393
fu_struct_ebitdo_pkt_set_payload_len(FuStructEbitdoPkt *st, guint16 value)
394
0
{
395
0
    g_return_if_fail(st != NULL);
396
0
    fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN);
397
0
}
398
/**
399
 * fu_struct_ebitdo_pkt_new: (skip):
400
 **/
401
FuStructEbitdoPkt *
402
fu_struct_ebitdo_pkt_new(void)
403
0
{
404
0
    FuStructEbitdoPkt *st = fu_struct_ebitdo_pkt_new_internal();
405
0
    st->buf = g_byte_array_sized_new(8);
406
0
    fu_byte_array_set_size(st->buf, 8, 0x0);
407
0
    return st;
408
0
}
409
/**
410
 * fu_struct_ebitdo_pkt_to_string: (skip):
411
 **/
412
static gchar *
413
fu_struct_ebitdo_pkt_to_string(const FuStructEbitdoPkt *st)
414
0
{
415
0
    g_autoptr(GString) str = g_string_new("FuStructEbitdoPkt:\n");
416
0
    g_return_val_if_fail(st != NULL, NULL);
417
0
    g_string_append_printf(str, "  pkt_len: 0x%x\n",
418
0
                           (guint) fu_struct_ebitdo_pkt_get_pkt_len(st));
419
0
    {
420
0
        const gchar *tmp = fu_ebitdo_pkt_type_to_string(fu_struct_ebitdo_pkt_get_type(st));
421
0
        if (tmp != NULL) {
422
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_ebitdo_pkt_get_type(st), tmp);
423
0
        } else {
424
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_ebitdo_pkt_get_type(st));
425
0
        }
426
0
    }
427
0
    g_string_append_printf(str, "  subtype: 0x%x\n",
428
0
                           (guint) fu_struct_ebitdo_pkt_get_subtype(st));
429
0
    g_string_append_printf(str, "  cmd_len: 0x%x\n",
430
0
                           (guint) fu_struct_ebitdo_pkt_get_cmd_len(st));
431
0
    {
432
0
        const gchar *tmp = fu_ebitdo_pkt_cmd_to_string(fu_struct_ebitdo_pkt_get_cmd(st));
433
0
        if (tmp != NULL) {
434
0
            g_string_append_printf(str, "  cmd: 0x%x [%s]\n", (guint) fu_struct_ebitdo_pkt_get_cmd(st), tmp);
435
0
        } else {
436
0
            g_string_append_printf(str, "  cmd: 0x%x\n", (guint) fu_struct_ebitdo_pkt_get_cmd(st));
437
0
        }
438
0
    }
439
0
    g_string_append_printf(str, "  payload_len: 0x%x\n",
440
0
                           (guint) fu_struct_ebitdo_pkt_get_payload_len(st));
441
0
    if (str->len > 0)
442
0
        g_string_set_size(str, str->len - 1);
443
0
    return g_string_free(g_steal_pointer(&str), FALSE);
444
0
}
445
static gboolean
446
fu_struct_ebitdo_pkt_parse_internal(FuStructEbitdoPkt *st, GError **error)
447
0
{
448
0
    if (g_log_get_debug_enabled()) {
449
0
        g_autofree gchar *str = fu_struct_ebitdo_pkt_to_string(st);
450
0
        g_debug("%s", str);
451
0
    }
452
0
    return TRUE;
453
0
}
454
455
/**
456
 * fu_struct_ebitdo_pkt_parse: (skip):
457
 **/
458
FuStructEbitdoPkt *
459
fu_struct_ebitdo_pkt_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
460
0
{
461
0
    g_autoptr(FuStructEbitdoPkt) st = fu_struct_ebitdo_pkt_new_internal();
462
0
    g_return_val_if_fail(buf != NULL, NULL);
463
0
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
464
0
    if (!fu_memchk_read(bufsz, offset, 8, error)) {
465
0
        g_prefix_error_literal(error, "invalid struct FuStructEbitdoPkt: ");
466
0
        return NULL;
467
0
    }
468
0
    st->buf = g_byte_array_new();
469
0
    g_byte_array_append(st->buf, buf + offset, 8);
470
0
    if (!fu_struct_ebitdo_pkt_parse_internal(st, error))
471
0
        return NULL;
472
0
    return g_steal_pointer(&st);
473
0
}