diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-07-03 15:05:14 +0200 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2018-10-16 17:09:21 +0000 |
commit | 16162a5033593e017775eab640a3b9bf1b805c39 (patch) | |
tree | 6c8516ebc4ceb135e5e4930f2183200c102a66a8 | |
parent | 89218a087499a6f5a39fe1a71a66241c28432357 (diff) |
ublox: implement detailed call state transitions with +UCALLSTAT
Among other things, we now support:
* Dialing to Ringing Out transition.
* Ringing Out to Active transition.
-rw-r--r-- | plugins/Makefile.am | 2 | ||||
-rw-r--r-- | plugins/ublox/mm-broadband-modem-ublox.c | 152 | ||||
-rw-r--r-- | plugins/ublox/mm-call-ublox.c | 194 | ||||
-rw-r--r-- | plugins/ublox/mm-call-ublox.h | 50 |
4 files changed, 396 insertions, 2 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 350dca1f..df991288 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1016,6 +1016,8 @@ 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 79688b2f..83352fa8 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 Aleksander Morgado <aleksander@aleksander.es> + * Copyright (C) 2016-2018 Aleksander Morgado <aleksander@aleksander.es> */ #include <config.h> @@ -25,6 +25,7 @@ #include "mm-log.h" #include "mm-iface-modem.h" #include "mm-iface-modem-3gpp.h" +#include "mm-iface-modem-voice.h" #include "mm-base-modem-at.h" #include "mm-broadband-bearer.h" #include "mm-broadband-modem-ublox.h" @@ -32,11 +33,16 @@ #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_voice_init (MMIfaceModemVoice *iface); + +static MMIfaceModemVoice *iface_modem_voice_parent; G_DEFINE_TYPE_EXTENDED (MMBroadbandModemUblox, mm_broadband_modem_ublox, MM_TYPE_BROADBAND_MODEM, 0, - G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init)) + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_VOICE, iface_modem_voice_init)) typedef enum { FEATURE_SUPPORT_UNKNOWN, @@ -745,6 +751,135 @@ load_unlock_retries (MMIfaceModem *self, } /*****************************************************************************/ +/* Enabling unsolicited events (Voice interface) */ + +static gboolean +modem_voice_enable_unsolicited_events_finish (MMIfaceModemVoice *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +own_voice_enable_unsolicited_events_ready (MMBaseModem *self, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + + mm_base_modem_at_command_full_finish (self, res, &error); + if (error) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +static void +parent_voice_enable_unsolicited_events_ready (MMIfaceModemVoice *self, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + + if (!iface_modem_voice_parent->enable_unsolicited_events_finish (self, res, &error)) { + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + /* Our own enable now */ + mm_base_modem_at_command_full ( + MM_BASE_MODEM (self), + mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), + "+UCALLSTAT=1", + 5, + FALSE, /* allow_cached */ + FALSE, /* raw */ + NULL, /* cancellable */ + (GAsyncReadyCallback)own_voice_enable_unsolicited_events_ready, + task); +} + +static void +modem_voice_enable_unsolicited_events (MMIfaceModemVoice *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + + task = g_task_new (self, NULL, callback, user_data); + + /* Chain up parent's enable */ + iface_modem_voice_parent->enable_unsolicited_events ( + self, + (GAsyncReadyCallback)parent_voice_enable_unsolicited_events_ready, + task); +} + +/*****************************************************************************/ +/* Disabling unsolicited events (Voice interface) */ + +static gboolean +modem_voice_disable_unsolicited_events_finish (MMIfaceModemVoice *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +own_voice_disable_unsolicited_events_ready (MMBaseModem *self, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + + mm_base_modem_at_command_full_finish (self, res, &error); + if (error) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +static void +modem_voice_disable_unsolicited_events (MMIfaceModemVoice *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + + task = g_task_new (self, NULL, callback, user_data); + + /* Note: no parent disable method */ + + mm_base_modem_at_command_full ( + MM_BASE_MODEM (self), + mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), + "+UCALLSTAT=0", + 5, + FALSE, /* allow_cached */ + FALSE, /* raw */ + NULL, /* cancellable */ + (GAsyncReadyCallback)own_voice_disable_unsolicited_events_ready, + task); +} + +/*****************************************************************************/ +/* Create call (Voice interface) */ + +static MMBaseCall * +create_call (MMIfaceModemVoice *self, + MMCallDirection direction, + const gchar *number) +{ + /* New u-blox Call */ + return mm_call_ublox_new (MM_BASE_MODEM (self), direction, number); +} + +/*****************************************************************************/ /* Create Bearer (Modem interface) */ typedef enum { @@ -1122,6 +1257,19 @@ iface_modem_init (MMIfaceModem *iface) } static void +iface_modem_voice_init (MMIfaceModemVoice *iface) +{ + iface_modem_voice_parent = g_type_interface_peek_parent (iface); + + 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; + iface->disable_unsolicited_events_finish = modem_voice_disable_unsolicited_events_finish; + + iface->create_call = create_call; +} + +static void finalize (GObject *object) { MMBroadbandModemUblox *self = MM_BROADBAND_MODEM_UBLOX (object); diff --git a/plugins/ublox/mm-call-ublox.c b/plugins/ublox/mm-call-ublox.c new file mode 100644 index 00000000..f9011fa0 --- /dev/null +++ b/plugins/ublox/mm-call-ublox.c @@ -0,0 +1,194 @@ +/* -*- 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 new file mode 100644 index 00000000..abacb50e --- /dev/null +++ b/plugins/ublox/mm-call-ublox.h @@ -0,0 +1,50 @@ +/* -*- 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 */ |