kernel-device: ID_USB_INTERFACE_NUM should be read as an hex string
The original g_udev_device_get_property_as_int() uses strtol() without an explicit base (i.e. 0) so that the base is autodetected from the string whenever possible (e.g. if prefixes with '0x' it is treated as a hexadecimal string). But, for ID_USB_INTERFACE_NUM, we explicitly require reading the number as an hex string, even if we don't have any '0x' prefix. Reported-by: Matthew Stanger <stangerm2@gmail.com>
This commit is contained in:
@@ -227,9 +227,9 @@ try_next_usbif (MMDevice *device)
|
||||
|
||||
/* Only expect ttys for next probing attempt */
|
||||
if (g_str_equal (mm_port_probe_get_port_subsys (probe), "tty")) {
|
||||
gint usbif;
|
||||
guint usbif;
|
||||
|
||||
usbif = mm_kernel_device_get_property_as_int (mm_port_probe_peek_port (probe), "ID_USB_INTERFACE_NUM");
|
||||
usbif = mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (probe), "ID_USB_INTERFACE_NUM");
|
||||
if (usbif == fi_ctx->first_usbif) {
|
||||
/* This is the one we just probed, which wasn't yet removed, so just skip it */
|
||||
} else if (usbif > fi_ctx->first_usbif &&
|
||||
@@ -390,8 +390,8 @@ huawei_custom_init (MMPortProbe *probe,
|
||||
ctx->getportmode_retries = 3;
|
||||
|
||||
/* Custom init only to be run in the first interface */
|
||||
if (mm_kernel_device_get_property_as_int (mm_port_probe_peek_port (probe),
|
||||
"ID_USB_INTERFACE_NUM") != fi_ctx->first_usbif) {
|
||||
if (mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (probe),
|
||||
"ID_USB_INTERFACE_NUM") != fi_ctx->first_usbif) {
|
||||
|
||||
if (fi_ctx->custom_init_run)
|
||||
/* If custom init was run already, we can consider this as successfully run */
|
||||
@@ -431,9 +431,9 @@ propagate_port_mode_results (GList *probes)
|
||||
/* Now we propagate the tags to the specific port probes */
|
||||
for (l = probes; l; l = g_list_next (l)) {
|
||||
MMPortSerialAtFlag at_port_flags = MM_PORT_SERIAL_AT_FLAG_NONE;
|
||||
gint usbif;
|
||||
guint usbif;
|
||||
|
||||
usbif = mm_kernel_device_get_property_as_int (mm_port_probe_peek_port (MM_PORT_PROBE (l->data)), "ID_USB_INTERFACE_NUM");
|
||||
usbif = mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (MM_PORT_PROBE (l->data)), "ID_USB_INTERFACE_NUM");
|
||||
|
||||
if (GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (device), TAG_GETPORTMODE_SUPPORTED))) {
|
||||
if (usbif + 1 == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (device), TAG_HUAWEI_PCUI_PORT))) {
|
||||
|
@@ -56,7 +56,7 @@ grab_port (MMPlugin *self,
|
||||
{
|
||||
MMPortSerialAtFlag pflags = MM_PORT_SERIAL_AT_FLAG_NONE;
|
||||
MMKernelDevice *port;
|
||||
gint usbif;
|
||||
guint usbif;
|
||||
|
||||
/* The Option plugin cannot do anything with non-AT ports */
|
||||
if (!mm_port_probe_is_at (probe)) {
|
||||
@@ -73,7 +73,7 @@ grab_port (MMPlugin *self,
|
||||
* the modem/data port, per mail with Option engineers. Only this port
|
||||
* will emit responses to dialing commands.
|
||||
*/
|
||||
usbif = mm_kernel_device_get_property_as_int (port, "ID_USB_INTERFACE_NUM");
|
||||
usbif = mm_kernel_device_get_property_as_int_hex (port, "ID_USB_INTERFACE_NUM");
|
||||
if (usbif == 0)
|
||||
pflags = MM_PORT_SERIAL_AT_FLAG_PRIMARY | MM_PORT_SERIAL_AT_FLAG_PPP;
|
||||
|
||||
|
@@ -873,6 +873,19 @@ kernel_device_get_property_as_int (MMKernelDevice *self,
|
||||
return ((value && mm_get_int_from_str (value, &aux)) ? aux : 0);
|
||||
}
|
||||
|
||||
static guint
|
||||
kernel_device_get_property_as_int_hex (MMKernelDevice *self,
|
||||
const gchar *property)
|
||||
{
|
||||
const gchar *value;
|
||||
guint aux = 0;
|
||||
|
||||
g_return_val_if_fail (MM_IS_KERNEL_DEVICE_GENERIC (self), -1);
|
||||
|
||||
value = g_object_get_data (G_OBJECT (self), property);
|
||||
return ((value && mm_get_uint_from_hex_str (value, &aux)) ? aux : 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
MMKernelDevice *
|
||||
@@ -1051,6 +1064,7 @@ mm_kernel_device_generic_class_init (MMKernelDeviceGenericClass *klass)
|
||||
kernel_device_class->get_property = kernel_device_get_property;
|
||||
kernel_device_class->get_property_as_boolean = kernel_device_get_property_as_boolean;
|
||||
kernel_device_class->get_property_as_int = kernel_device_get_property_as_int;
|
||||
kernel_device_class->get_property_as_int_hex = kernel_device_get_property_as_int_hex;
|
||||
|
||||
properties[PROP_PROPERTIES] =
|
||||
g_param_spec_object ("properties",
|
||||
|
@@ -579,6 +579,25 @@ kernel_device_get_property_as_int (MMKernelDevice *_self,
|
||||
return g_udev_device_get_property_as_int (self->priv->device, property);
|
||||
}
|
||||
|
||||
static guint
|
||||
kernel_device_get_property_as_int_hex (MMKernelDevice *_self,
|
||||
const gchar *property)
|
||||
{
|
||||
MMKernelDeviceUdev *self;
|
||||
const gchar *s;
|
||||
guint out = 0;
|
||||
|
||||
g_return_val_if_fail (MM_IS_KERNEL_DEVICE_UDEV (_self), -1);
|
||||
|
||||
self = MM_KERNEL_DEVICE_UDEV (_self);
|
||||
|
||||
if (!self->priv->device)
|
||||
return -1;
|
||||
|
||||
s = g_udev_device_get_property (self->priv->device, property);
|
||||
return ((s && mm_get_uint_from_hex_str (s, &out)) ? out : 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
MMKernelDevice *
|
||||
@@ -767,6 +786,7 @@ mm_kernel_device_udev_class_init (MMKernelDeviceUdevClass *klass)
|
||||
kernel_device_class->get_property = kernel_device_get_property;
|
||||
kernel_device_class->get_property_as_boolean = kernel_device_get_property_as_boolean;
|
||||
kernel_device_class->get_property_as_int = kernel_device_get_property_as_int;
|
||||
kernel_device_class->get_property_as_int_hex = kernel_device_get_property_as_int_hex;
|
||||
|
||||
properties[PROP_UDEV_DEVICE] =
|
||||
g_param_spec_object ("udev-device",
|
||||
|
@@ -166,6 +166,17 @@ mm_kernel_device_get_property_as_int (MMKernelDevice *self,
|
||||
-1);
|
||||
}
|
||||
|
||||
guint
|
||||
mm_kernel_device_get_property_as_int_hex (MMKernelDevice *self,
|
||||
const gchar *property)
|
||||
{
|
||||
g_return_val_if_fail (MM_IS_KERNEL_DEVICE (self), 0);
|
||||
|
||||
return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_property_as_int_hex ?
|
||||
MM_KERNEL_DEVICE_GET_CLASS (self)->get_property_as_int_hex (self, property) :
|
||||
0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
|
@@ -61,6 +61,7 @@ struct _MMKernelDeviceClass {
|
||||
const gchar * (* get_property) (MMKernelDevice *self, const gchar *property);
|
||||
gboolean (* get_property_as_boolean) (MMKernelDevice *self, const gchar *property);
|
||||
gint (* get_property_as_int) (MMKernelDevice *self, const gchar *property);
|
||||
guint (* get_property_as_int_hex) (MMKernelDevice *self, const gchar *property);
|
||||
};
|
||||
|
||||
GType mm_kernel_device_get_type (void);
|
||||
@@ -85,5 +86,6 @@ gboolean mm_kernel_device_has_property (MMKernelDevice *self, con
|
||||
const gchar *mm_kernel_device_get_property (MMKernelDevice *self, const gchar *property);
|
||||
gboolean mm_kernel_device_get_property_as_boolean (MMKernelDevice *self, const gchar *property);
|
||||
gint mm_kernel_device_get_property_as_int (MMKernelDevice *self, const gchar *property);
|
||||
guint mm_kernel_device_get_property_as_int_hex (MMKernelDevice *self, const gchar *property);
|
||||
|
||||
#endif /* MM_KERNEL_DEVICE_H */
|
||||
|
Reference in New Issue
Block a user