diff options
-rw-r--r-- | plugins/Makefile.am | 2 | ||||
-rw-r--r-- | plugins/ublox/mm-broadband-modem-ublox.c | 191 | ||||
-rw-r--r-- | plugins/ublox/mm-call-ublox.c | 194 | ||||
-rw-r--r-- | plugins/ublox/mm-call-ublox.h | 50 |
4 files changed, 187 insertions, 250 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 4bd63179..57cd6bd6 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1029,8 +1029,6 @@ pkglib_LTLIBRARIES += libmm-plugin-ublox.la libmm_plugin_ublox_la_SOURCES = \ ublox/mm-plugin-ublox.c \ ublox/mm-plugin-ublox.h \ - ublox/mm-call-ublox.c \ - ublox/mm-call-ublox.h \ ublox/mm-broadband-bearer-ublox.h \ ublox/mm-broadband-bearer-ublox.c \ ublox/mm-broadband-modem-ublox.h \ diff --git a/plugins/ublox/mm-broadband-modem-ublox.c b/plugins/ublox/mm-broadband-modem-ublox.c index 75e1a401..509c4c6d 100644 --- a/plugins/ublox/mm-broadband-modem-ublox.c +++ b/plugins/ublox/mm-broadband-modem-ublox.c @@ -10,7 +10,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * - * Copyright (C) 2016-2018 Aleksander Morgado <aleksander@aleksander.es> + * Copyright (C) 2016-2019 Aleksander Morgado <aleksander@aleksander.es> */ #include <config.h> @@ -33,7 +33,6 @@ #include "mm-sim-ublox.h" #include "mm-modem-helpers-ublox.h" #include "mm-ublox-enums-types.h" -#include "mm-call-ublox.h" static void iface_modem_init (MMIfaceModem *iface); static void iface_modem_3gpp_init (MMIfaceModem3gpp *iface); @@ -67,6 +66,9 @@ struct _MMBroadbandModemUbloxPrivate { /* Operator ID for manual registration */ gchar *operator_id; + /* Voice +UCALLSTAT support */ + GRegex *ucallstat_regex; + /* Regex to ignore */ GRegex *pbready_regex; }; @@ -1064,6 +1066,177 @@ modem_voice_disable_unsolicited_events (MMIfaceModemVoice *self, } /*****************************************************************************/ +/* Common setup/cleanup voice unsolicited events */ + +static void +ucallstat_received (MMPortSerialAt *port, + GMatchInfo *match_info, + MMBroadbandModemUblox *self) +{ + static const MMCallState ublox_call_state[] = { + [0] = MM_CALL_STATE_ACTIVE, + [1] = MM_CALL_STATE_HELD, + [2] = MM_CALL_STATE_DIALING, /* Dialing (MOC) */ + [3] = MM_CALL_STATE_RINGING_OUT, /* Alerting (MOC) */ + [4] = MM_CALL_STATE_RINGING_IN, /* Incoming (MTC) */ + [5] = MM_CALL_STATE_WAITING, /* Waiting (MTC) */ + [6] = MM_CALL_STATE_TERMINATED, + [7] = MM_CALL_STATE_ACTIVE, /* Treated same way as ACTIVE */ + }; + + MMCallInfo call_info = { 0 }; + guint aux; + + if (!mm_get_uint_from_match_info (match_info, 1, &aux)) { + mm_warn ("couldn't parse call index from +UCALLSTAT"); + return; + } + call_info.index = aux; + + if (!mm_get_uint_from_match_info (match_info, 2, &aux) || + (aux >= G_N_ELEMENTS (ublox_call_state))) { + mm_warn ("couldn't parse call state from +UCALLSTAT"); + return; + } + call_info.state = ublox_call_state[aux]; + + /* guess direction for some of the states */ + switch (call_info.state) { + case MM_CALL_STATE_DIALING: + case MM_CALL_STATE_RINGING_OUT: + call_info.direction = MM_CALL_DIRECTION_OUTGOING; + break; + case MM_CALL_STATE_RINGING_IN: + case MM_CALL_STATE_WAITING: + call_info.direction = MM_CALL_DIRECTION_INCOMING; + break; + default: + call_info.direction = MM_CALL_DIRECTION_UNKNOWN; + break; + } + + mm_iface_modem_voice_report_call (MM_IFACE_MODEM_VOICE (self), &call_info); +} + +static void +common_voice_setup_cleanup_unsolicited_events (MMBroadbandModemUblox *self, + gboolean enable) +{ + MMPortSerialAt *ports[2]; + guint i; + + if (G_UNLIKELY (!self->priv->ucallstat_regex)) + self->priv->ucallstat_regex = g_regex_new ("\\r\\n\\+UCALLSTAT:\\s*(\\d+),(\\d+)\\r\\n", + G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + + ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); + ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); + + for (i = 0; i < G_N_ELEMENTS (ports); i++) { + if (!ports[i]) + continue; + + mm_port_serial_at_add_unsolicited_msg_handler (ports[i], + self->priv->ucallstat_regex, + enable ? (MMPortSerialAtUnsolicitedMsgFn)ucallstat_received : NULL, + enable ? self : NULL, + NULL); + } +} + +/*****************************************************************************/ +/* Cleanup unsolicited events (Voice interface) */ + +static gboolean +modem_voice_cleanup_unsolicited_events_finish (MMIfaceModemVoice *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +parent_voice_cleanup_unsolicited_events_ready (MMIfaceModemVoice *self, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + + if (!iface_modem_voice_parent->cleanup_unsolicited_events_finish (self, res, &error)) { + mm_warn ("Couldn't cleanup parent voice unsolicited events: %s", error->message); + g_error_free (error); + } + + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +static void +modem_voice_cleanup_unsolicited_events (MMIfaceModemVoice *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + + task = g_task_new (self, NULL, callback, user_data); + + /* our own cleanup first */ + common_voice_setup_cleanup_unsolicited_events (MM_BROADBAND_MODEM_UBLOX (self), FALSE); + + /* Chain up parent's cleanup */ + iface_modem_voice_parent->cleanup_unsolicited_events ( + self, + (GAsyncReadyCallback)parent_voice_cleanup_unsolicited_events_ready, + task); +} + +/*****************************************************************************/ +/* Setup unsolicited events (Voice interface) */ + +static gboolean +modem_voice_setup_unsolicited_events_finish (MMIfaceModemVoice *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +parent_voice_setup_unsolicited_events_ready (MMIfaceModemVoice *self, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + + if (!iface_modem_voice_parent->cleanup_unsolicited_events_finish (self, res, &error)) { + mm_warn ("Couldn't cleanup parent voice unsolicited events: %s", error->message); + g_error_free (error); + } + + /* our own setup next */ + common_voice_setup_cleanup_unsolicited_events (MM_BROADBAND_MODEM_UBLOX (self), TRUE); + + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +static void +modem_voice_setup_unsolicited_events (MMIfaceModemVoice *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + + task = g_task_new (self, NULL, callback, user_data); + + /* chain up parent's setup first */ + iface_modem_voice_parent->setup_unsolicited_events ( + self, + (GAsyncReadyCallback)parent_voice_setup_unsolicited_events_ready, + task); +} + +/*****************************************************************************/ /* Create call (Voice interface) */ static MMBaseCall * @@ -1071,8 +1244,12 @@ create_call (MMIfaceModemVoice *self, MMCallDirection direction, const gchar *number) { - /* New u-blox Call */ - return mm_call_ublox_new (MM_BASE_MODEM (self), direction, number); + return mm_base_call_new (MM_BASE_MODEM (self), + direction, + number, + TRUE, /* skip_incoming_timeout */ + TRUE, /* supports_dialing_to_ringing */ + TRUE); /* supports_ringing_to_active */ } /*****************************************************************************/ @@ -1466,6 +1643,10 @@ iface_modem_voice_init (MMIfaceModemVoice *iface) { iface_modem_voice_parent = g_type_interface_peek_parent (iface); + iface->setup_unsolicited_events = modem_voice_setup_unsolicited_events; + iface->setup_unsolicited_events_finish = modem_voice_setup_unsolicited_events_finish; + iface->cleanup_unsolicited_events = modem_voice_cleanup_unsolicited_events; + iface->cleanup_unsolicited_events_finish = modem_voice_cleanup_unsolicited_events_finish; iface->enable_unsolicited_events = modem_voice_enable_unsolicited_events; iface->enable_unsolicited_events_finish = modem_voice_enable_unsolicited_events_finish; iface->disable_unsolicited_events = modem_voice_disable_unsolicited_events; @@ -1481,6 +1662,8 @@ finalize (GObject *object) g_regex_unref (self->priv->pbready_regex); + if (self->priv->ucallstat_regex) + g_regex_unref (self->priv->ucallstat_regex); g_free (self->priv->operator_id); G_OBJECT_CLASS (mm_broadband_modem_ublox_parent_class)->finalize (object); diff --git a/plugins/ublox/mm-call-ublox.c b/plugins/ublox/mm-call-ublox.c deleted file mode 100644 index f9011fa0..00000000 --- a/plugins/ublox/mm-call-ublox.c +++ /dev/null @@ -1,194 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details: - * - * Copyright (C) 2018 Aleksander Morgado <aleksander@aleksander.es> - */ - -#include <config.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <ctype.h> - -#include <ModemManager.h> -#define _LIBMM_INSIDE_MM -#include <libmm-glib.h> - -#include "mm-log.h" -#include "mm-base-modem-at.h" -#include "mm-broadband-modem-ublox.h" -#include "mm-call-ublox.h" - -G_DEFINE_TYPE (MMCallUblox, mm_call_ublox, MM_TYPE_BASE_CALL) - -struct _MMCallUbloxPrivate { - GRegex *ucallstat_regex; -}; - -/*****************************************************************************/ -/* In-call unsolicited events */ - -static void -ublox_ucallstat_received (MMPortSerialAt *port, - GMatchInfo *match_info, - MMCallUblox *self) -{ - static const gchar *call_stat_names[] = { - [0] = "active", - [1] = "hold", - [2] = "dialling (MO)", - [3] = "alerting (MO)", - [4] = "ringing (MT)", - [5] = "waiting (MT)", - [6] = "disconnected", - [7] = "connected", - }; - guint id; - guint stat; - - if (!mm_get_uint_from_match_info (match_info, 1, &id)) - return; - - if (!mm_get_uint_from_match_info (match_info, 2, &stat)) - return; - - if (stat < G_N_ELEMENTS (call_stat_names)) - mm_dbg ("u-blox call id '%u' state: '%s'", id, call_stat_names[stat]); - else - mm_dbg ("u-blox call id '%u' state unknown: '%u'", id, stat); - - switch (stat) { - case 0: - /* ringing to active */ - if (mm_gdbus_call_get_state (MM_GDBUS_CALL (self)) == MM_CALL_STATE_RINGING_OUT) - mm_base_call_change_state (MM_BASE_CALL (self), MM_CALL_STATE_ACTIVE, MM_CALL_STATE_REASON_ACCEPTED); - break; - case 1: - /* ignore hold state, we don't support this yet. */ - break; - case 2: - /* ignore dialing state, we already handle this in the parent */ - break; - case 3: - /* dialing to ringing */ - if (mm_gdbus_call_get_state (MM_GDBUS_CALL (self)) == MM_CALL_STATE_DIALING) - mm_base_call_change_state (MM_BASE_CALL (self), MM_CALL_STATE_RINGING_OUT, MM_CALL_STATE_REASON_OUTGOING_STARTED); - break; - case 4: - /* ignore MT ringing state, we already handle this in the parent */ - break; - case 5: - /* ignore MT waiting state */ - break; - case 6: - mm_base_call_change_state (MM_BASE_CALL (self), MM_CALL_STATE_TERMINATED, MM_CALL_STATE_REASON_TERMINATED); - break; - case 7: - /* ringing to active */ - if (mm_gdbus_call_get_state (MM_GDBUS_CALL (self)) == MM_CALL_STATE_RINGING_OUT) - mm_base_call_change_state (MM_BASE_CALL (self), MM_CALL_STATE_ACTIVE, MM_CALL_STATE_REASON_ACCEPTED); - break; - } -} - -static gboolean -common_setup_cleanup_unsolicited_events (MMCallUblox *self, - gboolean enable, - GError **error) -{ - MMBaseModem *modem = NULL; - MMPortSerialAt *port; - - if (G_UNLIKELY (!self->priv->ucallstat_regex)) - self->priv->ucallstat_regex = g_regex_new ("\\r\\n\\+UCALLSTAT:\\s*(\\d+),(\\d+)\\r\\n", - G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - - g_object_get (self, - MM_BASE_CALL_MODEM, &modem, - NULL); - - port = mm_base_modem_peek_port_primary (MM_BASE_MODEM (modem)); - if (port) { - mm_dbg ("%s +UCALLSTAT URC handler", enable ? "adding" : "removing"); - mm_port_serial_at_add_unsolicited_msg_handler ( - port, - self->priv->ucallstat_regex, - enable ? (MMPortSerialAtUnsolicitedMsgFn)ublox_ucallstat_received : NULL, - enable ? self : NULL, - NULL); - } - - g_object_unref (modem); - return TRUE; -} - -static gboolean -setup_unsolicited_events (MMBaseCall *self, - GError **error) -{ - return common_setup_cleanup_unsolicited_events (MM_CALL_UBLOX (self), TRUE, error); -} - -static gboolean -cleanup_unsolicited_events (MMBaseCall *self, - GError **error) -{ - return common_setup_cleanup_unsolicited_events (MM_CALL_UBLOX (self), FALSE, error); -} - -/*****************************************************************************/ - -MMBaseCall * -mm_call_ublox_new (MMBaseModem *modem, - MMCallDirection direction, - const gchar *number) -{ - return MM_BASE_CALL (g_object_new (MM_TYPE_CALL_UBLOX, - MM_BASE_CALL_MODEM, modem, - "direction", direction, - "number", number, - MM_BASE_CALL_SUPPORTS_DIALING_TO_RINGING, TRUE, - MM_BASE_CALL_SUPPORTS_RINGING_TO_ACTIVE, TRUE, - NULL)); -} - -static void -mm_call_ublox_init (MMCallUblox *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MM_TYPE_CALL_UBLOX, MMCallUbloxPrivate); -} - -static void -finalize (GObject *object) -{ - MMCallUblox *self = MM_CALL_UBLOX (object); - - if (self->priv->ucallstat_regex) - g_regex_unref (self->priv->ucallstat_regex); - - G_OBJECT_CLASS (mm_call_ublox_parent_class)->finalize (object); -} - -static void -mm_call_ublox_class_init (MMCallUbloxClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MMBaseCallClass *base_call_class = MM_BASE_CALL_CLASS (klass); - - g_type_class_add_private (object_class, sizeof (MMCallUbloxPrivate)); - - object_class->finalize = finalize; - - base_call_class->setup_unsolicited_events = setup_unsolicited_events; - base_call_class->cleanup_unsolicited_events = cleanup_unsolicited_events; -} diff --git a/plugins/ublox/mm-call-ublox.h b/plugins/ublox/mm-call-ublox.h deleted file mode 100644 index abacb50e..00000000 --- a/plugins/ublox/mm-call-ublox.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details: - * - * Copyright (C) 2018 Aleksander Morgado <aleksander@aleksander.es> - */ - -#ifndef MM_CALL_UBLOX_H -#define MM_CALL_UBLOX_H - -#include <glib.h> -#include <glib-object.h> - -#include "mm-base-call.h" - -#define MM_TYPE_CALL_UBLOX (mm_call_ublox_get_type ()) -#define MM_CALL_UBLOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_CALL_UBLOX, MMCallUblox)) -#define MM_CALL_UBLOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_CALL_UBLOX, MMCallUbloxClass)) -#define MM_IS_CALL_UBLOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_CALL_UBLOX)) -#define MM_IS_CALL_UBLOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_CALL_UBLOX)) -#define MM_CALL_UBLOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_CALL_UBLOX, MMCallUbloxClass)) - -typedef struct _MMCallUblox MMCallUblox; -typedef struct _MMCallUbloxClass MMCallUbloxClass; -typedef struct _MMCallUbloxPrivate MMCallUbloxPrivate; - -struct _MMCallUblox { - MMBaseCall parent; - MMCallUbloxPrivate *priv; -}; - -struct _MMCallUbloxClass { - MMBaseCallClass parent; -}; - -GType mm_call_ublox_get_type (void); - -MMBaseCall *mm_call_ublox_new (MMBaseModem *modem, - MMCallDirection direction, - const gchar *number); - -#endif /* MM_CALL_UBLOX_H */ |