libmm-glib,cell-info-cdma: new 'MMCellInfoCdma' object

Implementing support for CDMA cell info.
This commit is contained in:
Aleksander Morgado
2021-12-28 15:08:37 +01:00
parent bfb66970f2
commit 58de2a9904
8 changed files with 448 additions and 1 deletions

View File

@@ -93,6 +93,7 @@
<xi:include href="xml/mm-cdma-manual-activation-properties.xml"/>
<xi:include href="xml/mm-unlock-retries.xml"/>
<xi:include href="xml/mm-cell-info.xml"/>
<xi:include href="xml/mm-cell-info-cdma.xml"/>
<xi:include href="xml/mm-pco.xml"/>
<xi:include href="xml/mm-nr5g-registration-settings.xml"/>
</section>

View File

@@ -306,6 +306,35 @@ MM_CELL_INFO_GET_CLASS
mm_cell_info_get_type
</SECTION>
<SECTION>
<FILE>mm-cell-info-cdma</FILE>
<TITLE>MMCellInfoCdma</TITLE>
MMCellInfoCdma
<SUBSECTION Getters>
mm_cell_info_cdma_get_nid
mm_cell_info_cdma_get_sid
mm_cell_info_cdma_get_base_station_id
mm_cell_info_cdma_get_ref_pn
mm_cell_info_cdma_get_pilot_strength
<SUBSECTION Private>
mm_cell_info_cdma_new_from_dictionary
mm_cell_info_cdma_set_nid
mm_cell_info_cdma_set_sid
mm_cell_info_cdma_set_base_station_id
mm_cell_info_cdma_set_ref_pn
mm_cell_info_cdma_set_pilot_strength
<SUBSECTION Standard>
MMCellInfoCdmaClass
MMCellInfoCdmaPrivate
MM_IS_CELL_INFO_CDMA
MM_IS_CELL_INFO_CDMA_CLASS
MM_TYPE_CELL_INFO_CDMA
MM_CELL_INFO_CDMA
MM_CELL_INFO_CDMA_CLASS
MM_CELL_INFO_CDMA_GET_CLASS
mm_cell_info_cdma_get_type
</SECTION>
<SECTION>
<FILE>mm-modem-3gpp</FILE>
<TITLE>MMModem3gpp</TITLE>

View File

@@ -103,6 +103,8 @@ libmm_glib_la_SOURCES = \
mm-nr5g-registration-settings.c \
mm-cell-info.h \
mm-cell-info.c \
mm-cell-info-cdma.h \
mm-cell-info-cdma.c \
mm-compat.h \
mm-compat.c \
$(NULL)
@@ -183,6 +185,7 @@ include_HEADERS = \
mm-signal-threshold-properties.h \
mm-nr5g-registration-settings.h \
mm-cell-info.h \
mm-cell-info-cdma.h \
mm-compat.h \
$(NULL)

View File

@@ -87,6 +87,7 @@
#include <mm-signal-threshold-properties.h>
#include <mm-nr5g-registration-settings.h>
#include <mm-cell-info.h>
#include <mm-cell-info-cdma.h>
#include <mm-compat.h>
/* generated */

View File

@@ -17,6 +17,7 @@ headers = files(
'mm-call-properties.h',
'mm-cdma-manual-activation-properties.h',
'mm-cell-info.h',
'mm-cell-info-cdma.h',
'mm-compat.h',
'mm-firmware-properties.h',
'mm-firmware-update-settings.h',
@@ -73,6 +74,7 @@ sources = files(
'mm-call-properties.c',
'mm-cdma-manual-activation-properties.c',
'mm-cell-info.c',
'mm-cell-info-cdma.c',
'mm-common-helpers.c',
'mm-compat.c',
'mm-firmware-properties.c',

View File

@@ -0,0 +1,308 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* libmm-glib -- Access modem status & information from glib applications
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2022 Aleksander Morgado <aleksander@aleksander.es>
*/
#include "mm-helpers.h"
#include "mm-cell-info-cdma.h"
/**
* SECTION: mm-cell-info-cdma
* @title: MMCellInfoCdma
* @short_description: Helper object to report CDMA cell info
*
* The #MMCellInfoCdma is an object used to report CDMA cell
* information.
*
* The object inherits from the generic #MMCellInfo.
*/
G_DEFINE_TYPE (MMCellInfoCdma, mm_cell_info_cdma, MM_TYPE_CELL_INFO)
#define PROPERTY_NID "nid"
#define PROPERTY_SID "sid"
#define PROPERTY_BASE_STATION_ID "base-station-id"
#define PROPERTY_REF_PN "ref-pn"
#define PROPERTY_PILOT_STRENGTH "pilot-strength"
struct _MMCellInfoCdmaPrivate {
gchar *nid;
gchar *sid;
gchar *base_station_id;
gchar *ref_pn;
guint pilot_strength;
};
/*****************************************************************************/
/**
* mm_cell_info_cdma_get_nid:
* @self: a #MMCellInfoCdma.
*
* Get the CDMA network id.
*
* Encoded in upper-case hexadecimal format without leading zeros.
*
* Returns: (transfer none): the CDMA network id, or %NULL if not available.
*
* Since: 1.20
*/
const gchar *
mm_cell_info_cdma_get_nid (MMCellInfoCdma *self)
{
g_return_val_if_fail (MM_IS_CELL_INFO_CDMA (self), NULL);
RETURN_NON_EMPTY_CONSTANT_STRING (self->priv->nid);
}
/**
* mm_cell_info_cdma_set_nid: (skip)
*/
void
mm_cell_info_cdma_set_nid (MMCellInfoCdma *self,
const gchar *nid)
{
g_free (self->priv->nid);
self->priv->nid = g_strdup (nid);
}
/**
* mm_cell_info_cdma_get_sid:
* @self: a #MMCellInfoCdma.
*
* Get the CDMA system id.
*
* Encoded in upper-case hexadecimal format without leading zeros.
*
* Returns: (transfer none): the CDMA system id, or %NULL if not available.
*
* Since: 1.20
*/
const gchar *
mm_cell_info_cdma_get_sid (MMCellInfoCdma *self)
{
g_return_val_if_fail (MM_IS_CELL_INFO_CDMA (self), NULL);
RETURN_NON_EMPTY_CONSTANT_STRING (self->priv->sid);
}
/**
* mm_cell_info_cdma_set_sid: (skip)
*/
void
mm_cell_info_cdma_set_sid (MMCellInfoCdma *self,
const gchar *sid)
{
g_free (self->priv->sid);
self->priv->sid = g_strdup (sid);
}
/**
* mm_cell_info_cdma_get_base_station_id:
* @self: a #MMCellInfoCdma.
*
* Get the CDMA base station id.
*
* Encoded in upper-case hexadecimal format without leading zeros.
*
* Returns: (transfer none): the CDMA base station id, or %NULL if not available.
*
* Since: 1.20
*/
const gchar *
mm_cell_info_cdma_get_base_station_id (MMCellInfoCdma *self)
{
g_return_val_if_fail (MM_IS_CELL_INFO_CDMA (self), NULL);
RETURN_NON_EMPTY_CONSTANT_STRING (self->priv->base_station_id);
}
/**
* mm_cell_info_cdma_set_base_station_id: (skip)
*/
void
mm_cell_info_cdma_set_base_station_id (MMCellInfoCdma *self,
const gchar *base_station_id)
{
g_free (self->priv->base_station_id);
self->priv->base_station_id = g_strdup (base_station_id);
}
/**
* mm_cell_info_cdma_get_ref_pn:
* @self: a #MMCellInfoCdma.
*
* Get the CDMA base station PN number.
*
* Encoded in upper-case hexadecimal format without leading zeros.
*
* Returns: (transfer none): the CDMA base station PN number, or %NULL if not available.
*
* Since: 1.20
*/
const gchar *
mm_cell_info_cdma_get_ref_pn (MMCellInfoCdma *self)
{
g_return_val_if_fail (MM_IS_CELL_INFO_CDMA (self), NULL);
RETURN_NON_EMPTY_CONSTANT_STRING (self->priv->ref_pn);
}
/**
* mm_cell_info_cdma_set_ref_pn: (skip)
*/
void
mm_cell_info_cdma_set_ref_pn (MMCellInfoCdma *self,
const gchar *ref_pn)
{
g_free (self->priv->ref_pn);
self->priv->ref_pn = g_strdup (ref_pn);
}
/**
* mm_cell_info_cdma_get_pilot_strength:
* @self: a #MMCellInfoCdma.
*
* Get the signal strength of the pilot.
*
* Given in the same format and scale as the GSM SINR level.
*
* Returns: the pilot strength, or %G_MAXUINT if not available.
*
* Since: 1.20
*/
guint
mm_cell_info_cdma_get_pilot_strength (MMCellInfoCdma *self)
{
g_return_val_if_fail (MM_IS_CELL_INFO_CDMA (self), G_MAXUINT);
return self->priv->pilot_strength;
}
/**
* mm_cell_info_cdma_set_pilot_strength: (skip)
*/
void
mm_cell_info_cdma_set_pilot_strength (MMCellInfoCdma *self,
guint pilot_strength)
{
self->priv->pilot_strength = pilot_strength;
}
/*****************************************************************************/
static GString *
build_string (MMCellInfo *_self)
{
MMCellInfoCdma *self = MM_CELL_INFO_CDMA (_self);
GString *str;
str = g_string_new (NULL);
MM_CELL_INFO_BUILD_STRING_APPEND ("nid", "%s", nid, NULL);
MM_CELL_INFO_BUILD_STRING_APPEND ("sid", "%s", sid, NULL);
MM_CELL_INFO_BUILD_STRING_APPEND ("base station id", "%s", base_station_id, NULL);
MM_CELL_INFO_BUILD_STRING_APPEND ("ref pn", "%s", ref_pn, NULL);
MM_CELL_INFO_BUILD_STRING_APPEND ("pilot strength", "%u", pilot_strength, G_MAXUINT);
return str;
}
/*****************************************************************************/
/**
* mm_cell_info_cdma_get_dictionary: (skip)
*/
static GVariantDict *
get_dictionary (MMCellInfo *_self)
{
MMCellInfoCdma *self = MM_CELL_INFO_CDMA (_self);
GVariantDict *dict;
dict = g_variant_dict_new (NULL);
MM_CELL_INFO_GET_DICTIONARY_INSERT (NID, nid, string, NULL);
MM_CELL_INFO_GET_DICTIONARY_INSERT (SID, sid, string, NULL);
MM_CELL_INFO_GET_DICTIONARY_INSERT (BASE_STATION_ID, base_station_id, string, NULL);
MM_CELL_INFO_GET_DICTIONARY_INSERT (REF_PN, ref_pn, string, NULL);
MM_CELL_INFO_GET_DICTIONARY_INSERT (PILOT_STRENGTH, pilot_strength, uint32, G_MAXUINT);
return dict;
}
/*****************************************************************************/
/**
* mm_cell_info_cdma_new_from_dictionary: (skip)
*/
MMCellInfo *
mm_cell_info_cdma_new_from_dictionary (GVariantDict *dict)
{
MMCellInfoCdma *self;
self = MM_CELL_INFO_CDMA (g_object_new (MM_TYPE_CELL_INFO_CDMA, NULL));
if (dict) {
MM_CELL_INFO_NEW_FROM_DICTIONARY_STRING_SET (cdma, NID, nid);
MM_CELL_INFO_NEW_FROM_DICTIONARY_STRING_SET (cdma, SID, sid);
MM_CELL_INFO_NEW_FROM_DICTIONARY_STRING_SET (cdma, BASE_STATION_ID, base_station_id);
MM_CELL_INFO_NEW_FROM_DICTIONARY_STRING_SET (cdma, REF_PN, ref_pn);
MM_CELL_INFO_NEW_FROM_DICTIONARY_NUM_SET (cdma, PILOT_STRENGTH, pilot_strength, UINT32, uint32);
}
return MM_CELL_INFO (self);
}
/*****************************************************************************/
static void
mm_cell_info_cdma_init (MMCellInfoCdma *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MM_TYPE_CELL_INFO_CDMA, MMCellInfoCdmaPrivate);
self->priv->pilot_strength = G_MAXUINT;
}
static void
finalize (GObject *object)
{
MMCellInfoCdma *self = MM_CELL_INFO_CDMA (object);
g_free (self->priv->sid);
g_free (self->priv->nid);
g_free (self->priv->base_station_id);
g_free (self->priv->ref_pn);
G_OBJECT_CLASS (mm_cell_info_cdma_parent_class)->finalize (object);
}
static void
mm_cell_info_cdma_class_init (MMCellInfoCdmaClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
MMCellInfoClass *cell_info_class = MM_CELL_INFO_CLASS (klass);
g_type_class_add_private (object_class, sizeof (MMCellInfoCdmaPrivate));
object_class->finalize = finalize;
cell_info_class->get_dictionary = get_dictionary;
cell_info_class->build_string = build_string;
}

View File

@@ -0,0 +1,98 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* libmm-glib -- Access modem status & information from glib applications
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2022 Aleksander Morgado <aleksander@aleksander.es>
*/
#ifndef MM_CELL_INFO_CDMA_H
#define MM_CELL_INFO_CDMA_H
#if !defined (__LIBMM_GLIB_H_INSIDE__) && !defined (LIBMM_GLIB_COMPILATION)
#error "Only <libmm-glib.h> can be included directly."
#endif
#include <ModemManager.h>
#include <glib-object.h>
#include "mm-cell-info.h"
G_BEGIN_DECLS
#define MM_TYPE_CELL_INFO_CDMA (mm_cell_info_cdma_get_type ())
#define MM_CELL_INFO_CDMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_CELL_INFO_CDMA, MMCellInfoCdma))
#define MM_CELL_INFO_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_CELL_INFO_CDMA, MMCellInfoCdmaClass))
#define MM_IS_CELL_INFO_CDMA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_CELL_INFO_CDMA))
#define MM_IS_CELL_INFO_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_CELL_INFO_CDMA))
#define MM_CELL_INFO_CDMA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_CELL_INFO_CDMA, MMCellInfoCdmaClass))
typedef struct _MMCellInfoCdma MMCellInfoCdma;
typedef struct _MMCellInfoCdmaClass MMCellInfoCdmaClass;
typedef struct _MMCellInfoCdmaPrivate MMCellInfoCdmaPrivate;
/**
* MMCellInfoCdma:
*
* The #MMCellInfoCdma structure contains private data and should only be
* accessed using the provided API.
*/
struct _MMCellInfoCdma {
/*< private >*/
MMCellInfo parent;
MMCellInfoCdmaPrivate *priv;
};
struct _MMCellInfoCdmaClass {
/*< private >*/
MMCellInfoClass parent;
};
GType mm_cell_info_cdma_get_type (void);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MMCellInfoCdma, g_object_unref)
const gchar *mm_cell_info_cdma_get_nid (MMCellInfoCdma *self);
const gchar *mm_cell_info_cdma_get_sid (MMCellInfoCdma *self);
const gchar *mm_cell_info_cdma_get_base_station_id (MMCellInfoCdma *self);
const gchar *mm_cell_info_cdma_get_ref_pn (MMCellInfoCdma *self);
guint mm_cell_info_cdma_get_pilot_strength (MMCellInfoCdma *self);
/*****************************************************************************/
/* ModemManager/libmm-glib/mmcli specific methods */
#if defined (_LIBMM_INSIDE_MM) || \
defined (_LIBMM_INSIDE_MMCLI) || \
defined (LIBMM_GLIB_COMPILATION)
void mm_cell_info_cdma_set_nid (MMCellInfoCdma *self,
const gchar *nid);
void mm_cell_info_cdma_set_sid (MMCellInfoCdma *self,
const gchar *sid);
void mm_cell_info_cdma_set_base_station_id (MMCellInfoCdma *self,
const gchar *base_station_id);
void mm_cell_info_cdma_set_ref_pn (MMCellInfoCdma *self,
const gchar *ref_pn);
void mm_cell_info_cdma_set_pilot_strength (MMCellInfoCdma *self,
guint pilot_strength);
MMCellInfo *mm_cell_info_cdma_new_from_dictionary (GVariantDict *dict);
#endif
G_END_DECLS
#endif /* MM_CELL_INFO_CDMA_H */

View File

@@ -21,6 +21,7 @@
*/
#include "mm-cell-info.h"
#include "mm-cell-info-cdma.h"
#include "mm-enums-types.h"
#include "mm-errors-types.h"
@@ -54,7 +55,9 @@ ensure_cell_type (MMCellInfo *self)
if (self->priv->cell_type != MM_CELL_TYPE_UNKNOWN)
return;
/* MM_CELL_TYPE_CDMA; */
if (MM_IS_CELL_INFO_CDMA (self))
self->priv->cell_type = MM_CELL_TYPE_CDMA;
/* MM_CELL_TYPE_GSM; */
/* MM_CELL_TYPE_UMTS; */
/* MM_CELL_TYPE_TDSCDMA; */
@@ -154,6 +157,8 @@ mm_cell_info_new_from_dictionary (GVariant *dictionary,
}
switch (g_variant_get_uint32 (aux)) {
case MM_CELL_TYPE_CDMA:
self = mm_cell_info_cdma_new_from_dictionary (dict);
break;
case MM_CELL_TYPE_GSM:
case MM_CELL_TYPE_UMTS:
case MM_CELL_TYPE_TDSCDMA: