aboutsummaryrefslogtreecommitdiff
path: root/src/mm-modem-base.c
diff options
context:
space:
mode:
authorEric Shienbrood <ers@chromium.org>2011-11-16 17:42:50 -0600
committerDan Williams <dcbw@redhat.com>2011-11-16 17:42:50 -0600
commite7b6b2dc1c709ae877e3cd472d4134b918bb5fb7 (patch)
tree00307c0559926bddad575ca85f1bffab43105b56 /src/mm-modem-base.c
parent71598a628987162196b98124486ad8e728852ec5 (diff)
core: keep track of all PIN retry counts
Added a PinRetryCounts property on org.freedesktop.ModemManager.Modem. This is dictionary that records the number of PIN tries remaining for each of the possible PIN code types for which the modem is capable of reporting the count. Also, these counts are kept up to date across ChangePin and EnablePin operations, not just when an unlock is attempted.
Diffstat (limited to 'src/mm-modem-base.c')
-rw-r--r--src/mm-modem-base.c98
1 files changed, 74 insertions, 24 deletions
diff --git a/src/mm-modem-base.c b/src/mm-modem-base.c
index a065681e..526eb51e 100644
--- a/src/mm-modem-base.c
+++ b/src/mm-modem-base.c
@@ -55,6 +55,7 @@ typedef struct {
char *device_ident;
char *unlock_required;
guint32 unlock_retries;
+ GArray *pin_retry_counts;
guint32 ip_method;
gboolean valid;
MMModemState state;
@@ -354,44 +355,64 @@ mm_modem_base_set_unlock_required (MMModemBase *self, const char *unlock_require
g_object_notify (G_OBJECT (self), MM_MODEM_UNLOCK_REQUIRED);
}
-guint32
-mm_modem_base_get_unlock_retries (MMModemBase *self)
-{
- g_return_val_if_fail (self != NULL, 0);
- g_return_val_if_fail (MM_IS_MODEM_BASE (self), 0);
-
- return MM_MODEM_BASE_GET_PRIVATE (self)->unlock_retries;
-}
-
void
-mm_modem_base_set_unlock_retries (MMModemBase *self, guint unlock_retries)
+mm_modem_base_set_pin_retry_counts (MMModemBase *self, GArray *pin_retries)
{
MMModemBasePrivate *priv;
- const char *dbus_path;
+ GArray *old_retries;
+ gboolean same;
+ PinRetryCount *active = NULL;
+ guint i, j;
+ guint old_unlock_retries;
g_return_if_fail (self != NULL);
g_return_if_fail (MM_IS_MODEM_BASE (self));
priv = MM_MODEM_BASE_GET_PRIVATE (self);
-
- /* Only do something if the value changes */
- if (priv->unlock_retries == unlock_retries)
+ if (!pin_retries) {
+ priv->unlock_retries = MM_MODEM_UNLOCK_RETRIES_NOT_SUPPORTED;
return;
+ }
- priv->unlock_retries = unlock_retries;
+ old_retries = priv->pin_retry_counts;
+ old_unlock_retries = priv->unlock_retries;
- dbus_path = (const char *) g_object_get_data (G_OBJECT (self), DBUS_PATH_TAG);
- if (dbus_path) {
- if (priv->unlock_required) {
- mm_info ("Modem %s: # unlock retries for %s is %d",
- dbus_path, priv->unlock_required, priv->unlock_retries);
- } else {
- mm_info ("Modem %s: # unlock retries is %d",
- dbus_path, priv->unlock_retries);
+ /* Only do something if one of the values changes */
+ same = (old_retries != NULL) && (pin_retries->len == old_retries->len);
+ for (i = 0; i < pin_retries->len; ++i) {
+ PinRetryCount *newur = &g_array_index (pin_retries, PinRetryCount, i);
+
+ if (!g_strcmp0 (newur->name, priv->unlock_required))
+ active = newur;
+
+ if (old_retries) {
+ for (j = 0; j < old_retries->len; ++j) {
+ PinRetryCount *oldur = &g_array_index (old_retries, PinRetryCount, i);
+
+ if (!g_strcmp0 (oldur->name, newur->name)) {
+ if (oldur->count != newur->count)
+ same = FALSE;
+ break;
+ }
+ }
}
}
- g_object_notify (G_OBJECT (self), MM_MODEM_UNLOCK_RETRIES);
+ if (priv->pin_retry_counts)
+ g_array_unref (priv->pin_retry_counts);
+
+ priv->pin_retry_counts = pin_retries;
+
+ if (priv->unlock_required) {
+ g_assert (active);
+ priv->unlock_retries = active->count;
+ } else
+ priv->unlock_retries = 0;
+
+ if (old_unlock_retries != priv->unlock_retries)
+ g_object_notify (G_OBJECT (self), MM_MODEM_UNLOCK_RETRIES);
+ if (!same)
+ g_object_notify (G_OBJECT (self), MM_MODEM_PIN_RETRY_COUNTS);
}
const char *
@@ -700,6 +721,10 @@ mm_modem_base_init (MMModemBase *self)
NULL,
MM_DBUS_INTERFACE_MODEM);
mm_properties_changed_signal_register_property (G_OBJECT (self),
+ MM_MODEM_PIN_RETRY_COUNTS,
+ NULL,
+ MM_DBUS_INTERFACE_MODEM);
+ mm_properties_changed_signal_register_property (G_OBJECT (self),
MM_MODEM_IP_METHOD,
NULL,
MM_DBUS_INTERFACE_MODEM);
@@ -760,6 +785,7 @@ set_property (GObject *object, guint prop_id,
case MM_MODEM_PROP_DEVICE_IDENTIFIER:
case MM_MODEM_PROP_UNLOCK_REQUIRED:
case MM_MODEM_PROP_UNLOCK_RETRIES:
+ case MM_MODEM_PROP_PIN_RETRY_COUNTS:
break;
case MM_MODEM_PROP_HW_VID:
/* Construct only */
@@ -778,6 +804,23 @@ set_property (GObject *object, guint prop_id,
}
}
+static GHashTable *
+get_retry_counts (GArray *counts)
+{
+ GHashTable *map;
+ int i;
+
+ map = g_hash_table_new (g_str_hash, g_str_equal);
+
+ if (counts) {
+ for (i = 0; i < counts->len; ++i) {
+ PinRetryCount *ur = (PinRetryCount *) &g_array_index (counts, PinRetryCount, i);
+ g_hash_table_insert (map, (char *) ur->name, GUINT_TO_POINTER (ur->count));
+ }
+ }
+ return map;
+}
+
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
@@ -824,6 +867,9 @@ get_property (GObject *object, guint prop_id,
case MM_MODEM_PROP_UNLOCK_RETRIES:
g_value_set_uint (value, priv->unlock_retries);
break;
+ case MM_MODEM_PROP_PIN_RETRY_COUNTS:
+ g_value_set_boxed (value, get_retry_counts (priv->pin_retry_counts));
+ break;
case MM_MODEM_PROP_HW_VID:
g_value_set_uint (value, priv->vid);
break;
@@ -929,6 +975,10 @@ mm_modem_base_class_init (MMModemBaseClass *klass)
MM_MODEM_UNLOCK_RETRIES);
g_object_class_override_property (object_class,
+ MM_MODEM_PROP_PIN_RETRY_COUNTS,
+ MM_MODEM_PIN_RETRY_COUNTS);
+
+ g_object_class_override_property (object_class,
MM_MODEM_PROP_HW_VID,
MM_MODEM_HW_VID);