port-probe: enable probing for Vendor
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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 */
|
||||
|
||||
|
@@ -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;
|
||||
@@ -140,6 +141,25 @@ port_probe_run_is_cancelled (MMPortProbe *self)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -581,6 +610,15 @@ mm_port_probe_get_port (MMPortProbe *self)
|
||||
return self->priv->port;
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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 */
|
||||
@@ -95,6 +96,7 @@ 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);
|
||||
const gchar *mm_port_probe_get_vendor (MMPortProbe *self);
|
||||
|
||||
#endif /* MM_PORT_PROBE_H */
|
||||
|
||||
|
Reference in New Issue
Block a user