summaryrefslogtreecommitdiff
path: root/plugins/gemalto.c
diff options
context:
space:
mode:
authorVincent Cesson <vincent.cesson@smile.fr>2017-05-16 10:38:40 +0200
committerDenis Kenzior <denkenz@gmail.com>2017-05-16 13:13:48 -0500
commit5e6770e38e7c82e6a67ba8ef59a393b296d594e9 (patch)
treed7f2943481a2809ac5553b3697e7f02e8b97f9db /plugins/gemalto.c
parent440c9bec888f7e2f3eb2c76f32e8503d203624c0 (diff)
downloadofono-5e6770e38e7c82e6a67ba8ef59a393b296d594e9.tar.gz
gemalto: Prepare new interface for hardware monitoring
Gemalto modems have hardware related commands, allowing to monitor voltage and temperature. These parameters will be accessible on DBus interface: org.ofono.HardwareMonitor. - Create the DBus method table with one entry: GetStatistics. This method would return temperature and voltage values. - Create a dedicated structure to handle the DBus methods. - Create enable/disable functions to handle DBus interface registration.
Diffstat (limited to 'plugins/gemalto.c')
-rw-r--r--plugins/gemalto.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/plugins/gemalto.c b/plugins/gemalto.c
index 2870ce8a..3798e097 100644
--- a/plugins/gemalto.c
+++ b/plugins/gemalto.c
@@ -29,8 +29,12 @@
#include <glib.h>
#include <gatchat.h>
#include <gattty.h>
+#include <gdbus.h>
+
+#include "ofono.h"
#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/dbus.h>
#include <ofono/plugin.h>
#include <ofono/log.h>
#include <ofono/modem.h>
@@ -46,14 +50,23 @@
#include <drivers/atmodem/atutil.h>
#include <drivers/atmodem/vendor.h>
+#define HARDWARE_MONITOR_INTERFACE OFONO_SERVICE ".cinterion.HardwareMonitor"
+
static const char *none_prefix[] = { NULL };
+struct gemalto_hardware_monitor {
+ DBusMessage *msg;
+ int32_t temperature;
+ int32_t voltage;
+};
+
struct gemalto_data {
GAtChat *app;
GAtChat *mdm;
struct ofono_sim *sim;
gboolean have_sim;
struct at_util_sim_state_query *sim_state_query;
+ struct gemalto_hardware_monitor *hm;
};
static int gemalto_probe(struct ofono_modem *modem)
@@ -142,6 +155,59 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
NULL);
}
+static DBusMessage *hardware_monitor_get_statistics(DBusConnection *conn,
+ DBusMessage *msg,
+ void *user_data)
+{
+ DBG("");
+
+ return __ofono_error_not_implemented(msg);
+}
+
+static const GDBusMethodTable hardware_monitor_methods[] = {
+ { GDBUS_ASYNC_METHOD("GetStatistics",
+ NULL, GDBUS_ARGS({ "Statistics", "a{sv}" }),
+ hardware_monitor_get_statistics) },
+ {}
+};
+
+static void hardware_monitor_cleanup(void *user_data)
+{
+ struct gemalto_data *data = user_data;
+ struct gemalto_hardware_monitor *hm = data->hm;
+
+ g_free(hm);
+}
+
+static int gemalto_hardware_monitor_enable(struct ofono_modem *modem)
+{
+ struct gemalto_data *data = ofono_modem_get_data(modem);
+ DBusConnection *conn = ofono_dbus_get_connection();
+ const char *path = ofono_modem_get_path(modem);
+
+ DBG("");
+
+ /* Enable temperature output */
+ g_at_chat_send(data->app, "AT^SCTM=0,1", none_prefix, NULL, NULL, NULL);
+
+ /* Create Hardware Monitor DBus interface */
+ data->hm = g_try_new0(struct gemalto_hardware_monitor, 1);
+ if (data->hm == NULL)
+ return -EIO;
+
+ if (!g_dbus_register_interface(conn, path, HARDWARE_MONITOR_INTERFACE,
+ hardware_monitor_methods, NULL, NULL,
+ data, hardware_monitor_cleanup)) {
+ ofono_error("Could not register %s interface under %s",
+ HARDWARE_MONITOR_INTERFACE, path);
+ g_free(data->hm);
+ return -EIO;
+ }
+
+ ofono_modem_add_interface(modem, HARDWARE_MONITOR_INTERFACE);
+ return 0;
+}
+
static int gemalto_enable(struct ofono_modem *modem)
{
struct gemalto_data *data = ofono_modem_get_data(modem);
@@ -181,6 +247,8 @@ static int gemalto_enable(struct ofono_modem *modem)
g_at_chat_send(data->app, "AT+CFUN=4", none_prefix,
cfun_enable, modem, NULL);
+ gemalto_hardware_monitor_enable(modem);
+
return -EINPROGRESS;
}
@@ -203,12 +271,19 @@ static void gemalto_smso_cb(gboolean ok, GAtResult *result, gpointer user_data)
static int gemalto_disable(struct ofono_modem *modem)
{
struct gemalto_data *data = ofono_modem_get_data(modem);
+ DBusConnection *conn = ofono_dbus_get_connection();
+ const char *path = ofono_modem_get_path(modem);
DBG("%p", modem);
g_at_chat_cancel_all(data->app);
g_at_chat_unregister_all(data->app);
+ if (g_dbus_unregister_interface(conn, path,
+ HARDWARE_MONITOR_INTERFACE))
+ ofono_modem_remove_interface(modem,
+ HARDWARE_MONITOR_INTERFACE);
+
/* Shutdown the modem */
g_at_chat_send(data->app, "AT^SMSO", none_prefix, gemalto_smso_cb,
modem, NULL);