From: Andras Domokos <[email protected]>
---
src/modem.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/ofono.h | 4 ++
2 files changed, 136 insertions(+), 0 deletions(-)
diff --git a/src/modem.c b/src/modem.c
index f73cc1d..5315e72 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -72,6 +72,8 @@ struct ofono_modem {
ofono_bool_t powered_pending;
guint timeout;
ofono_bool_t online;
+ ofono_bool_t emergency_online;
+ unsigned int emergency_mode;
struct ofono_watchlist *online_watches;
GHashTable *properties;
struct ofono_sim *sim;
@@ -514,6 +516,125 @@ static void offline_cb(const struct ofono_error *error,
void *data)
modem_change_state(modem, MODEM_STATE_OFFLINE);
}
+ofono_bool_t ofono_modem_get_emergency_mode(struct ofono_modem *modem)
+{
+ if (modem == NULL)
+ return FALSE;
+
+ return modem->emergency_mode != 0;
+}
+
+static void modem_change_online(struct ofono_modem *modem,
+ enum modem_state new_state)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+ enum modem_state old_state = modem->modem_state;
+ ofono_bool_t new_online = new_state == MODEM_STATE_ONLINE;
+
+ DBG("old state: %d, new state: %d", old_state, new_state);
+
+ if (new_online == modem->online)
+ return;
+
+ modem->modem_state = new_state;
+ modem->emergency_online = modem->online;
+ modem->online = new_online;
+
+ ofono_dbus_signal_property_changed(conn, modem->path,
+ OFONO_MODEM_INTERFACE, "Online",
+ DBUS_TYPE_BOOLEAN, &modem->online);
+
+ notify_online_watches(modem);
+}
+
+static void emergency_online_cb(const struct ofono_error *error, void *data)
+{
+ struct ofono_modem *modem = data;
+
+ DBG("modem: %p", modem);
+
+ if (error->type == OFONO_ERROR_TYPE_NO_ERROR &&
+ modem->modem_state == MODEM_STATE_OFFLINE)
+ modem_change_online(modem, MODEM_STATE_ONLINE);
+}
+
+static void emergency_offline_cb(const struct ofono_error *error, void *data)
+{
+ struct ofono_modem *modem = data;
+ DBusConnection *conn = ofono_dbus_get_connection();
+ const char *path = ofono_modem_get_path(modem);
+ gboolean state = FALSE;
+
+ DBG("modem: %p", modem);
+
+ if (error->type == OFONO_ERROR_TYPE_NO_ERROR &&
+ modem->modem_state == MODEM_STATE_ONLINE)
+ modem_change_online(modem, MODEM_STATE_OFFLINE);
+
+ modem->emergency_mode--;
+
+ ofono_dbus_signal_property_changed(conn, path,
+ OFONO_MODEM_INTERFACE,
+ "EmergencyMode",
+ DBUS_TYPE_BOOLEAN,
+ &state);
+}
+
+void ofono_modem_inc_emergency_mode(struct ofono_modem *modem)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+ const char *path = ofono_modem_get_path(modem);
+ gboolean state = TRUE;
+
+ DBG("modem: %p", modem);
+
+ modem->emergency_mode++;
+ if (modem->emergency_mode > 1)
+ return;
+
+ ofono_dbus_signal_property_changed(conn, path,
+ OFONO_MODEM_INTERFACE,
+ "EmergencyMode",
+ DBUS_TYPE_BOOLEAN,
+ &state);
+
+ if (modem->online)
+ return;
+
+ modem->driver->set_online(modem, TRUE, emergency_online_cb, modem);
+}
+
+void ofono_modem_dec_emergency_mode(struct ofono_modem *modem)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+ const char *path = ofono_modem_get_path(modem);
+ gboolean state = FALSE;
+
+ DBG("modem: %p", modem);
+
+ if (modem->emergency_mode == 0)
+ return;
+
+ if (modem->emergency_mode > 1) {
+ modem->emergency_mode--;
+ return;
+ }
+
+ if (!modem->emergency_online) {
+ modem->driver->set_online(modem, FALSE,
+ emergency_offline_cb, modem);
+ return;
+ }
+
+ modem->emergency_mode--;
+
+ ofono_dbus_signal_property_changed(conn, path,
+ OFONO_MODEM_INTERFACE,
+ "EmergencyMode",
+ DBUS_TYPE_BOOLEAN,
+ &state);
+}
+
static DBusMessage *set_property_online(struct ofono_modem *modem,
DBusMessage *msg,
DBusMessageIter *var)
@@ -535,6 +656,9 @@ static DBusMessage *set_property_online(struct ofono_modem
*modem,
if (modem->modem_state < MODEM_STATE_OFFLINE)
return __ofono_error_not_available(msg);
+ if (modem->emergency_mode)
+ return __ofono_error_failed(msg);
+
if (modem->online == online)
return dbus_message_new_method_return(msg);
@@ -562,6 +686,7 @@ void __ofono_modem_append_properties(struct ofono_modem
*modem,
int i;
GSList *l;
struct ofono_atom *devinfo_atom;
+ ofono_bool_t state;
ofono_dbus_dict_append(dict, "Online", DBUS_TYPE_BOOLEAN,
&modem->online);
@@ -569,6 +694,10 @@ void __ofono_modem_append_properties(struct ofono_modem
*modem,
ofono_dbus_dict_append(dict, "Powered", DBUS_TYPE_BOOLEAN,
&modem->powered);
+ state = ofono_modem_get_emergency_mode(modem);
+ ofono_dbus_dict_append(dict, "EmergencyMode",
+ DBUS_TYPE_BOOLEAN, &state);
+
devinfo_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_DEVINFO);
/* We cheat a little here and don't check the registered status */
@@ -647,6 +776,9 @@ static int set_powered(struct ofono_modem *modem,
ofono_bool_t powered)
if (modem->powered_pending == powered)
return -EALREADY;
+ if (modem->emergency_mode)
+ return -EINVAL;
+
/* Remove the atoms even if the driver is no longer available */
if (powered == FALSE)
modem_change_state(modem, MODEM_STATE_POWER_OFF);
diff --git a/src/ofono.h b/src/ofono.h
index 01cd6c0..ac56a85 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -185,6 +185,10 @@ unsigned int __ofono_modem_add_online_watch(struct
ofono_modem *modem,
void __ofono_modem_remove_online_watch(struct ofono_modem *modem,
unsigned int id);
+ofono_bool_t ofono_modem_get_emergency_mode(struct ofono_modem *modem);
+void ofono_modem_inc_emergency_mode(struct ofono_modem *modem);
+void ofono_modem_dec_emergency_mode(struct ofono_modem *modem);
+
#include <ofono/call-barring.h>
gboolean __ofono_call_barring_is_busy(struct ofono_call_barring *cb);
--
1.7.0.4
_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono