aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2011-09-10 11:19:12 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-03-15 14:14:20 +0100
commit1f9fd9e0beba7fd90c46d057c849fb007001b75f (patch)
tree095659d36721cf94e69456befabd386aff4bef6d
parent05f8493ee7baa43cb7ff1242eae4930fc85e6ee5 (diff)
port-probe: enable probing for Vendor
-rw-r--r--src/mm-port-probe-at-command.c28
-rw-r--r--src/mm-port-probe-at-command.h1
-rw-r--r--src/mm-port-probe.c46
-rw-r--r--src/mm-port-probe.h6
4 files changed, 76 insertions, 5 deletions
diff --git a/src/mm-port-probe-at-command.c b/src/mm-port-probe-at-command.c
index 72a49f1b..099f85fd 100644
--- a/src/mm-port-probe-at-command.c
+++ b/src/mm-port-probe-at-command.c
@@ -190,3 +190,31 @@ mm_port_probe_at_command_get_capabilities_probing (void)
return capabilities_probing;
}
+/* ---- VENDOR probing ---- */
+
+static gboolean
+parse_vendor (const gchar *response,
+ const GError *error,
+ GValue *result,
+ GError **result_error)
+{
+ gchar *str;
+
+ str = g_strstrip (g_strdelimit (g_strdup (response), "\r\n", ' '));
+ g_value_init (result, G_TYPE_STRING);
+ g_value_take_string (result, str);
+ return TRUE;
+}
+
+static const MMPortProbeAtCommand vendor_probing[] = {
+ { "+CGMI", parse_vendor },
+ { "+GMI", parse_vendor },
+ { "I", parse_vendor },
+ { NULL }
+};
+
+const MMPortProbeAtCommand *
+mm_port_probe_at_command_get_vendor_probing (void)
+{
+ return vendor_probing;
+}
diff --git a/src/mm-port-probe-at-command.h b/src/mm-port-probe-at-command.h
index d66b2084..ea41ec45 100644
--- a/src/mm-port-probe-at-command.h
+++ b/src/mm-port-probe-at-command.h
@@ -53,6 +53,7 @@ typedef struct {
/* Default commands used during probing */
const MMPortProbeAtCommand *mm_port_probe_at_command_get_probing (void);
const MMPortProbeAtCommand *mm_port_probe_at_command_get_capabilities_probing (void);
+const MMPortProbeAtCommand *mm_port_probe_at_command_get_vendor_probing (void);
#endif /* MM_PORT_PROBE_AT_COMMAND_H */
diff --git a/src/mm-port-probe.c b/src/mm-port-probe.c
index 1332be0b..99498299 100644
--- a/src/mm-port-probe.c
+++ b/src/mm-port-probe.c
@@ -61,6 +61,7 @@ struct _MMPortProbePrivate {
guint32 flags;
gboolean is_at;
guint32 capabilities;
+ gchar *vendor;
/* Current probing task. Only one can be available at a time */
PortProbeRunTask *task;
@@ -141,6 +142,25 @@ port_probe_run_is_cancelled (MMPortProbe *self)
}
static void
+serial_probe_at_vendor_result_processor (MMPortProbe *self,
+ GValue *result)
+{
+ if (result) {
+ /* If any result given, it must be a string */
+ g_assert (G_VALUE_HOLDS_STRING (result));
+
+ mm_dbg ("(%s) vendor probing finished", self->priv->name);
+ self->priv->vendor = g_utf8_casefold (g_value_get_string (result), -1);
+ self->priv->flags |= MM_PORT_PROBE_AT_VENDOR;
+ return;
+ }
+
+ mm_dbg ("(%s) no result in vendor probing", self->priv->name);
+ self->priv->vendor = NULL;
+ self->priv->flags |= MM_PORT_PROBE_AT_VENDOR;
+}
+
+static void
serial_probe_at_capabilities_result_processor (MMPortProbe *self,
GValue *result)
{
@@ -178,7 +198,8 @@ serial_probe_at_result_processor (MMPortProbe *self,
mm_dbg ("(%s) port is not AT-capable", self->priv->name);
self->priv->is_at = FALSE;
self->priv->flags |= (MM_PORT_PROBE_AT |
- MM_PORT_PROBE_AT_CAPABILITIES);
+ MM_PORT_PROBE_AT_CAPABILITIES |
+ MM_PORT_PROBE_AT_VENDOR);
}
static void
@@ -284,6 +305,13 @@ serial_probe_schedule (MMPortProbe *self)
task->at_result_processor = serial_probe_at_capabilities_result_processor;
task->at_commands = mm_port_probe_at_command_get_capabilities_probing ();
}
+ /* Vendor requested and not already probed? */
+ else if ((task->flags & MM_PORT_PROBE_AT_VENDOR) &&
+ !(self->priv->flags & MM_PORT_PROBE_AT_VENDOR)) {
+ /* Prepare AT vendor probing */
+ task->at_result_processor = serial_probe_at_vendor_result_processor;
+ task->at_commands = mm_port_probe_at_command_get_vendor_probing ();
+ }
/* If a next AT group detected, go for it */
if (task->at_result_processor &&
@@ -519,7 +547,7 @@ mm_port_probe_run (MMPortProbe *self,
/* Check if we already have the requested probing results.
* We will fix here the 'task->flags' so that we only request probing
* for the missing things. */
- for (i = MM_PORT_PROBE_AT; i <= MM_PORT_PROBE_AT_CAPABILITIES; i = (i << 1)) {
+ for (i = MM_PORT_PROBE_AT; i <= MM_PORT_PROBE_AT_VENDOR; i = (i << 1)) {
if ((flags & i) && !(self->priv->flags & i)) {
task->flags += i;
}
@@ -541,7 +569,8 @@ mm_port_probe_run (MMPortProbe *self,
self->priv->task = task;
/* If any AT-specific probing requested, require generic AT check before */
- if (task->flags & MM_PORT_PROBE_AT_CAPABILITIES) {
+ if (task->flags & (MM_PORT_PROBE_AT_CAPABILITIES |
+ MM_PORT_PROBE_AT_VENDOR)) {
task->flags |= MM_PORT_PROBE_AT;
}
@@ -582,6 +611,15 @@ mm_port_probe_get_port (MMPortProbe *self)
};
const gchar *
+mm_port_probe_get_vendor (MMPortProbe *self)
+{
+ g_return_val_if_fail (MM_IS_PORT_PROBE (self), NULL);
+ g_return_val_if_fail (self->priv->flags & MM_PORT_PROBE_AT_VENDOR, NULL);
+
+ return self->priv->vendor;
+}
+
+const gchar *
mm_port_probe_get_port_name (MMPortProbe *self)
{
g_return_val_if_fail (MM_IS_PORT_PROBE (self), NULL);
@@ -652,6 +690,8 @@ finalize (GObject *object)
g_free (self->priv->driver);
g_object_unref (self->priv->port);
+ g_free (self->priv->vendor);
+
G_OBJECT_CLASS (mm_port_probe_parent_class)->finalize (object);
}
diff --git a/src/mm-port-probe.h b/src/mm-port-probe.h
index 46b03bc6..a011da25 100644
--- a/src/mm-port-probe.h
+++ b/src/mm-port-probe.h
@@ -33,6 +33,7 @@
/* Flags to request port probing */
#define MM_PORT_PROBE_AT 0x0001
#define MM_PORT_PROBE_AT_CAPABILITIES 0x0002
+#define MM_PORT_PROBE_AT_VENDOR 0x0004
/* Flags to report probed capabilities */
#define MM_PORT_PROBE_CAPABILITY_GSM 0x0001 /* GSM */
@@ -93,8 +94,9 @@ gboolean mm_port_probe_run_finish (MMPortProbe *self,
gboolean mm_port_probe_run_cancel (MMPortProbe *self);
/* Probing result getters */
-gboolean mm_port_probe_is_at (MMPortProbe *self);
-guint32 mm_port_probe_get_capabilities (MMPortProbe *self);
+gboolean mm_port_probe_is_at (MMPortProbe *self);
+guint32 mm_port_probe_get_capabilities (MMPortProbe *self);
+const gchar *mm_port_probe_get_vendor (MMPortProbe *self);
#endif /* MM_PORT_PROBE_H */