broadband-modem,iface-modem: move bearer counting to interface and generalize

Allow counting more kinds of bearers than just multiplexed ones.

Signed-off-by: Dan Williams <dan@ioncontrol.co>
This commit is contained in:
Dan Williams
2025-07-21 15:11:16 -05:00
parent 6c75cbcf74
commit f7897daeb5
6 changed files with 93 additions and 60 deletions
+5 -4
View File
@@ -1459,10 +1459,11 @@ load_settings_from_bearer (MMBearerMbim *self,
guint max_multiplexed_bearers;
const gchar *data_port_driver;
if (!mm_broadband_modem_get_active_multiplexed_bearers (MM_BROADBAND_MODEM (ctx->modem),
&current_multiplexed_bearers,
&max_multiplexed_bearers,
error))
if (!mm_iface_modem_count_bearers (MM_IFACE_MODEM (ctx->modem),
MM_IFACE_MODEM_COUNT_BEARERS_FLAG_MULTIPLEXED,
&current_multiplexed_bearers,
&max_multiplexed_bearers,
error))
return FALSE;
/* Check multiplex support in the kernel and the device */
+5 -4
View File
@@ -2425,10 +2425,11 @@ load_settings_from_bearer (MMBearerQmi *self,
guint max_multiplexed_bearers;
gboolean multiplex_supported = TRUE;
if (!mm_broadband_modem_get_active_multiplexed_bearers (MM_BROADBAND_MODEM (ctx->modem),
&current_multiplexed_bearers,
&max_multiplexed_bearers,
error))
if (!mm_iface_modem_count_bearers (MM_IFACE_MODEM (ctx->modem),
MM_IFACE_MODEM_COUNT_BEARERS_FLAG_MULTIPLEXED,
&current_multiplexed_bearers,
&max_multiplexed_bearers,
error))
return FALSE;
/* Check multiplex support in the kernel and the device */
-46
View File
@@ -13809,52 +13809,6 @@ mm_broadband_modem_get_current_charset (MMBroadbandModem *self)
/*****************************************************************************/
static void
bearer_count_multiplexed_connected (MMBaseBearer *bearer,
guint *count)
{
/* The Multiplexed property is only set if connected, so it's enough to check
* that one to see if we're connected and multiplexed */
if (mm_gdbus_bearer_get_multiplexed (MM_GDBUS_BEARER (bearer)))
*count += 1;
}
gboolean
mm_broadband_modem_get_active_multiplexed_bearers (MMBroadbandModem *self,
guint *out_current,
guint *out_max,
GError **error)
{
g_autoptr(MMBearerList) list = NULL;
guint max;
guint count = 0;
g_object_get (self,
MM_IFACE_MODEM_BEARER_LIST, &list,
NULL);
if (!list) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Bearer list unavailable");
return FALSE;
}
max = mm_bearer_list_get_max_active_multiplexed (list);
mm_bearer_list_foreach (list,
(MMBearerListForeachFunc)bearer_count_multiplexed_connected,
&count);
g_assert (!(!max && count));
if (out_max)
*out_max = max;
if (out_current)
*out_current = count;
return TRUE;
}
/*****************************************************************************/
gchar *
mm_broadband_modem_create_device_identifier (MMBroadbandModem *self,
const gchar *ati,
-6
View File
@@ -135,12 +135,6 @@ gboolean mm_broadband_modem_sim_hot_swap_ports_context_init (MMBroadbandModem
GError **error);
void mm_broadband_modem_sim_hot_swap_ports_context_reset (MMBroadbandModem *self);
/* Helper to manage multiplexed bearers */
gboolean mm_broadband_modem_get_active_multiplexed_bearers (MMBroadbandModem *self,
guint *out_current,
guint *out_max,
GError **error);
/* Helper to manage initial EPS bearer */
gint mm_broadband_modem_get_initial_eps_bearer_cid (MMBroadbandModem *self);
+68
View File
@@ -6784,6 +6784,74 @@ mm_iface_modem_get_current_modes (MMIfaceModem *self,
/*****************************************************************************/
typedef struct {
const MMIfaceModemCountBearersFlags flags;
guint count;
} CountBearersContext;
static void
bearer_count (MMBaseBearer *bearer,
CountBearersContext *ctx)
{
MMBearerStatus status;
status = mm_base_bearer_get_status (MM_BASE_BEARER (bearer));
if (ctx->flags & MM_IFACE_MODEM_COUNT_BEARERS_FLAG_MULTIPLEXED) {
/* The Multiplexed property is only set if connected, so it's enough to check
* that one to see if we're connected and multiplexed */
if (mm_gdbus_bearer_get_multiplexed (MM_GDBUS_BEARER (bearer)))
ctx->count++;
} else if (ctx->flags & MM_IFACE_MODEM_COUNT_BEARERS_FLAG_CONNECTED) {
if (status == MM_BEARER_STATUS_CONNECTED)
ctx->count++;
} else if (ctx->flags & MM_IFACE_MODEM_COUNT_BEARERS_FLAG_ACTIVE) {
if (status >= MM_BEARER_STATUS_CONNECTING)
ctx->count++;
} else
ctx->count++;
}
gboolean
mm_iface_modem_count_bearers (MMIfaceModem *self,
MMIfaceModemCountBearersFlags flags,
guint *out_current,
guint *out_max,
GError **error)
{
g_autoptr(MMBearerList) list = NULL;
guint max = 0;
CountBearersContext ctx = {
.flags = flags,
.count = 0,
};
g_object_get (self,
MM_IFACE_MODEM_BEARER_LIST, &list,
NULL);
if (!list) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Bearer list unavailable");
return FALSE;
}
if (flags & MM_IFACE_MODEM_COUNT_BEARERS_FLAG_MULTIPLEXED)
max = mm_bearer_list_get_max_active_multiplexed (list);
else
max = mm_bearer_list_get_max_active (list);
mm_bearer_list_foreach (list, (MMBearerListForeachFunc)bearer_count, &ctx);
g_assert (max >= ctx.count);
if (out_max)
*out_max = max;
if (out_current)
*out_current = ctx.count;
return TRUE;
}
/*****************************************************************************/
static void
mm_iface_modem_default_init (MMIfaceModemInterface *iface)
{
+15
View File
@@ -622,4 +622,19 @@ void mm_iface_modem_process_sim_event (MMIfaceModem *self);
gboolean mm_iface_modem_is_primary_sim_slot_switch_ongoing (MMIfaceModem *self);
typedef enum {
/* Connecting or connected bearers */
MM_IFACE_MODEM_COUNT_BEARERS_FLAG_ACTIVE = 0x1,
/* Fully connected bearers */
MM_IFACE_MODEM_COUNT_BEARERS_FLAG_CONNECTED = 0x2,
/* Multiplexed implies connected */
MM_IFACE_MODEM_COUNT_BEARERS_FLAG_MULTIPLEXED = 0x4,
} MMIfaceModemCountBearersFlags;
gboolean mm_iface_modem_count_bearers (MMIfaceModem *self,
MMIfaceModemCountBearersFlags flags,
guint *out_current,
guint *out_max,
GError **error);
#endif /* MM_IFACE_MODEM_H */