Debian Codegraph @

src/libqmi-glib/qmi-helpers.h

raw
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3 /*
4 * libqmi-glib -- GLib/GIO based library to control QMI devices
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA.
20 *
21 * Copyright (C) 2012-2015 Dan Williams <[email protected]>
22 * Copyright (C) 2012-2017 Aleksander Morgado <[email protected]>
23 * Copyright (C) 1999,2000 Erik Walthinsen <[email protected]>
24 * Copyright (C) 2000 Wim Taymans <[email protected]>
25 * Copyright (C) 2002 Thomas Vander Stichele <[email protected]>
26
27 */
28
29 #ifndef _LIBQMI_GLIB_QMI_HELPERS_H_
30 #define _LIBQMI_GLIB_QMI_HELPERS_H_
31
32 #include <glib.h>
33 #include <gio/gio.h>
34
35 G_BEGIN_DECLS
36
37 G_GNUC_INTERNAL
38 gboolean qmi_helpers_check_user_allowed (uid_t uid,
39 GError **error);
40
41 G_GNUC_INTERNAL
42 gboolean qmi_helpers_check_group_allowed (uid_t uid,
43 GError **error);
44
45 G_GNUC_INTERNAL
46 gboolean qmi_helpers_string_utf8_validate_printable (const guint8 *utf8,
47 gsize utf8_len);
48
49 G_GNUC_INTERNAL
50 gchar *qmi_helpers_string_utf8_from_gsm7 (const guint8 *gsm,
51 gsize gsm_len);
52
53 G_GNUC_INTERNAL
54 gchar *qmi_helpers_string_utf8_from_ucs2le (const guint8 *ucs2le,
55 gsize ucs2le_len);
56
57 typedef enum {
58 QMI_HELPERS_TRANSPORT_TYPE_UNKNOWN,
59 QMI_HELPERS_TRANSPORT_TYPE_QMUX,
60 QMI_HELPERS_TRANSPORT_TYPE_MBIM,
61 } QmiHelpersTransportType;
62
63 /*
64 * Symbol defining the file name for a unix domain socket used instead of a device file.
65 * The unix domain socket is addressed with the QMUX protocol.
66 */
67 #define QMI_QMUX_SOCKET_FILE_NAME "qmux_socket"
68
69 G_GNUC_INTERNAL
70 QmiHelpersTransportType qmi_helpers_get_transport_type (const gchar *path,
71 GError **error);
72
73 G_GNUC_INTERNAL
74 gchar *qmi_helpers_get_devpath (const gchar *cdc_wdm_path,
75 GError **error);
76
77 G_GNUC_INTERNAL
78 gchar *qmi_helpers_get_devname (const gchar *cdc_wdm_path,
79 GError **error);
80
81 G_GNUC_INTERNAL
82 gboolean qmi_helpers_read_sysfs_file (const gchar *sysfs_path,
83 gchar *out_value, /* caller allocates */
84 guint max_read_size,
85 GError **error);
86
87 G_GNUC_INTERNAL
88 gboolean qmi_helpers_write_sysfs_file (const gchar *sysfs_path,
89 const gchar *value,
90 GError **error);
91
92 G_GNUC_INTERNAL
93 gboolean qmi_helpers_list_links (GFile *sysfs_file,
94 GCancellable *cancellable,
95 GPtrArray *previous_links,
96 GPtrArray **out_links,
97 GError **error);
98
99 G_GNUC_INTERNAL
100 void qmi_helpers_clear_string (gchar **value);
101
102 static inline gfloat
103 QMI_GFLOAT_SWAP_LE_BE (gfloat in)
104 {
105 union
106 {
107 guint32 i;
108 gfloat f;
109 } u;
110
111 u.f = in;
112 u.i = GUINT32_SWAP_LE_BE (u.i);
113 return u.f;
114 }
115
116 static inline gdouble
117 QMI_GDOUBLE_SWAP_LE_BE (gdouble in)
118 {
119 union
120 {
121 guint64 i;
122 gdouble d;
123 } u;
124
125 u.d = in;
126 u.i = GUINT64_SWAP_LE_BE (u.i);
127 return u.d;
128 }
129
130 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
131 #define QMI_ENDIAN_HOST QMI_ENDIAN_LITTLE
132 #define QMI_GFLOAT_TO_LE(val) ((gfloat) (val))
133 #define QMI_GFLOAT_TO_BE(val) (QMI_GFLOAT_SWAP_LE_BE (val))
134 #define QMI_GDOUBLE_TO_LE(val) ((gdouble) (val))
135 #define QMI_GDOUBLE_TO_BE(val) (QMI_GDOUBLE_SWAP_LE_BE (val))
136
137 #elif G_BYTE_ORDER == G_BIG_ENDIAN
138 #define QMI_ENDIAN_HOST QMI_ENDIAN_BIG
139 #define QMI_GFLOAT_TO_LE(val) (QMI_GFLOAT_SWAP_LE_BE (val))
140 #define QMI_GFLOAT_TO_BE(val) ((gfloat) (val))
141 #define QMI_GDOUBLE_TO_LE(val) (QMI_GDOUBLE_SWAP_LE_BE (val))
142 #define QMI_GDOUBLE_TO_BE(val) ((gdouble) (val))
143
144 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
145 #error unknown ENDIAN type
146 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
147
148 #define QMI_GFLOAT_FROM_LE(val) (QMI_GFLOAT_TO_LE (val))
149 #define QMI_GFLOAT_FROM_BE(val) (QMI_GFLOAT_TO_BE (val))
150 #define QMI_GDOUBLE_FROM_LE(val) (QMI_GDOUBLE_TO_LE (val))
151 #define QMI_GDOUBLE_FROM_BE(val) (QMI_GDOUBLE_TO_BE (val))
152
153
154
155 #if !GLIB_CHECK_VERSION(2,54,0)
156
157 /* Pointer Array lookup with a GEqualFunc, imported from GLib 2.54 */
158 #define g_ptr_array_find_with_equal_func qmi_ptr_array_find_with_equal_func
159 G_GNUC_INTERNAL
160 gboolean qmi_ptr_array_find_with_equal_func (GPtrArray *haystack,
161 gconstpointer needle,
162 GEqualFunc equal_func,
163 guint *index_);
164
165 #endif
166
167 G_END_DECLS
168
169 #endif /* _LIBQMI_GLIB_QMI_UTILS_PRIVATE_H_ */