diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2011-09-10 11:40:23 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:20 +0100 |
commit | b73fb8e8f27ac34ec5aa16e3e5a3605b03dbe740 (patch) | |
tree | a75c866c25906dc7d67517e979495984075ddc8b | |
parent | 1f9fd9e0beba7fd90c46d057c849fb007001b75f (diff) |
port-probe: enable probing for Product
-rw-r--r-- | src/mm-port-probe-at-command.c | 30 | ||||
-rw-r--r-- | src/mm-port-probe-at-command.h | 1 | ||||
-rw-r--r-- | src/mm-port-probe.c | 45 | ||||
-rw-r--r-- | src/mm-port-probe.h | 2 |
4 files changed, 75 insertions, 3 deletions
diff --git a/src/mm-port-probe-at-command.c b/src/mm-port-probe-at-command.c index 099f85fd..ecf494c4 100644 --- a/src/mm-port-probe-at-command.c +++ b/src/mm-port-probe-at-command.c @@ -218,3 +218,33 @@ mm_port_probe_at_command_get_vendor_probing (void) { return vendor_probing; } + +/* ---- PRODUCT probing ---- */ + +static gboolean +parse_product (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 product_probing[] = { + { "+CGMM", parse_product }, + { "+GMM", parse_product }, + { "I", parse_product }, + { NULL } +}; + +const MMPortProbeAtCommand * +mm_port_probe_at_command_get_product_probing (void) +{ + return product_probing; +} diff --git a/src/mm-port-probe-at-command.h b/src/mm-port-probe-at-command.h index ea41ec45..f74cb750 100644 --- a/src/mm-port-probe-at-command.h +++ b/src/mm-port-probe-at-command.h @@ -54,6 +54,7 @@ typedef struct { 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); +const MMPortProbeAtCommand *mm_port_probe_at_command_get_product_probing (void); #endif /* MM_PORT_PROBE_AT_COMMAND_H */ diff --git a/src/mm-port-probe.c b/src/mm-port-probe.c index 99498299..7fa28ab1 100644 --- a/src/mm-port-probe.c +++ b/src/mm-port-probe.c @@ -62,6 +62,7 @@ struct _MMPortProbePrivate { gboolean is_at; guint32 capabilities; gchar *vendor; + gchar *product; /* Current probing task. Only one can be available at a time */ PortProbeRunTask *task; @@ -142,6 +143,25 @@ port_probe_run_is_cancelled (MMPortProbe *self) } static void +serial_probe_at_product_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) product probing finished", self->priv->name); + self->priv->product = g_utf8_casefold (g_value_get_string (result), -11); + self->priv->flags |= MM_PORT_PROBE_AT_PRODUCT; + return; + } + + mm_dbg ("(%s) no result in product probing", self->priv->name); + self->priv->product = NULL; + self->priv->flags |= MM_PORT_PROBE_AT_PRODUCT; +} + +static void serial_probe_at_vendor_result_processor (MMPortProbe *self, GValue *result) { @@ -199,7 +219,8 @@ serial_probe_at_result_processor (MMPortProbe *self, self->priv->is_at = FALSE; self->priv->flags |= (MM_PORT_PROBE_AT | MM_PORT_PROBE_AT_CAPABILITIES | - MM_PORT_PROBE_AT_VENDOR); + MM_PORT_PROBE_AT_VENDOR | + MM_PORT_PROBE_AT_PRODUCT); } static void @@ -312,6 +333,13 @@ serial_probe_schedule (MMPortProbe *self) task->at_result_processor = serial_probe_at_vendor_result_processor; task->at_commands = mm_port_probe_at_command_get_vendor_probing (); } + /* Product requested and not already probed? */ + else if ((task->flags & MM_PORT_PROBE_AT_PRODUCT) && + !(self->priv->flags & MM_PORT_PROBE_AT_PRODUCT)) { + /* Prepare AT product probing */ + task->at_result_processor = serial_probe_at_product_result_processor; + task->at_commands = mm_port_probe_at_command_get_product_probing (); + } /* If a next AT group detected, go for it */ if (task->at_result_processor && @@ -547,7 +575,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_VENDOR; i = (i << 1)) { + for (i = MM_PORT_PROBE_AT; i <= MM_PORT_PROBE_AT_PRODUCT; i = (i << 1)) { if ((flags & i) && !(self->priv->flags & i)) { task->flags += i; } @@ -570,7 +598,8 @@ mm_port_probe_run (MMPortProbe *self, /* If any AT-specific probing requested, require generic AT check before */ if (task->flags & (MM_PORT_PROBE_AT_CAPABILITIES | - MM_PORT_PROBE_AT_VENDOR)) { + MM_PORT_PROBE_AT_VENDOR | + MM_PORT_PROBE_AT_PRODUCT)) { task->flags |= MM_PORT_PROBE_AT; } @@ -620,6 +649,15 @@ mm_port_probe_get_vendor (MMPortProbe *self) } const gchar * +mm_port_probe_get_product (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_PRODUCT, NULL); + + return self->priv->product; +} + +const gchar * mm_port_probe_get_port_name (MMPortProbe *self) { g_return_val_if_fail (MM_IS_PORT_PROBE (self), NULL); @@ -691,6 +729,7 @@ finalize (GObject *object) g_object_unref (self->priv->port); g_free (self->priv->vendor); + g_free (self->priv->product); 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 a011da25..4616fe66 100644 --- a/src/mm-port-probe.h +++ b/src/mm-port-probe.h @@ -34,6 +34,7 @@ #define MM_PORT_PROBE_AT 0x0001 #define MM_PORT_PROBE_AT_CAPABILITIES 0x0002 #define MM_PORT_PROBE_AT_VENDOR 0x0004 +#define MM_PORT_PROBE_AT_PRODUCT 0x0008 /* Flags to report probed capabilities */ #define MM_PORT_PROBE_CAPABILITY_GSM 0x0001 /* GSM */ @@ -97,6 +98,7 @@ gboolean mm_port_probe_run_cancel (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); +const gchar *mm_port_probe_get_product (MMPortProbe *self); #endif /* MM_PORT_PROBE_H */ |