aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--introspection/mm-modem-gsm-sms.xml18
-rw-r--r--src/Makefile.am8
-rw-r--r--src/mm-generic-gsm.c52
-rw-r--r--src/mm-modem-gsm-sms.c298
-rw-r--r--src/mm-modem-gsm-sms.h45
-rwxr-xr-xtest/mm-send-sms.py39
6 files changed, 459 insertions, 1 deletions
diff --git a/introspection/mm-modem-gsm-sms.xml b/introspection/mm-modem-gsm-sms.xml
index 69bf7351..a9d0d575 100644
--- a/introspection/mm-modem-gsm-sms.xml
+++ b/introspection/mm-modem-gsm-sms.xml
@@ -30,26 +30,38 @@
</method>
<method name="GetFormat">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_sms_get_format"/>
<arg name="result" type="u" direction="out"/>
</method>
<method name="SetFormat">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_sms_set_format"/>
<arg name="format" type="u" direction="in"/>
</method>
<method name="GetSmsc">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_sms_get_smsc"/>
<arg name="result" type="s" direction="out"/>
</method>
<method name="SetSmsc">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_sms_set_smsc"/>
<arg name="smsc" type="s" direction="in"/>
</method>
<method name="List">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_sms_list"/>
<arg name="result" type="aa{sv}" direction="out"/>
</method>
<method name="Save">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_sms_save"/>
<arg name="properties" type="a{sv}" direction="in">
<tp:docstring>
SMS properties to save with the following key values:
@@ -65,6 +77,8 @@
</method>
<method name="Send">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_sms_send"/>
<arg name="properties" type="a{sv}" direction="in">
<tp:docstring>
SMS properties to save with the following key values:
@@ -80,10 +94,14 @@
</method>
<method name="SendFromStorage">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_sms_send_from_storage"/>
<arg name="index" type="u" direction="in"/>
</method>
<method name="SetIndication">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_sms_set_indication"/>
<arg name="mode" type="u" direction="in"/>
<arg name="mt" type="u" direction="in"/>
<arg name="bm" type="u" direction="in"/>
diff --git a/src/Makefile.am b/src/Makefile.am
index caafef8b..d6d4e73f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,6 +29,8 @@ modem_manager_SOURCES = \
mm-modem-gsm-card.h \
mm-modem-gsm-network.c \
mm-modem-gsm-network.h \
+ mm-modem-gsm-sms.c \
+ mm-modem-gsm-sms.h \
mm-modem-simple.c \
mm-modem-simple.h \
mm-options.c \
@@ -58,6 +60,9 @@ mm-modem-gsm-card-glue.h: $(top_srcdir)/introspection/mm-modem-gsm-card.xml
mm-modem-gsm-network-glue.h: $(top_srcdir)/introspection/mm-modem-gsm-network.xml
dbus-binding-tool --prefix=mm_modem_gsm_network --mode=glib-server --output=$@ $<
+mm-modem-gsm-sms-glue.h: $(top_srcdir)/introspection/mm-modem-gsm-sms.xml
+ dbus-binding-tool --prefix=mm_modem_gsm_sms --mode=glib-server --output=$@ $<
+
BUILT_SOURCES = \
mm-manager-glue.h \
@@ -65,6 +70,7 @@ BUILT_SOURCES = \
mm-modem-simple-glue.h \
mm-modem-cdma-glue.h \
mm-modem-gsm-card-glue.h \
- mm-modem-gsm-network-glue.h
+ mm-modem-gsm-network-glue.h \
+ mm-modem-gsm-sms-glue.h
CLEANFILES = $(BUILT_SOURCES)
diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c
index 250b8cf6..4520b8eb 100644
--- a/src/mm-generic-gsm.c
+++ b/src/mm-generic-gsm.c
@@ -6,6 +6,7 @@
#include "mm-generic-gsm.h"
#include "mm-modem-gsm-card.h"
#include "mm-modem-gsm-network.h"
+#include "mm-modem-gsm-sms.h"
#include "mm-modem-simple.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
@@ -1153,6 +1154,46 @@ get_signal_quality (MMModemGsmNetwork *modem,
}
/*****************************************************************************/
+/* MMModemGsmSms interface */
+
+static void
+sms_send_done (MMSerial *serial,
+ GString *response,
+ GError *error,
+ gpointer user_data)
+{
+ MMCallbackInfo *info = (MMCallbackInfo *) user_data;
+
+ if (error)
+ info->error = g_error_copy (error);
+
+ mm_callback_info_schedule (info);
+}
+
+static void
+sms_send (MMModemGsmSms *modem,
+ const char *number,
+ const char *text,
+ const char *smsc,
+ guint validity,
+ guint class,
+ MMModemFn callback,
+ gpointer user_data)
+{
+ MMCallbackInfo *info;
+ char *command;
+
+ info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
+
+ /* FIXME: use the PDU mode instead */
+ mm_serial_queue_command (MM_SERIAL (modem), "AT+CMGF=1", 3, NULL, NULL);
+
+ command = g_strdup_printf ("+CMGS=\"%s\"\r%s\x1a", number, text);
+ mm_serial_queue_command (MM_SERIAL (modem), command, 10, sms_send_done, info);
+ g_free (command);
+}
+
+/*****************************************************************************/
/* MMModemSimple interface */
typedef enum {
@@ -1427,6 +1468,12 @@ modem_gsm_network_init (MMModemGsmNetwork *class)
}
static void
+modem_gsm_sms_init (MMModemGsmSms *class)
+{
+ class->send = sms_send;
+}
+
+static void
modem_simple_init (MMModemSimple *class)
{
class->connect = simple_connect;
@@ -1580,6 +1627,10 @@ mm_generic_gsm_get_type (void)
(GInterfaceInitFunc) modem_gsm_network_init
};
+ static const GInterfaceInfo modem_gsm_sms_info = {
+ (GInterfaceInitFunc) modem_gsm_sms_init
+ };
+
static const GInterfaceInfo modem_simple_info = {
(GInterfaceInitFunc) modem_simple_init
};
@@ -1589,6 +1640,7 @@ mm_generic_gsm_get_type (void)
g_type_add_interface_static (generic_gsm_type, MM_TYPE_MODEM, &modem_iface_info);
g_type_add_interface_static (generic_gsm_type, MM_TYPE_MODEM_GSM_CARD, &modem_gsm_card_info);
g_type_add_interface_static (generic_gsm_type, MM_TYPE_MODEM_GSM_NETWORK, &modem_gsm_network_info);
+ g_type_add_interface_static (generic_gsm_type, MM_TYPE_MODEM_GSM_SMS, &modem_gsm_sms_info);
g_type_add_interface_static (generic_gsm_type, MM_TYPE_MODEM_SIMPLE, &modem_simple_info);
}
diff --git a/src/mm-modem-gsm-sms.c b/src/mm-modem-gsm-sms.c
new file mode 100644
index 00000000..d93f727d
--- /dev/null
+++ b/src/mm-modem-gsm-sms.c
@@ -0,0 +1,298 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+#include <string.h>
+#include <dbus/dbus-glib.h>
+
+#include "mm-modem-gsm-sms.h"
+#include "mm-errors.h"
+#include "mm-callback-info.h"
+#include "mm-marshal.h"
+
+static void impl_gsm_modem_sms_delete (MMModemGsmSms *modem,
+ guint idx,
+ DBusGMethodInvocation *context);
+
+static void impl_gsm_modem_sms_get (MMModemGsmSms *modem,
+ guint idx,
+ DBusGMethodInvocation *context);
+
+static void impl_gsm_modem_sms_get_format (MMModemGsmSms *modem,
+ DBusGMethodInvocation *context);
+
+static void impl_gsm_modem_sms_set_format (MMModemGsmSms *modem,
+ guint format,
+ DBusGMethodInvocation *context);
+
+static void impl_gsm_modem_sms_get_smsc (MMModemGsmSms *modem,
+ DBusGMethodInvocation *context);
+
+static void impl_gsm_modem_sms_set_smsc (MMModemGsmSms *modem,
+ const char *smsc,
+ DBusGMethodInvocation *context);
+
+static void impl_gsm_modem_sms_list (MMModemGsmSms *modem,
+ DBusGMethodInvocation *context);
+
+static void impl_gsm_modem_sms_save (MMModemGsmSms *modem,
+ GHashTable *properties,
+ DBusGMethodInvocation *context);
+
+static void impl_gsm_modem_sms_send (MMModemGsmSms *modem,
+ GHashTable *properties,
+ DBusGMethodInvocation *context);
+
+static void impl_gsm_modem_sms_send_from_storage (MMModemGsmSms *modem,
+ guint idx,
+ DBusGMethodInvocation *context);
+
+static void impl_gsm_modem_sms_set_indication (MMModemGsmSms *modem,
+ guint mode,
+ guint mt,
+ guint bm,
+ guint ds,
+ guint bfr,
+ DBusGMethodInvocation *context);
+
+#include "mm-modem-gsm-sms-glue.h"
+
+enum {
+ SMS_RECEIVED,
+
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+/*****************************************************************************/
+
+static void
+async_call_done (MMModem *modem, GError *error, gpointer user_data)
+{
+ DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
+
+ if (error)
+ dbus_g_method_return_error (context, error);
+ else
+ dbus_g_method_return (context);
+}
+
+static void
+async_call_not_supported (MMModemGsmSms *self,
+ MMModemFn callback,
+ gpointer user_data)
+{
+ MMCallbackInfo *info;
+
+ info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
+ info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
+ "Operation not supported");
+ mm_callback_info_schedule (info);
+}
+
+/*****************************************************************************/
+
+void
+mm_modem_gsm_sms_send (MMModemGsmSms *self,
+ const char *number,
+ const char *text,
+ const char *smsc,
+ guint validity,
+ guint class,
+ MMModemFn callback,
+ gpointer user_data)
+{
+ g_return_if_fail (MM_IS_MODEM_GSM_SMS (self));
+ g_return_if_fail (number != NULL);
+ g_return_if_fail (text != NULL);
+ g_return_if_fail (callback != NULL);
+
+ if (MM_MODEM_GSM_SMS_GET_INTERFACE (self)->send)
+ MM_MODEM_GSM_SMS_GET_INTERFACE (self)->send (self, number, text, smsc, validity, class, callback, user_data);
+ else
+ async_call_not_supported (self, callback, user_data);
+
+}
+
+/*****************************************************************************/
+
+static void
+impl_gsm_modem_sms_delete (MMModemGsmSms *modem,
+ guint idx,
+ DBusGMethodInvocation *context)
+{
+ async_call_not_supported (modem, async_call_done, context);
+}
+
+static void
+impl_gsm_modem_sms_get (MMModemGsmSms *modem,
+ guint idx,
+ DBusGMethodInvocation *context)
+{
+ async_call_not_supported (modem, async_call_done, context);
+}
+
+static void
+impl_gsm_modem_sms_get_format (MMModemGsmSms *modem,
+ DBusGMethodInvocation *context)
+{
+ async_call_not_supported (modem, async_call_done, context);
+}
+
+static void
+impl_gsm_modem_sms_set_format (MMModemGsmSms *modem,
+ guint format,
+ DBusGMethodInvocation *context)
+{
+ async_call_not_supported (modem, async_call_done, context);
+}
+
+static void
+impl_gsm_modem_sms_get_smsc (MMModemGsmSms *modem,
+ DBusGMethodInvocation *context)
+{
+ async_call_not_supported (modem, async_call_done, context);
+}
+
+static void
+impl_gsm_modem_sms_set_smsc (MMModemGsmSms *modem,
+ const char *smsc,
+ DBusGMethodInvocation *context)
+{
+ async_call_not_supported (modem, async_call_done, context);
+}
+
+static void
+impl_gsm_modem_sms_list (MMModemGsmSms *modem,
+ DBusGMethodInvocation *context)
+{
+ async_call_not_supported (modem, async_call_done, context);
+}
+
+static void
+impl_gsm_modem_sms_save (MMModemGsmSms *modem,
+ GHashTable *properties,
+ DBusGMethodInvocation *context)
+{
+ async_call_not_supported (modem, async_call_done, context);
+}
+
+static void
+impl_gsm_modem_sms_send (MMModemGsmSms *modem,
+ GHashTable *properties,
+ DBusGMethodInvocation *context)
+{
+ GValue *value;
+ const char *number;
+ const char *text;
+ const char *smsc;
+ GError *error = NULL;
+ guint validity;
+ guint class;
+
+ value = (GValue *) g_hash_table_lookup (properties, "number");
+ if (value)
+ number = g_value_get_string (value);
+
+ value = (GValue *) g_hash_table_lookup (properties, "text");
+ if (value)
+ text = g_value_get_string (value);
+
+ value = (GValue *) g_hash_table_lookup (properties, "smsc");
+ if (value)
+ smsc = g_value_get_string (value);
+
+ value = (GValue *) g_hash_table_lookup (properties, "validity");
+ if (value)
+ validity = g_value_get_uint (value);
+
+ value = (GValue *) g_hash_table_lookup (properties, "class");
+ if (value)
+ class = g_value_get_uint (value);
+
+ if (!number)
+ error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
+ "Missing number");
+ else if (!text)
+ error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
+ "Missing message text");
+
+ if (error) {
+ async_call_done (MM_MODEM (modem), error, context);
+ g_error_free (error);
+ } else
+ mm_modem_gsm_sms_send (modem, number, text, smsc, validity, class, async_call_done, context);
+}
+
+static void
+impl_gsm_modem_sms_send_from_storage (MMModemGsmSms *modem,
+ guint idx,
+ DBusGMethodInvocation *context)
+{
+ async_call_not_supported (modem, async_call_done, context);
+}
+
+static void
+impl_gsm_modem_sms_set_indication (MMModemGsmSms *modem,
+ guint mode,
+ guint mt,
+ guint bm,
+ guint ds,
+ guint bfr,
+ DBusGMethodInvocation *context)
+{
+ async_call_not_supported (modem, async_call_done, context);
+}
+
+/*****************************************************************************/
+
+static void
+mm_modem_gsm_sms_init (gpointer g_iface)
+{
+ GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
+ static gboolean initialized = FALSE;
+
+ if (initialized)
+ return;
+
+ /* Signals */
+ signals[SMS_RECEIVED] =
+ g_signal_new ("sms-received",
+ iface_type,
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (MMModemGsmSms, sms_received),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1,
+ G_TYPE_UINT);
+
+ initialized = TRUE;
+}
+
+GType
+mm_modem_gsm_sms_get_type (void)
+{
+ static GType sms_type = 0;
+
+ if (!G_UNLIKELY (sms_type)) {
+ const GTypeInfo sms_info = {
+ sizeof (MMModemGsmSms), /* class_size */
+ mm_modem_gsm_sms_init, /* base_init */
+ NULL, /* base_finalize */
+ NULL,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ 0,
+ 0, /* n_preallocs */
+ NULL
+ };
+
+ sms_type = g_type_register_static (G_TYPE_INTERFACE,
+ "MMModemGsmSms",
+ &sms_info, 0);
+
+ g_type_interface_add_prerequisite (sms_type, G_TYPE_OBJECT);
+ dbus_g_object_type_install_info (sms_type, &dbus_glib_mm_modem_gsm_sms_object_info);
+ }
+
+ return sms_type;
+}
diff --git a/src/mm-modem-gsm-sms.h b/src/mm-modem-gsm-sms.h
new file mode 100644
index 00000000..24630ba7
--- /dev/null
+++ b/src/mm-modem-gsm-sms.h
@@ -0,0 +1,45 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+#ifndef MM_MODEM_GSM_SMS_H
+#define MM_MODEM_GSM_SMS_H
+
+#include <mm-modem.h>
+
+#define MM_TYPE_MODEM_GSM_SMS (mm_modem_gsm_sms_get_type ())
+#define MM_MODEM_GSM_SMS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_GSM_SMS, MMModemGsmSms))
+#define MM_IS_MODEM_GSM_SMS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_GSM_SMS))
+#define MM_MODEM_GSM_SMS_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM_GSM_SMS, MMModemGsmSms))
+
+typedef struct _MMModemGsmSms MMModemGsmSms;
+
+struct _MMModemGsmSms {
+ GTypeInterface g_iface;
+
+ /* Methods */
+ void (*send) (MMModemGsmSms *modem,
+ const char *number,
+ const char *text,
+ const char *smsc,
+ guint validity,
+ guint class,
+ MMModemFn callback,
+ gpointer user_data);
+
+ /* Signals */
+ void (*sms_received) (MMModemGsmSms *self,
+ guint32 index);
+
+};
+
+GType mm_modem_gsm_sms_get_type (void);
+
+void mm_modem_gsm_sms_send (MMModemGsmSms *self,
+ const char *number,
+ const char *text,
+ const char *smsc,
+ guint validity,
+ guint class,
+ MMModemFn callback,
+ gpointer user_data);
+
+#endif /* MM_MODEM_GSM_SMS_H */
diff --git a/test/mm-send-sms.py b/test/mm-send-sms.py
new file mode 100755
index 00000000..06be591d
--- /dev/null
+++ b/test/mm-send-sms.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+
+# An example on how to send an SMS message using ModemManager
+
+import sys
+import dbus
+
+if len(sys.argv) != 3:
+ print "Usage: %s <number> <message>" % sys.argv[0]
+ sys.exit(1)
+
+number = sys.argv[1]
+message = sys.argv[2]
+
+bus = dbus.SystemBus()
+
+manager_proxy = bus.get_object('org.freedesktop.ModemManager', '/org/freedesktop/ModemManager')
+manager_iface = dbus.Interface(manager_proxy, dbus_interface='org.freedesktop.ModemManager')
+modems = manager_iface.EnumerateDevices()
+if len(modems) == 0:
+ print "No modems found"
+ sys.exit(1)
+
+proxy = bus.get_object('org.freedesktop.ModemManager', modems[0])
+modem = dbus.Interface(proxy, dbus_interface='org.freedesktop.ModemManager.Modem')
+modem.Enable(True)
+
+msg_dict = dbus.Dictionary({ dbus.String('number') : dbus.String(number),
+ dbus.String('text') : dbus.String(message)
+ },
+ signature=dbus.Signature("sv"))
+
+sms_iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.ModemManager.Modem.Gsm.SMS')
+try:
+ sms_iface.Send(msg_dict)
+except e:
+ print "Sending message failed"
+finally:
+ modem.Enable(False)