aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmi-firmware-update/qfu-qdl-message.c
blob: 9650ddbeaa34581644ea9218ecaedd0aad32f6a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * qmi-firmware-update -- Command line tool to update firmware in QMI devices
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright (C) 2016 Bjørn Mork <bjorn@mork.no>
 * Copyright (C) 2016 Zodiac Inflight Innovations
 * Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es>
 */

#include <string.h>

#include <glib-object.h>
#include <gio/gio.h>

#include "qfu-qdl-message.h"
#include "qfu-utils.h"
#include "qfu-enum-types.h"

/******************************************************************************/
/* QDL generic */

/* Generic message for operations that just require the command id */
typedef struct _QdlMsg QdlMsg;
struct _QdlMsg {
    guint8 cmd;
} __attribute__ ((packed));

G_STATIC_ASSERT (sizeof (QdlMsg) <= QFU_QDL_MESSAGE_MAX_HEADER_SIZE);

static gsize
qdl_message_generic_build (guint8    *buffer,
                           gsize      buffer_len,
                           QfuQdlCmd  cmd)
{
    QdlMsg *req;

    g_assert (buffer_len >= sizeof (QdlMsg));

    /* Create request */
    req = (QdlMsg *) buffer;
    req->cmd = (guint8) cmd;

    g_debug ("[qfu,qdl-message] sent %s:", qfu_qdl_cmd_get_string ((QfuQdlCmd) req->cmd));

	return (sizeof (QdlMsg));
}

/******************************************************************************/
/* QDL Hello */

/* feature bits */
#define QDL_FEATURE_GENERIC_UNFRAMED 0x10
#define QDL_FEATURE_QDL_UNFRAMED     0x20
#define QDL_FEATURE_BAR_MODE         0x40

typedef struct _QdlHelloReq QdlHelloReq;
struct _QdlHelloReq {
    guint8 cmd; /* 0x01 */
    gchar  magic[32];
    guint8 maxver;
    guint8 minver;
    guint8 features;
} __attribute__ ((packed));

G_STATIC_ASSERT (sizeof (QdlHelloReq) <= QFU_QDL_MESSAGE_MAX_HEADER_SIZE);

gsize
qfu_qdl_request_hello_build (guint8 *buffer,
                             gsize   buffer_len,
                             guint8  minver,
                             guint8  maxver)
{
    static const QdlHelloReq common_hello_req = {
        .cmd = QFU_QDL_CMD_HELLO_REQ,
        .magic = { "QCOM high speed protocol hst" },
        .maxver = 0,
        .minver = 0,
        .features = QDL_FEATURE_QDL_UNFRAMED | QDL_FEATURE_GENERIC_UNFRAMED,
    };
    QdlHelloReq *req;

    g_assert (buffer_len >= sizeof (QdlHelloReq));

    /* Create request */
    req = (QdlHelloReq *) buffer;
    memcpy (req, &common_hello_req, sizeof (QdlHelloReq));
    req->minver = minver;
    req->maxver = maxver;

    g_debug ("[qfu,qdl-message] sent %s:", qfu_qdl_cmd_get_string ((QfuQdlCmd) req->cmd));
    g_debug ("[qfu,qdl-message]   magic:           %.*s",   req->maxver <= 5 ? 24 : 32, req->magic);
    g_debug ("[qfu,qdl-message]   maximum version: %u",     req->maxver);
    g_debug ("[qfu,qdl-message]   minimum version: %u",     req->minver);
    g_debug ("[qfu,qdl-message]   features:        0x%02x", req->features);

	return (sizeof (QdlHelloReq));
}

typedef struct _QdlHelloRsp QdlHelloRsp;
struct _QdlHelloRsp {
    guint8  cmd; /* 0x02 */
    gchar   magic[32];
    guint8  maxver;
    guint8  minver;
    guint32 reserved1;
    guint32 reserved2;
    guint8  reserved3;
    guint16 reserved4;
    guint16 reserved5;
    guint8  features;
} __attribute__ ((packed));

G_STATIC_ASSERT (sizeof (QdlHelloRsp) <= QFU_QDL_MESSAGE_MAX_HEADER_SIZE);

gboolean
qfu_qdl_response_hello_parse (const guint8  *buffer,
                              gsize          buffer_len,
                              GError       **error)
{
    QdlHelloRsp *rsp;

	if (buffer_len != sizeof (QdlHelloRsp)) {
        g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                     "message size mismatch: %" G_GSIZE_FORMAT " != %" G_GSIZE_FORMAT,
                     buffer_len, sizeof (QdlHelloRsp));
        return FALSE;
    }

    rsp = (QdlHelloRsp *) buffer;
    g_assert (rsp->cmd == QFU_QDL_CMD_HELLO_RSP);

    g_debug ("[qfu,qdl-message] received %s:", qfu_qdl_cmd_get_string ((QfuQdlCmd) rsp->cmd));
    g_debug ("[qfu,qdl-message]   magic:           %.*s",   rsp->maxver <= 5 ? 24 : 32, rsp->magic);
    g_debug ("[qfu,qdl-message]   maximum version: %u",     rsp->maxver);
    g_debug ("[qfu,qdl-message]   minimum version: %u",     rsp->minver);
    g_debug ("[qfu,qdl-message]   features:        0x%02x", rsp->features);

    /* For now, ignore fields */

    return TRUE;
}

/******************************************************************************/
/* QDL Error */

typedef enum {
    QDL_ERROR_NONE              = 0x00,
    QDL_ERROR_01_RESERVED       = 0x01,
    QDL_ERROR_BAD_ADDR          = 0x02,
    QDL_ERROR_BAD_LEN           = 0x03,
    QDL_ERROR_BAD_PACKET        = 0x04,
    QDL_ERROR_BAD_CMD           = 0x05,
    QDL_ERROR_06                = 0x06,
    QDL_ERROR_OP_FAILED         = 0x07,
    QDL_ERROR_BAD_FLASH_ID      = 0x08,
    QDL_ERROR_BAD_VOLTAGE       = 0x09,
    QDL_ERROR_WRITE_FAILED      = 0x0a,
    QDL_ERROR_11_RESERVED       = 0x0b,
    QDL_ERROR_BAD_SPC           = 0x0c,
    QDL_ERROR_POWERDOWN         = 0x0d,
    QDL_ERROR_UNSUPPORTED       = 0x0e,
    QDL_ERROR_CMD_SEQ           = 0x0f,
    QDL_ERROR_CLOSE             = 0x10,
    QDL_ERROR_BAD_FEATURES      = 0x11,
    QDL_ERROR_SPACE             = 0x12,
    QDL_ERROR_BAD_SECURITY      = 0x13,
    QDL_ERROR_MULTI_UNSUPPORTED = 0x14,
    QDL_ERROR_POWEROFF          = 0x15,
    QDL_ERROR_CMD_UNSUPPORTED   = 0x16,
    QDL_ERROR_BAD_CRC           = 0x17,
    QDL_ERROR_STATE             = 0x18,
    QDL_ERROR_TIMEOUT           = 0x19,
    QDL_ERROR_IMAGE_AUTH        = 0x1a,
    QDL_ERROR_LAST
} QdlError;

static const gchar *qdl_error_str[] = {
    [QDL_ERROR_NONE              ] = "None",
    [QDL_ERROR_01_RESERVED       ] = "Reserved",
    [QDL_ERROR_BAD_ADDR          ] = "Invalid destination address",
    [QDL_ERROR_BAD_LEN           ] = "Invalid length",
    [QDL_ERROR_BAD_PACKET        ] = "Unexpected end of packet",
    [QDL_ERROR_BAD_CMD           ] = "Invalid command",
    [QDL_ERROR_06                ] = "Reserved",
    [QDL_ERROR_OP_FAILED         ] = "Operation failed",
    [QDL_ERROR_BAD_FLASH_ID      ] = "Invalid flash intelligent ID",
    [QDL_ERROR_BAD_VOLTAGE       ] = "Invalid programming voltage",
    [QDL_ERROR_WRITE_FAILED      ] = "Write verify failed",
    [QDL_ERROR_11_RESERVED       ] = "Reserved",
    [QDL_ERROR_BAD_SPC           ] = "Invalid security code",
    [QDL_ERROR_POWERDOWN         ] = "Power-down failed",
    [QDL_ERROR_UNSUPPORTED       ] = "NAND flash programming not supported",
    [QDL_ERROR_CMD_SEQ           ] = "Command out of sequence",
    [QDL_ERROR_CLOSE             ] = "Close failed",
    [QDL_ERROR_BAD_FEATURES      ] = "Invalid feature bits",
    [QDL_ERROR_SPACE             ] = "Out of space",
    [QDL_ERROR_BAD_SECURITY      ] = "Invalid security mode",
    [QDL_ERROR_MULTI_UNSUPPORTED ] = "Multi-image NAND not supported",
    [QDL_ERROR_POWEROFF          ] = "Power-off command not supported",
    [QDL_ERROR_CMD_UNSUPPORTED   ] = "Command not supported",
    [QDL_ERROR_BAD_CRC           ] = "Invalid CRC",
    [QDL_ERROR_STATE             ] = "Command received in invalid state",
    [QDL_ERROR_TIMEOUT           ] = "Receive timeout",
    [QDL_ERROR_IMAGE_AUTH        ] = "Image authentication error",
};

G_STATIC_ASSERT (G_N_ELEMENTS (qdl_error_str) == QDL_ERROR_LAST);

static GIOErrorEnum
qdl_error_to_gio_error_enum (QdlError err)
{
    switch (err) {
    case QDL_ERROR_CMD_UNSUPPORTED:
        return G_IO_ERROR_NOT_SUPPORTED;
    default:
        return G_IO_ERROR_FAILED;
    }
}

static const gchar *
qdl_error_to_string (QdlError err)
{
    return (err < QDL_ERROR_LAST ? qdl_error_str[err] : "Unknown");
}

typedef struct _QdlErrRsp QdlErrRsp;
struct _QdlErrRsp {
    guint8  cmd; /* 0x0d */
    guint32 error;
    guint8  errortxt;
} __attribute__ ((packed));

G_STATIC_ASSERT (sizeof (QdlErrRsp) <= QFU_QDL_MESSAGE_MAX_HEADER_SIZE);

gboolean
qfu_qdl_response_error_parse (const guint8  *buffer,
                              gsize          buffer_len,
                              GError       **error)
{
    QdlErrRsp *rsp;

	if (buffer_len != sizeof (QdlErrRsp)) {
        g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                     "message size mismatch: %" G_GSIZE_FORMAT " != %" G_GSIZE_FORMAT,
                     buffer_len, sizeof (QdlErrRsp));
        return FALSE;
    }

    rsp = (QdlErrRsp *) buffer;
    g_assert (rsp->cmd == QFU_QDL_CMD_ERROR);

    g_debug ("[qfu,qdl-message] received %s", qfu_qdl_cmd_get_string ((QfuQdlCmd) rsp->cmd));
    g_debug ("[qfu,qdl-message]   error:    %" G_GUINT32_FORMAT, GUINT32_FROM_LE (rsp->error));
    g_debug ("[qfu,qdl-message]   errortxt: %u", rsp->errortxt);

    /* Always return an error in this case */
    g_set_error (error, G_IO_ERROR, qdl_error_to_gio_error_enum (GUINT32_FROM_LE (rsp->error)),
                 "%s", qdl_error_to_string ((QdlError) GUINT32_FROM_LE (rsp->error)));
    return FALSE;
}

/******************************************************************************/
/* QDL Ufopen */

typedef struct _QdlUfopenReq QdlUfopenReq;
struct _QdlUfopenReq {
    guint8  cmd; /* 0x25 */
    guint8  type;
    guint32 length;
    guint8  windowsize;
    guint32 chunksize;
    guint16 reserved;
} __attribute__ ((packed));

G_STATIC_ASSERT (sizeof (QdlUfopenReq) <= QFU_QDL_MESSAGE_MAX_HEADER_SIZE);

gssize
qfu_qdl_request_ufopen_build (guint8        *buffer,
                              gsize          buffer_len,
                              QfuImage      *image,
                              GCancellable  *cancellable,
                              GError       **error)
{
    QdlUfopenReq *req;

    g_assert (buffer_len >= sizeof (QdlUfopenReq));

    /* Create request */
    req = (QdlUfopenReq *) buffer;
    memset (req, 0, sizeof (QdlUfopenReq));
	req->cmd        = QFU_QDL_CMD_OPEN_UNFRAMED_REQ;
	req->type       = (guint8) qfu_image_get_image_type (image);
	req->windowsize = 1; /* snooped */
	req->length     = GUINT32_TO_LE (qfu_image_get_header_size (image) + qfu_image_get_data_size (image));
	req->chunksize  = GUINT32_TO_LE (qfu_image_get_data_size (image));

    /* Append header */
    if (qfu_image_read_header (image, buffer + sizeof (QdlUfopenReq), buffer_len - sizeof (QdlUfopenReq), cancellable, error) < 0) {
        g_prefix_error (error, "couldn't read image header: ");
        return -1;
    }

    g_debug ("[qfu,qdl-message] sent %s:", qfu_qdl_cmd_get_string ((QfuQdlCmd) req->cmd));
    g_debug ("[qfu,qdl-message]   type:        %u", req->type);
    g_debug ("[qfu,qdl-message]   length:      %" G_GUINT32_FORMAT, GUINT32_FROM_LE (req->length));
    g_debug ("[qfu,qdl-message]   window size: %u", req->windowsize);
    g_debug ("[qfu,qdl-message]   chunk size:  %" G_GUINT32_FORMAT, GUINT32_FROM_LE (req->chunksize));

	return (sizeof (QdlUfopenReq) + qfu_image_get_header_size (image));
}

typedef struct _QdlUfopenRsp QdlUfopenRsp;
struct _QdlUfopenRsp {
    guint8  cmd; /* 0x26 */
    guint16 status;
    guint8  windowsize;
    guint32 chunksize;
} __attribute__ ((packed));

G_STATIC_ASSERT (sizeof (QdlUfopenRsp) <= QFU_QDL_MESSAGE_MAX_HEADER_SIZE);

gboolean
qfu_qdl_response_ufopen_parse (const guint8  *buffer,
                               gsize          buffer_len,
                               GError       **error)
{
    QdlUfopenRsp *rsp;

	if (buffer_len != sizeof (QdlUfopenRsp)) {
        g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                     "message size mismatch: %" G_GSIZE_FORMAT " != %" G_GSIZE_FORMAT,
                     buffer_len, sizeof (QdlUfopenRsp));
        return FALSE;
    }

    rsp = (QdlUfopenRsp *) buffer;
    g_assert (rsp->cmd == QFU_QDL_CMD_OPEN_UNFRAMED_RSP);

    g_debug ("[qfu,qdl-message] received %s", qfu_qdl_cmd_get_string ((QfuQdlCmd) rsp->cmd));
    g_debug ("[qfu,qdl-message]   status:      %" G_GUINT16_FORMAT, GUINT16_FROM_LE (rsp->status));
    g_debug ("[qfu,qdl-message]   window size: %u", rsp->windowsize);
    g_debug ("[qfu,qdl-message]   chunk size:  %" G_GUINT32_FORMAT, GUINT32_FROM_LE (rsp->chunksize));

    /* For now, ignore all fields but build a GError based on status */

    /* Return error if status != 0 */
    if (rsp->status != 0) {
        g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                     "operation returned an error status: %" G_GUINT16_FORMAT,
                     GUINT16_FROM_LE (rsp->status));
        return FALSE;
    }

    return TRUE;
}

/******************************************************************************/
/* QDL Ufwrite */

/* This request is not HDLC framed, so this "header" includes the crc */
typedef struct _QdlUfwriteReq QdlUfwriteReq;
struct _QdlUfwriteReq {
    guint8  cmd; /* 0x27 */
    guint16 sequence;
    guint32 reserved;
    guint32 chunksize;
    guint16 crc;
} __attribute__ ((packed));

G_STATIC_ASSERT (sizeof (QdlUfwriteReq) <= QFU_QDL_MESSAGE_MAX_HEADER_SIZE);

gssize
qfu_qdl_request_ufwrite_build (guint8        *buffer,
                               gsize          buffer_len,
                               QfuImage      *image,
                               guint16        sequence,
                               GCancellable  *cancellable,
                               GError       **error)
{
    QdlUfwriteReq *req;
    gssize         n_read;

    g_assert (buffer_len >= sizeof (QdlUfwriteReq));

    /* Append chunk */
    n_read = qfu_image_read_data_chunk (image, sequence, buffer + sizeof (QdlUfwriteReq), buffer_len - sizeof (QdlUfwriteReq), cancellable, error);
    if (n_read < 0) {
        g_prefix_error (error, "couldn't read image chunk #%u: ", sequence);
        return -1;
    }

    /* Create request after appending, so that we have correct chunksize */
    req = (QdlUfwriteReq *) buffer;
    memset (req, 0, sizeof (QdlUfwriteReq));
	req->cmd       = QFU_QDL_CMD_WRITE_UNFRAMED_REQ;
	req->sequence  = GUINT16_TO_LE (sequence);
	req->reserved  = 0;
	req->chunksize = GUINT32_TO_LE ((guint32) n_read);
	req->crc       = GUINT16_TO_LE (qfu_utils_crc16 (buffer, sizeof (QdlUfwriteReq) - 2));

    g_debug ("[qfu,qdl-message] sent %s:", qfu_qdl_cmd_get_string ((QfuQdlCmd) req->cmd));
    g_debug ("[qfu,qdl-message]   sequence:   %" G_GUINT16_FORMAT, GUINT16_FROM_LE (req->sequence));
    g_debug ("[qfu,qdl-message]   chunk size: %" G_GUINT32_FORMAT, GUINT32_FROM_LE (req->chunksize));

	return (sizeof (QdlUfopenReq) + n_read);
}

/* The response is HDLC framed, so the crc is part of the framing */
typedef struct _QdlUfwriteRsp QdlUfwriteRsp;
struct _QdlUfwriteRsp {
    guint8  cmd; /* 0x28 */
    guint16 sequence;
    guint32 reserved;
    guint16 status;
} __attribute__ ((packed));

G_STATIC_ASSERT (sizeof (QdlUfwriteRsp) <= QFU_QDL_MESSAGE_MAX_HEADER_SIZE);

gboolean
qfu_qdl_response_ufwrite_parse (const guint8  *buffer,
                                gsize          buffer_len,
                                guint16       *sequence,
                                GError       **error)
{
    QdlUfwriteRsp *rsp;

	if (buffer_len != sizeof (QdlUfwriteRsp)) {
        g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                     "message size mismatch: %" G_GSIZE_FORMAT " != %" G_GSIZE_FORMAT,
                     buffer_len, sizeof (QdlUfwriteRsp));
        return FALSE;
    }

    rsp = (QdlUfwriteRsp *) buffer;
    g_assert (rsp->cmd == QFU_QDL_CMD_WRITE_UNFRAMED_RSP);

    g_debug ("[qfu,qdl-message] received %s", qfu_qdl_cmd_get_string ((QfuQdlCmd) rsp->cmd));
    g_debug ("[qfu,qdl-message]   status:   %" G_GUINT16_FORMAT, GUINT16_FROM_LE (rsp->status));
    g_debug ("[qfu,qdl-message]   sequence: %" G_GUINT16_FORMAT, GUINT16_FROM_LE (rsp->sequence));

    /* Only return sequence and return GError based on status */

    /* Return error if status != 0 */
    if (rsp->status != 0) {
        g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                     "operation returned an error status: %" G_GUINT16_FORMAT,
                     GUINT16_FROM_LE (rsp->status));
        return FALSE;
    }

    if (sequence)
        *sequence = GUINT16_FROM_LE (rsp->sequence);

    return TRUE;
}

/******************************************************************************/
/* QDL Ufclose */

gsize
qfu_qdl_request_ufclose_build (guint8 *buffer,
                               gsize   buffer_len)
{
    return qdl_message_generic_build (buffer, buffer_len, QFU_QDL_CMD_CLOSE_UNFRAMED_REQ);
}

typedef struct _QdlUfcloseRsp QdlUfcloseRsp;
struct _QdlUfcloseRsp {
    guint8  cmd; /* 0x2a */
    guint16 status;
    guint8  type;
    guint8  errortxt;
} __attribute__ ((packed));

gboolean
qfu_qdl_response_ufclose_parse (const guint8  *buffer,
                                gsize          buffer_len,
                                GError       **error)
{
    QdlUfcloseRsp *rsp;

	if (buffer_len != sizeof (QdlUfcloseRsp)) {
        g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                     "message size mismatch: %" G_GSIZE_FORMAT " != %" G_GSIZE_FORMAT,
                     buffer_len, sizeof (QdlUfcloseRsp));
        return FALSE;
    }

    rsp = (QdlUfcloseRsp *) buffer;
    g_assert (rsp->cmd == QFU_QDL_CMD_CLOSE_UNFRAMED_RSP);

    g_debug ("[qfu,qdl-message] received %s", qfu_qdl_cmd_get_string ((QfuQdlCmd) rsp->cmd));
    g_debug ("[qfu,qdl-message]   status:      %" G_GUINT16_FORMAT, GUINT16_FROM_LE (rsp->status));
    g_debug ("[qfu,qdl-message]   type:        %u", rsp->type);
    g_debug ("[qfu,qdl-message]   errortxt:    %u", rsp->errortxt);

    /* For now, ignore all fields but build a GError based on status */

    /* Return error if status != 0 */
    if (rsp->status != 0) {
        g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                     "operation returned an error status: %" G_GUINT16_FORMAT,
                     GUINT16_FROM_LE (rsp->status));
        return FALSE;
    }

    return TRUE;
}

/******************************************************************************/
/* QDL session close */

gsize
qfu_qdl_request_reset_build (guint8 *buffer,
                             gsize   buffer_len)
{
    return qdl_message_generic_build (buffer, buffer_len, QFU_QDL_CMD_RESET_REQ);
}

/******************************************************************************/
/* Other unused messages */

/* 0x29 - cmd only */
/* 0x2d - cmd only */
/* 0x2e - cmd only */

typedef struct _QdlImageprefRsp QdlImageprefRsp;
struct _QdlImageprefRsp {
    guint8 cmd; /* 0x2f */
    guint8 entries;
    struct {
        guint8 type;
        gchar  id[16];
    } image[];
} __attribute__ ((packed));