Coverage Report

Created: 2025-11-24 06:59

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