| 1 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* libqmi-glib -- GLib/GIO based library to control QMI devices |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library 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 GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public |
| 16 |
* License along with this library; if not, write to the |
| 17 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 |
* Boston, MA 02110-1301 USA. |
| 19 |
* |
| 20 |
* Copyright (C) 2020 Aleksander Morgado <[email protected]> |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <glib.h> |
| 24 |
#include "qmi-enums-nas.h" |
| 25 |
#include "qmi-helpers.h" |
| 26 |
|
| 27 |
gchar * |
| 28 |
qmi_nas_read_string_from_plmn_encoded_array (QmiNasPlmnEncodingScheme encoding, |
| 29 |
const GArray *array) |
| 30 |
{ |
| 31 |
switch (encoding) { |
| 32 |
case QMI_NAS_PLMN_ENCODING_SCHEME_GSM: |
| 33 |
return qmi_helpers_string_utf8_from_gsm7 ((const guint8 *)array->data, array->len); |
| 34 |
case QMI_NAS_PLMN_ENCODING_SCHEME_UCS2LE: |
| 35 |
return qmi_helpers_string_utf8_from_ucs2le ((const guint8 *)array->data, array->len); |
| 36 |
default: |
| 37 |
return NULL; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
gchar * |
| 42 |
qmi_nas_read_string_from_network_description_encoded_array (QmiNasNetworkDescriptionEncoding encoding, |
| 43 |
const GArray *array) |
| 44 |
{ |
| 45 |
switch (encoding) { |
| 46 |
case QMI_NAS_NETWORK_DESCRIPTION_ENCODING_UNSPECIFIED: |
| 47 |
case QMI_NAS_NETWORK_DESCRIPTION_ENCODING_ASCII7: |
| 48 |
return (g_utf8_validate ((const gchar *)array->data, array->len, NULL) ? |
| 49 |
g_strndup ((const gchar *)array->data, array->len) : |
| 50 |
NULL); |
| 51 |
case QMI_NAS_NETWORK_DESCRIPTION_ENCODING_GSM: |
| 52 |
return qmi_helpers_string_utf8_from_gsm7 ((const guint8 *)array->data, array->len); |
| 53 |
case QMI_NAS_NETWORK_DESCRIPTION_ENCODING_UNICODE: |
| 54 |
return qmi_helpers_string_utf8_from_ucs2le ((const guint8 *)array->data, array->len); |
| 55 |
default: |
| 56 |
return NULL; |
| 57 |
} |
| 58 |
} |