Coverage Report

Created: 2025-11-11 06:44

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