Debian Codegraph @

src/libmbim-glib/mbim-tlv.h

raw
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 /*
4 * libmbim-glib -- GLib/GIO based library to control MBIM devices
5 *
6 * Copyright (C) 2021 Aleksander Morgado <[email protected]>
7 * Copyright (C) 2021 Intel Corporation
8 */
9
10 #ifndef _LIBMBIM_GLIB_MBIM_TLV_H_
11 #define _LIBMBIM_GLIB_MBIM_TLV_H_
12
13 #if !defined (__LIBMBIM_GLIB_H_INSIDE__) && !defined (LIBMBIM_GLIB_COMPILATION)
14 #error "Only <libmbim-glib.h> can be included directly."
15 #endif
16
17 #include <glib.h>
18 #include <glib-object.h>
19
20 #include "mbim-uuid.h"
21
22 G_BEGIN_DECLS
23
24 /**
25 * SECTION:mbim-tlv
26 * @title: MbimTlv
27 * @short_description: A variable-sized data structure specified in Microsoft
28 * MBIM extension v3.0.
29 *
30 * The #MbimTlv structure is capable of exchanging a wide range of information
31 * between an MBIM host and an MBIM device.
32 *
33 * CID payloads for requests, responses, and/or notifications may contain zero
34 * or more unnamed and optional Information Elements (IE) encoded as #MbimTlv
35 * fields.
36 */
37
38 /**
39 * MbimTlv:
40 *
41 * An opaque type representing a MBIM TLV.
42 *
43 * Since: 1.28
44 */
45 typedef struct _MbimTlv MbimTlv;
46
47 GType mbim_tlv_get_type (void) G_GNUC_CONST;
48 #define MBIM_TYPE_TLV (mbim_tlv_get_type ())
49
50 /*****************************************************************************/
51 /* Generic TLV interface */
52
53 /**
54 * MbimTlvType:
55 * @MBIM_TLV_TYPE_INVALID: Invalid TLV type.
56 * @MBIM_TLV_TYPE_UE_POLICITES: UE policies.
57 * @MBIM_TLV_TYPE_SINGLE_NSSAI: Single NSSAI.
58 * @MBIM_TLV_TYPE_ALLOWED_NSSAI: Allowed NSSAI.
59 * @MBIM_TLV_TYPE_CFG_NSSAI: Configured NSSAI.
60 * @MBIM_TLV_TYPE_DFLT_CFG_NSSAI: Default configured NSSAI.
61 * @MBIM_TLV_TYPE_PRECFG_DFLT_CFG_NSSAI: Preconfigured default configured NSSAI.
62 * @MBIM_TLV_TYPE_REJ_NSSAI: Rejected NSSAI.
63 * @MBIM_TLV_TYPE_LADN: Local Area Data Network (LADN).
64 * @MBIM_TLV_TYPE_TAI: Tracking Area Identity (TAI).
65 * @MBIM_TLV_TYPE_WCHAR_STR: WCHAR string.
66 * @MBIM_TLV_TYPE_UINT16_TBL: Array of 1 or more @guint16 entries.
67 * @MBIM_TLV_TYPE_EAP_PACKET: Extensible Authentication Protocol packet.
68 * @MBIM_TLV_TYPE_PCO: Protocol Configuration Option (PCO).
69 * @MBIM_TLV_TYPE_ROUTE_SELECTION_DESCRIPTORS: One or more route selection descriptors.
70 * @MBIM_TLV_TYPE_TRAFFIC_PARAMETERS: A traffic parameters record.
71 * @MBIM_TLV_TYPE_WAKE_COMMAND: Wake command.
72 * @MBIM_TLV_TYPE_WAKE_PACKET: Wake packet.
73 *
74 * Type of the MBIM TLV.
75 *
76 * Since: 1.28
77 */
78 typedef enum { /*< since=1.28 >*/
79 MBIM_TLV_TYPE_INVALID = 0,
80 MBIM_TLV_TYPE_UE_POLICITES = 1,
81 MBIM_TLV_TYPE_SINGLE_NSSAI = 2,
82 MBIM_TLV_TYPE_ALLOWED_NSSAI = 3,
83 MBIM_TLV_TYPE_CFG_NSSAI = 4,
84 MBIM_TLV_TYPE_DFLT_CFG_NSSAI = 5,
85 MBIM_TLV_TYPE_PRECFG_DFLT_CFG_NSSAI = 6,
86 MBIM_TLV_TYPE_REJ_NSSAI = 7,
87 MBIM_TLV_TYPE_LADN = 8,
88 MBIM_TLV_TYPE_TAI = 9,
89 MBIM_TLV_TYPE_WCHAR_STR = 10,
90 MBIM_TLV_TYPE_UINT16_TBL = 11,
91 MBIM_TLV_TYPE_EAP_PACKET = 12,
92 MBIM_TLV_TYPE_PCO = 13,
93 MBIM_TLV_TYPE_ROUTE_SELECTION_DESCRIPTORS = 14,
94 MBIM_TLV_TYPE_TRAFFIC_PARAMETERS = 15,
95 MBIM_TLV_TYPE_WAKE_COMMAND = 16,
96 MBIM_TLV_TYPE_WAKE_PACKET = 17,
97 } MbimTlvType;
98
99 /**
100 * mbim_tlv_new:
101 * @type: a #MbimTlvType.
102 * @data: contents of the TLV.
103 * @data_length: length of the message.
104 *
105 * Create a #MbimTlv with the given contents.
106 *
107 * Returns: (transfer full): a newly created #MbimTlv, which should be freed with mbim_tlv_unref().
108 *
109 * Since: 1.28
110 */
111 MbimTlv *mbim_tlv_new (MbimTlvType type,
112 const guint8 *data,
113 guint32 data_length);
114
115 /**
116 * mbim_tlv_dup:
117 * @self: a #MbimTlv to duplicate.
118 *
119 * Create a #MbimTlv with the same contents as @self.
120 *
121 * Returns: (transfer full): a newly created #MbimTlv, which should be freed with mbim_tlv_unref().
122 *
123 * Since: 1.28
124 */
125 MbimTlv *mbim_tlv_dup (const MbimTlv *self);
126
127 /**
128 * mbim_tlv_ref:
129 * @self: a #MbimTlv.
130 *
131 * Atomically increments the reference count of @self by one.
132 *
133 * Returns: (transfer full): the new reference to @self.
134 *
135 * Since: 1.28
136 */
137 MbimTlv *mbim_tlv_ref (MbimTlv *self);
138
139 /**
140 * mbim_tlv_unref:
141 * @self: a #MbimTlv.
142 *
143 * Atomically decrements the reference count of @self by one.
144 * If the reference count drops to 0, @self is completely disposed.
145 *
146 * Since: 1.28
147 */
148 void mbim_tlv_unref (MbimTlv *self);
149
150 /**
151 * mbim_tlv_get_raw:
152 * @self: a #MbimTlv.
153 * @length: (out): return location for the size of the output buffer.
154 * @error: return location for error or %NULL.
155 *
156 * Gets the whole raw data buffer of the #MbimTlv.
157 *
158 * Returns: The raw data buffer, or #NULL if @error is set.
159 *
160 * Since: 1.28
161 */
162 const guint8 *mbim_tlv_get_raw (const MbimTlv *self,
163 guint32 *length,
164 GError **error);
165
166 /**
167 * mbim_tlv_get_tlv_type:
168 * @self: a #MbimTlv.
169 *
170 * Gets the message type.
171 *
172 * Returns: a #MbimTlvType.
173 *
174 * Since: 1.28
175 */
176 MbimTlvType mbim_tlv_get_tlv_type (const MbimTlv *self);
177
178 /**
179 * mbim_tlv_get_tlv_data:
180 * @self: a #MbimTlv.
181 * @out_length: (out): return location for the size of the output buffer.
182 *
183 * Gets the TLV raw data.
184 *
185 * Returns: (transfer none): The raw data buffer, or #NULL if empty.
186 *
187 * Since: 1.28
188 */
189 const guint8 *mbim_tlv_get_tlv_data (const MbimTlv *self,
190 guint32 *out_length);
191
192 G_DEFINE_AUTOPTR_CLEANUP_FUNC (MbimTlv, mbim_tlv_unref)
193
194 /*****************************************************************************/
195 /* String TLV type helpers */
196
197 /**
198 * mbim_tlv_string_new:
199 * @str: a string.
200 * @error: return location for error or %NULL.
201 *
202 * Create a #MbimTlv of type %MBIM_TLV_TYPE_WCHAR_STR with the given contents.
203 *
204 * Returns: (transfer full): a newly created #MbimTlv which should be freed with mbim_tlv_unref(), or %NULL if @error is set.
205 *
206 * Since: 1.28
207 */
208 MbimTlv *mbim_tlv_string_new (const gchar *str,
209 GError **error);
210
211 /**
212 * mbim_tlv_string_get:
213 * @self: a #MbimTlv of type %MBIM_TLV_TYPE_WCHAR_STR.
214 * @error: return location for error or %NULL.
215 *
216 * Get a string with the contents in the #MbimTlv.
217 *
218 * Returns: (transfer full): a newly created string, which should be freed with g_free(), or %NULL if @error is set.
219 *
220 * Since: 1.28
221 */
222 gchar *mbim_tlv_string_get (const MbimTlv *self,
223 GError **error);
224
225 /*****************************************************************************/
226 /* guint16 array type helpers */
227
228 /**
229 * mbim_tlv_guint16_array_get:
230 * @self: a #MbimTlv of type %MBIM_TLV_TYPE_UINT16_TBL.
231 * @array_size: (out)(optional)(transfer none): return location for a #guint32,
232 * or %NULL if the field is not needed.
233 * @array: (out)(optional)(transfer full)(type guint16): return location for a
234 * newly allocated array of #guint16 values, or %NULL if the field is not
235 * needed. Free the returned value with g_free().
236 * @error: return location for error or %NULL.
237 *
238 * Get an array of #guint16 values with the contents in the #MbimTlv.
239 *
240 * The method may return a successful return even with on empty arrays (i.e.
241 * with @array_size set to 0 and @array set to %NULL).
242 *
243 * Returns: %TRUE if on success, %FALSE if @error is set.
244 *
245 * Since: 1.28
246 */
247 gboolean mbim_tlv_guint16_array_get (const MbimTlv *self,
248 guint32 *array_size,
249 guint16 **array,
250 GError **error);
251
252 /*****************************************************************************/
253 /* wake command type helpers */
254
255 /**
256 * mbim_tlv_wake_command_get:
257 * @self: a #MbimTlv of type %MBIM_TLV_TYPE_WAKE_COMMAND.
258 * @service: (out)(optional)(transfer none): return location for a #MbimUuid
259 * specifying the service that triggered the wake.
260 * @cid: (out)(optional)(transfer none): return location for the command id that
261 * triggered the wake.
262 * @payload_size: (out)(optional)(transfer none): return location for a #guint32,
263 * or %NULL if the field is not needed.
264 * @payload: (out)(optional)(transfer full)(type guint8): return location for a
265 * newly allocated array of #guint8 values, or %NULL if the field is not
266 * needed. Free the returned value with g_free().
267 * @error: return location for error or %NULL.
268 *
269 * Get the contents of a wake command TLV.
270 *
271 * The method may return a successful return even with on empty payload (i.e.
272 * with @payload_size set to 0 and @payload set to %NULL).
273 *
274 * Returns: %TRUE if on success, %FALSE if @error is set.
275 *
276 * Since: 1.28
277 */
278 gboolean mbim_tlv_wake_command_get (const MbimTlv *self,
279 const MbimUuid **service,
280 guint32 *cid,
281 guint32 *payload_size,
282 guint8 **payload,
283 GError **error);
284
285 /*****************************************************************************/
286 /* wake packet type helpers */
287
288 /**
289 * mbim_tlv_wake_packet_get:
290 * @self: a #MbimTlv of type %MBIM_TLV_TYPE_WAKE_PACKET.
291 * @filter_id: (out)(optional)(transfer none): return location for a #guint32
292 * specifying the filter id.
293 * @original_packet_size: (out)(optional)(transfer none): return location for a
294 * #guint32, or %NULL if the field is not needed.
295 * @packet_size: (out)(optional)(transfer none): return location for a #guint32,
296 * or %NULL if the field is not needed.
297 * @packet: (out)(optional)(transfer full)(type guint8): return location for a
298 * newly allocated array of #guint8 values, or %NULL if the field is not
299 * needed. Free the returned value with g_free().
300 * @error: return location for error or %NULL.
301 *
302 * Get the contents of a wake packet TLV.
303 *
304 * Returns: %TRUE if on success, %FALSE if @error is set.
305 *
306 * Since: 1.28
307 */
308 gboolean mbim_tlv_wake_packet_get (const MbimTlv *self,
309 guint32 *filter_id,
310 guint32 *original_packet_size,
311 guint32 *packet_size,
312 guint8 **packet,
313 GError **error);
314
315 G_END_DECLS
316
317 #endif /* _LIBMBIM_GLIB_MBIM_TLV_H_ */