Debian Codegraph @

src/qmi-firmware-update/qfu-image.h

raw
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * qmi-firmware-update -- Command line tool to update firmware in QMI devices
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Copyright (C) 2016 Bjørn Mork <[email protected]>
19 * Copyright (C) 2016 Zodiac Inflight Innovations
20 * Copyright (C) 2016-2017 Aleksander Morgado <[email protected]>
21 */
22
23 #ifndef QFU_IMAGE_H
24 #define QFU_IMAGE_H
25
26 #include <glib-object.h>
27 #include <gio/gio.h>
28
29 G_BEGIN_DECLS
30
31 /* Most of these origin from GobiAPI_1.0.40/Core/QDLEnum.h
32 *
33 * The gobi-loader's snooped magic strings use types
34 * 0x05 => "amss.mbn"
35 * 0x06 => "apps.mbn"
36 * 0x0d => "uqcn.mbn" (Gobi 2000 only)
37 * with no file header data
38 *
39 * The 0x80 type is snooped from the Sierra Wireless firmware
40 * uploaders, using 400 bytes file header data
41 */
42 typedef enum {
43 QFU_IMAGE_TYPE_UNKNOWN = 0x00,
44 QFU_IMAGE_TYPE_AMSS_MODEM = 0x05,
45 QFU_IMAGE_TYPE_AMSS_APPLICATION = 0x06,
46 QFU_IMAGE_TYPE_AMSS_UQCN = 0x0d,
47 QFU_IMAGE_TYPE_DBL = 0x0f,
48 QFU_IMAGE_TYPE_OSBL = 0x10,
49 QFU_IMAGE_TYPE_CWE = 0x80,
50 } QfuImageType;
51
52 /* Default chunk size */
53 #define QFU_IMAGE_CHUNK_SIZE (1024 * 1024)
54
55 #define QFU_TYPE_IMAGE (qfu_image_get_type ())
56 #define QFU_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), QFU_TYPE_IMAGE, QfuImage))
57 #define QFU_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), QFU_TYPE_IMAGE, QfuImageClass))
58 #define QFU_IS_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), QFU_TYPE_IMAGE))
59 #define QFU_IS_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), QFU_TYPE_IMAGE))
60 #define QFU_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), QFU_TYPE_IMAGE, QfuImageClass))
61
62 typedef struct _QfuImage QfuImage;
63 typedef struct _QfuImageClass QfuImageClass;
64 typedef struct _QfuImagePrivate QfuImagePrivate;
65
66 struct _QfuImage {
67 GObject parent;
68 QfuImagePrivate *priv;
69 };
70
71 struct _QfuImageClass {
72 GObjectClass parent;
73
74 goffset (* get_header_size) (QfuImage *self);
75 gssize (* read_header) (QfuImage *self,
76 guint8 *out_buffer,
77 gsize out_buffer_size,
78 GCancellable *cancellable,
79 GError **error);
80 goffset (* get_data_size) (QfuImage *self);
81 };
82
83 GType qfu_image_get_type (void);
84 G_DEFINE_AUTOPTR_CLEANUP_FUNC (QfuImage, g_object_unref);
85
86 QfuImage *qfu_image_new (GFile *file,
87 QfuImageType image_type,
88 GCancellable *cancellable,
89 GError **error);
90 QfuImageType qfu_image_get_image_type (QfuImage *self);
91 const gchar *qfu_image_get_display_name (QfuImage *self);
92 goffset qfu_image_get_size (QfuImage *self);
93 goffset qfu_image_get_header_size (QfuImage *self);
94 gssize qfu_image_read_header (QfuImage *self,
95 guint8 *out_buffer,
96 gsize out_buffer_size,
97 GCancellable *cancellable,
98 GError **error);
99 goffset qfu_image_get_data_size (QfuImage *self);
100 guint16 qfu_image_get_n_data_chunks (QfuImage *self);
101 gsize qfu_image_get_data_chunk_size (QfuImage *self,
102 guint16 chunk_i);
103 gssize qfu_image_read_data_chunk (QfuImage *self,
104 guint16 chunk_i,
105 guint8 *out_buffer,
106 gsize out_buffer_size,
107 GCancellable *cancellable,
108 GError **error);
109 gssize qfu_image_read (QfuImage *self,
110 goffset offset,
111 gsize size,
112 guint8 *out_buffer,
113 gsize out_buffer_size,
114 GCancellable *cancellable,
115 GError **error);
116
117 G_END_DECLS
118
119 #endif /* QFU_IMAGE_H */